From 6d008e45ee6c520ab50485a5c84ca1dfda190a48 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 1 Dec 2020 10:54:12 +0000 Subject: [PATCH] #2530 Remove activity finishing from IntroFragment and rely on default behaviour - use pops to make intro the only destination on the stack --- .../org/kiwix/kiwixmobile/intro/IntroFragment.kt | 10 ++-------- .../org/kiwix/kiwixmobile/main/KiwixMainActivity.kt | 3 ++- app/src/main/res/navigation/kiwix_nav_graph.xml | 13 ++++++++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/intro/IntroFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/intro/IntroFragment.kt index 861c17fc38..bce427ab15 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/intro/IntroFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/intro/IntroFragment.kt @@ -23,8 +23,8 @@ import android.os.Looper import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isVisible +import androidx.navigation.fragment.findNavController import androidx.viewpager.widget.ViewPager import kotlinx.android.synthetic.main.fragment_intro.get_started import kotlinx.android.synthetic.main.fragment_intro.tab_indicator @@ -35,7 +35,6 @@ import org.kiwix.kiwixmobile.cachedComponent import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions -import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.zim_manager.SimplePageChangeListener import java.util.Timer import java.util.TimerTask @@ -103,15 +102,10 @@ class IntroFragment : BaseFragment(), IntroContract.View, FragmentActivityExtens views = emptyArray() } - override fun onBackPressed(activity: AppCompatActivity): FragmentActivityExtensions.Super { - activity.finish() - return super.onBackPressed(activity) - } - private fun navigateToLibrary() { dismissAutoRotate() presenter.setIntroShown() - (requireActivity() as KiwixMainActivity).navController.popBackStack() + findNavController().navigate(IntroFragmentDirections.actionIntrofragmentToLibraryFragment()) } private fun updateView(position: Int) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index 9748511857..58e78da209 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -38,6 +38,7 @@ import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions import org.kiwix.kiwixmobile.core.di.components.CoreComponent import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.kiwixActivityComponent +import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections const val NAVIGATE_TO_ZIM_HOST_FRAGMENT = "navigate_to_zim_host_fragment" @@ -94,7 +95,7 @@ class KiwixMainActivity : CoreMainActivity() { } } if (sharedPreferenceUtil.showIntro()) { - navigate(R.id.introFragment) + navigate(LocalLibraryFragmentDirections.actionLibraryFragmentToIntrofragment()) } } diff --git a/app/src/main/res/navigation/kiwix_nav_graph.xml b/app/src/main/res/navigation/kiwix_nav_graph.xml index 18bf190b19..e51ca0ef73 100644 --- a/app/src/main/res/navigation/kiwix_nav_graph.xml +++ b/app/src/main/res/navigation/kiwix_nav_graph.xml @@ -69,6 +69,11 @@ + + tools:layout="@layout/fragment_intro"> + +