diff --git a/app/build.gradle b/app/build.gradle index 7641028..82df49e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index c650b1c..428913e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -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() @@ -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 - api.spouts().enqueue(object : Callback> { + api!!.spouts().enqueue(object : Callback> { override fun onResponse(call: Call>, response: Response>) { 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()) {