From 0498f26dc62c68561ce9803f49597b11b1fc0a4d Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Feb 2020 18:01:22 -0800 Subject: Allow currentFragment to be nullable --- .../kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt | 6 +++--- .../main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index b22ef999..06e7969d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -791,7 +791,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, return true } } - if (currentFragment.onBackPressed()) return true + if (currentFragment?.onBackPressed() == true) return true if (prefs.exitConfirmation) { materialDialog { title(R.string.kau_exit) @@ -807,10 +807,10 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, return false } - inline val currentFragment: BaseFragment + inline val currentFragment: BaseFragment? get() { val viewpager = contentBinding.viewpager - return supportFragmentManager.findFragmentByTag("android:switcher:${viewpager.id}:${viewpager.currentItem}") as BaseFragment + return supportFragmentManager.findFragmentByTag("android:switcher:${viewpager.id}:${viewpager.currentItem}") as? BaseFragment } override fun reloadFragment(fragment: BaseFragment) { 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 e0053402..6522721d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt @@ -82,7 +82,7 @@ class MainActivity : BaseMainActivity() { tabs.addOnTabSelectedListener(object : TabLayout.ViewPagerOnTabSelectedListener(viewpager) { override fun onTabReselected(tab: TabLayout.Tab) { super.onTabReselected(tab) - currentFragment.onTabClick() + currentFragment?.onTabClick() } override fun onTabSelected(tab: TabLayout.Tab) { -- cgit v1.2.3