From 69a2418afcf66cb588ad79d7de7f6ded82e5b503 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Sat, 22 Jul 2017 13:12:13 +0200 Subject: [PATCH] Fix 51 (#52) * Some more bug fixes. * Cleaning travis file. * Fixes #51 --- .travis.yml | 9 ------- .../bou/readerforselfoss/AddSourceActivity.kt | 4 +-- .../bou/readerforselfoss/HomeActivity.kt | 7 ++--- .../bou/readerforselfoss/LoginActivity.kt | 4 +-- .../apps/amine/bou/readerforselfoss/MyApp.kt | 26 +++++++++++++++---- .../bou/readerforselfoss/ReaderActivity.kt | 13 +++++----- .../settings/SettingsActivity.java | 4 ++- .../bou/readerforselfoss/utils/AppUtils.kt | 5 +++- .../bou/readerforselfoss/utils/LinksUtils.kt | 2 +- 9 files changed, 44 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index ba2d0d7..c21680c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,15 +28,6 @@ android: - 'android-sdk-license-.+' - 'google-gdk-license-.+' -#install: -# - echo y | android update sdk --no-ui --filter "android-26,build-tools-26.0.0" -# - echo y | android update sdk --no-ui --all --filter "platform-tools, tools" -# - echo y | android update sdk --no-ui --all --filter "android-26, build-tools-26.0.0" -# - echo y | android update sdk --no-ui --all --filter "extra-android-m2repository" -# - echo y | android update sdk --no-ui --all --filter "extra-android-support" -# - echo y | android update sdk --no-ui --all --filter "extra-google-m2repository" -# - echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services" - before_script: - mkdir app/src/main/res/mipmap-hdpi - convert -size 72x72 xc:white app/src/main/res/mipmap-hdpi/ic_launcher.png 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 4e11606..4b4483d 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -16,7 +16,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.Spout import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.utils.Config -import apps.amine.bou.readerforselfoss.utils.isUrlValid +import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid import com.ftinc.scoop.Scoop @@ -73,7 +73,7 @@ class AddSourceActivity : AppCompatActivity() { val config = Config(this) - if (config.baseUrl.isEmpty() || !config.baseUrl.isUrlValid()) { + if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { mustLoginToAddSource() } else { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 7776f30..7665c92 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -185,9 +185,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } else { (recyclerView.adapter as ItemListAdapter).removeItemAtIndex(position) } - tabNewBadge.setText("${items.size}").maybeShow() - - mayBeEmpty() + if (items.size > 0) + tabNewBadge.setText("${items.size}").maybeShow() + else + tabNewBadge.hide() } catch (e: IndexOutOfBoundsException) {} diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt index 26ef700..4614879 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -31,7 +31,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.checkAndDisplayStoreApk -import apps.amine.bou.readerforselfoss.utils.isUrlValid +import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid import com.ftinc.scoop.Scoop @@ -149,7 +149,7 @@ class LoginActivity : AppCompatActivity() { var cancel = false var focusView: View? = null - if (!url.isUrlValid()) { + if (!url.isBaseUrlValid()) { mUrlView.error = getString(R.string.login_url_problem) focusView = mUrlView cancel = true diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt index 43e9e02..4c5edae 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -23,17 +23,31 @@ class MyApp : MultiDexApplication() { if (!BuildConfig.DEBUG) Fabric.with(this, Crashlytics()) - Amplify.initSharedInstance(this) - .setFeedbackEmailAddress(getString(R.string.feedback_email)) - .setAlwaysShow(BuildConfig.DEBUG) - .applyAllDefaultRules() + initAmplify() + initCache() + + initDrawerImageLoader() + + initTheme() + + } + + private fun initAmplify() { + Amplify.initSharedInstance(this) + .setFeedbackEmailAddress(getString(R.string.feedback_email)) + .applyAllDefaultRules() + } + + private fun initCache() { try { Reservoir.init(this, 8192) //in bytes } catch (e: IOException) { //failure } + } + private fun initDrawerImageLoader() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() { override fun set(imageView: ImageView?, uri: Uri?, placeholder: Drawable?, tag: String?) { Glide.with(imageView?.context).load(uri).placeholder(placeholder).into(imageView) @@ -47,6 +61,9 @@ class MyApp : MultiDexApplication() { return baseContext.resources.getDrawable(R.mipmap.ic_launcher) } }) + } + + private fun initTheme() { Scoop.waffleCone() .addFlavor(getString(R.string.default_theme), R.style.NoBar, true) .addFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark) @@ -64,6 +81,5 @@ class MyApp : MultiDexApplication() { .addFlavor(getString(R.string.red_teal_dark_theme), R.style.NoBarRedTealDark) .setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)) .initialize() - } } \ No newline at end of file diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index 2ee8f7b..c7e0cf4 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -100,12 +100,13 @@ class ReaderActivity : DragDismissActivity() { override fun onFailure(call: Call, t: Throwable) = openInBrowserAfterFailing() private fun openInBrowserAfterFailing() { - CustomTabActivityHelper.openCustomTab(this@ReaderActivity, customTabsIntent, Uri.parse(url) - ) { _, uri -> - val intent = Intent(Intent.ACTION_VIEW, uri) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - startActivity(intent) - } + this@ReaderActivity.openItemUrl( + url, + customTabsIntent, + true, + false, + this@ReaderActivity + ) finish() } }) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java index 18914c9..6780bcb 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java @@ -206,7 +206,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity { public void onHeaderClick(Header header, int position) { super.onHeaderClick(header, position); if (header.id == R.id.theme_change) { - getApplicationContext().startActivity(ScoopSettingsActivity.createIntent(getApplicationContext())); + Intent intent = ScoopSettingsActivity.createIntent(getApplicationContext()); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getApplicationContext().startActivity(intent); finish(); } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt index 8004f5b..0f88da2 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt @@ -36,7 +36,10 @@ fun Context.checkAndDisplayStoreApk() = { } else Unit } -fun String.isUrlValid(): Boolean { +fun String.isUrlValid(): Boolean = + HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches() + +fun String.isBaseUrlValid(): Boolean { val baseUrl = HttpUrl.parse(this) var existsAndEndsWithSlash = false if (baseUrl != null) { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt index cbec9f3..c033d3c 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt @@ -55,7 +55,7 @@ fun Context.openItemUrl(linkDecoded: String, internalBrowser: Boolean, articleViewer: Boolean, app: Activity) { - if (!internalBrowser) { + if (!internalBrowser || !linkDecoded.isUrlValid()) { openInBrowser(linkDecoded, app) } else { if (articleViewer) {