diff options
author | Allan Wang <me@allanwang.ca> | 2017-11-15 03:48:56 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-11-15 03:48:56 -0500 |
commit | 0b60ad9b70be8cac67913c9e6438a5bb812cbd37 (patch) | |
tree | 5ec577af73537aa598ed6d5f8196fadf1b897933 /app/src/main/kotlin/com | |
parent | 5a6bf455cb2e550c18f94d8aeaaa91c2260cb75a (diff) | |
download | frost-0b60ad9b70be8cac67913c9e6438a5bb812cbd37.tar.gz frost-0b60ad9b70be8cac67913c9e6438a5bb812cbd37.tar.bz2 frost-0b60ad9b70be8cac67913c9e6438a5bb812cbd37.zip |
Fix some logic
Diffstat (limited to 'app/src/main/kotlin/com')
5 files changed, 38 insertions, 24 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt index 803a9690..d1cdf1fa 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt @@ -4,6 +4,7 @@ import android.content.res.Configuration import android.os.Bundle import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.searchview.SearchViewHolder +import ca.allanwang.kau.utils.finishSlideOut import com.github.pwittchen.reactivenetwork.library.rx2.Connectivity import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork import com.pitchedapps.frost.R @@ -20,21 +21,16 @@ import io.reactivex.schedulers.Schedulers * Created by Allan Wang on 2017-06-12. */ abstract class BaseActivity : KauBaseActivity() { - override fun onBackPressed() { + + /** + * Inherited consumer to customize back press + */ + protected open fun backConsumer(): Boolean = false + + override final fun onBackPressed() { if (this is SearchViewHolder && searchViewOnBackPress()) return if (this is VideoViewHolder && videoOnBackPress()) return - if (this is MainActivity && currentFragment.onBackPressed()) return - if (this !is WebOverlayActivityBase && isTaskRoot && Prefs.exitConfirmation) { - materialDialogThemed { - title(R.string.kau_exit) - content(R.string.kau_exit_confirmation) - positiveText(R.string.kau_yes) - negativeText(R.string.kau_no) - onPositive { _, _ -> super.onBackPressed() } - checkBoxPromptRes(R.string.kau_do_not_show_again, false, { _, b -> Prefs.exitConfirmation = !b }) - } - return - } + if (backConsumer()) return super.onBackPressed() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt index 9b5fdb0f..0d6cce07 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -121,10 +121,12 @@ class LoginActivity : BaseActivity() { cookie.fetchUsername { usernameObservable.onSuccess(it) } } - override fun onBackPressed() { - if (web.canGoBack()) + override fun backConsumer(): Boolean { + if (web.canGoBack()) { web.goBack() - else - super.onBackPressed() + return true + } + return false } + }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt index 442d98d8..5d7e3625 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt @@ -434,6 +434,22 @@ class MainActivity : BaseActivity(), super.onDestroy() } + override fun backConsumer(): Boolean { + if (currentFragment.onBackPressed()) return true + if (Prefs.exitConfirmation) { + materialDialogThemed { + title(R.string.kau_exit) + content(R.string.kau_exit_confirmation) + positiveText(R.string.kau_yes) + negativeText(R.string.kau_no) + onPositive { _, _ -> finish() } + checkBoxPromptRes(R.string.kau_do_not_show_again, false, { _, b -> Prefs.exitConfirmation = !b }) + } + return true + } + return false + } + inline val currentFragment get() = supportFragmentManager.findFragmentByTag("android:switcher:${R.id.container}:${viewPager.currentItem}") as WebFragment diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index ce4bffb5..c41964cd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -172,6 +172,12 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc } } + override fun backConsumer(): Boolean { + if (!frostWeb.onBackPressed()) + finishSlideOut() + return true + } + /** * Our theme for the overlay should be fully opaque */ @@ -190,12 +196,6 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc kauSwipeOnDestroy() } - override fun onBackPressed() { - if (!frostWeb.onBackPressed()) { - finishSlideOut() - } - } - override fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams) { openMediaPicker(filePathCallback, fileChooserParams) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 67881ada..22b6c0b6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -153,7 +153,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient if (path.startsWith("/composer/")) return launchRequest(request) if (url.contains("scontent-sea1-1.xx.fbcdn.net") && (path.endsWith(".jpg") || path.endsWith(".png"))) return launchImage(url) - if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) return true + if (Prefs.linksInDefaultApp && !url.isFacebookUrl && view.context.resolveActivityForUri(request.url)) return true return super.shouldOverrideUrlLoading(view, request) } |