This commit is contained in:
Amine 2017-06-08 20:35:50 +02:00
parent 4565079f29
commit 3da1d431db
2 changed files with 20 additions and 9 deletions

View File

@ -25,8 +25,8 @@ android {
applicationId "apps.amine.bou.readerforselfoss"
minSdkVersion 16
targetSdkVersion 25
versionCode 1510
versionName "1.5.1"
versionCode 1511
versionName "1.5.1.1"
// Enabling multidex support.
multiDexEnabled true

View File

@ -31,7 +31,14 @@ class AddSourceActivity : AppCompatActivity() {
val mTags = findViewById(R.id.tags) as EditText
val mSpoutsSpinner = findViewById(R.id.spoutsSpinner) as Spinner
val mSaveBtn = findViewById(R.id.saveBtn) as Button
val api = SelfossApi(this)
var api: SelfossApi? = null
try {
api = SelfossApi(this)
} catch (e: IllegalArgumentException) {
mustLoginToAddSource()
}
val intent = intent
@ -40,7 +47,7 @@ class AddSourceActivity : AppCompatActivity() {
mNameInput.setText(intent.getStringExtra(Intent.EXTRA_TITLE))
}
mSaveBtn.setOnClickListener { handleSaveSource(mTags, mNameInput.text.toString(), mSourceUri.text.toString(), api) }
mSaveBtn.setOnClickListener { handleSaveSource(mTags, mNameInput.text.toString(), mSourceUri.text.toString(), api!!) }
val spoutsKV = HashMap<String, String>()
@ -58,14 +65,11 @@ class AddSourceActivity : AppCompatActivity() {
val config = Config(this)
if (config.baseUrl.isEmpty() || !isUrlValid(config.baseUrl)) {
Toast.makeText(this, getString(R.string.addStringNoUrl), Toast.LENGTH_SHORT).show()
val i = Intent(this, LoginActivity::class.java)
startActivity(i)
finish()
mustLoginToAddSource()
} else {
var items: Map<String, Spout>
api.spouts().enqueue(object : Callback<Map<String, Spout>> {
api!!.spouts().enqueue(object : Callback<Map<String, Spout>> {
override fun onResponse(call: Call<Map<String, Spout>>, response: Response<Map<String, Spout>>) {
if (response.body() != null) {
items = response.body()!!
@ -99,6 +103,13 @@ class AddSourceActivity : AppCompatActivity() {
}
}
private fun mustLoginToAddSource() {
Toast.makeText(this, getString(R.string.addStringNoUrl), Toast.LENGTH_SHORT).show()
val i = Intent(this, LoginActivity::class.java)
startActivity(i)
finish()
}
private fun handleSaveSource(mTags: EditText, title: String, url: String, api: SelfossApi) {
if (title.isEmpty() || url.isEmpty() || mSpoutsValue == null || mSpoutsValue!!.isEmpty()) {