diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c3feb48..49c07523 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -179,7 +179,7 @@ android:label="@string/app.about.wikimedia" android:parentActivityName=".fragments.MainFragment" /> (R.id.bottom_navigation) - - bottomNavigationView.selectedItemId = R.id.info - - bottomNavigationView.setOnNavigationItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedListener { item -> - when (item.itemId) { - R.id.settings -> { - startActivity(Intent(applicationContext, SettingsActivity::class.java)) - overridePendingTransition(0, 0) - return@OnNavigationItemSelectedListener true - } - - R.id.info -> { - return@OnNavigationItemSelectedListener true } - R.id.installation -> { - startActivity(Intent(applicationContext, MainActivity::class.java)) - overridePendingTransition(0, 0) - return@OnNavigationItemSelectedListener true - } - } - false - }) - bottomNavigationView.selectedItemId = R.id.info - } - -} - - - diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index 22abc51a..6e24a104 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -6,6 +6,7 @@ import android.view.GestureDetector import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.activity.addCallback import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import be.scri.R @@ -32,6 +33,10 @@ class AboutFragment : Fragment() { savedInstanceState: Bundle? ): View? { binding = FragmentAboutBinding.inflate(inflater, container, false) + val callback = requireActivity().onBackPressedDispatcher.addCallback(this) { + getParentFragmentManager().popBackStack() + } + callback.isEnabled = true return binding.root } @@ -77,7 +82,7 @@ class AboutFragment : Fragment() { private fun getThirdRecyclerViewData(): List { return listOf( - ItemsViewModel(image = R.drawable.shield_lock, R.string.app_about_privacyPolicy, image2 = R.drawable.right_arrow, url = null, activity = null, action = null), + ItemsViewModel(image = R.drawable.shield_lock, R.string.app_about_privacyPolicy, image2 = R.drawable.right_arrow, url = null, activity = null, action = ::loadPrivacyPolicyFragment), ItemsViewModel(image = R.drawable.license_icon, R.string.app_about_thirdParty, image2 = R.drawable.right_arrow, url = null, activity = null, action = null) ) } @@ -111,5 +116,13 @@ class AboutFragment : Fragment() { fragmentTransaction.commit() } + private fun loadPrivacyPolicyFragment() { + val fragment = PrivacyPolicyFragment() + val fragmentTransaction = requireActivity().supportFragmentManager.beginTransaction() + fragmentTransaction.replace(R.id.fragment_container, fragment) + fragmentTransaction.addToBackStack(null) + fragmentTransaction.commit() + } + } diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index 68bbccda..f13d8369 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -10,6 +10,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.InputMethodManager +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatDelegate import androidx.fragment.app.Fragment import be.scri.R @@ -43,6 +44,10 @@ class MainFragment : Fragment() { } } } + val callback = requireActivity().onBackPressedDispatcher.addCallback(this) { + getParentFragmentManager().popBackStack() + } + callback.isEnabled = true return binding.root } diff --git a/app/src/main/java/be/scri/fragments/PrivacyPolicyFragment.kt b/app/src/main/java/be/scri/fragments/PrivacyPolicyFragment.kt new file mode 100644 index 00000000..dd30a914 --- /dev/null +++ b/app/src/main/java/be/scri/fragments/PrivacyPolicyFragment.kt @@ -0,0 +1,66 @@ +package be.scri.fragments + + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import be.scri.R +import be.scri.activities.MainActivity +import be.scri.databinding.ActivityPrivacyPolicyBinding + + +class PrivacyPolicyFragment : Fragment(){ + + + private lateinit var binding: ActivityPrivacyPolicyBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val viewpager = requireActivity().findViewById(R.id.view_pager) + val frameLayout = requireActivity().findViewById(R.id.fragment_container) + val callback = requireActivity().onBackPressedDispatcher.addCallback(this) { + viewpager.setCurrentItem(2, true); + } + callback.isEnabled = true + + + } + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = ActivityPrivacyPolicyBinding.inflate(inflater, container, false) + (requireActivity() as MainActivity).supportActionBar?.title = getString(R.string.app_about_privacyPolicy) + (requireActivity() as MainActivity).showFragmentContainer() + requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + val viewpager = requireActivity().findViewById(R.id.view_pager) + val frameLayout = requireActivity().findViewById(R.id.fragment_container) + if (viewpager.currentItem == 2) { + viewpager.setCurrentItem(2, true) + frameLayout.visibility = View.GONE + } else { + if (parentFragmentManager.backStackEntryCount > 0) { + parentFragmentManager.popBackStack() + } else { + isEnabled = false + requireActivity().onBackPressed() + } + } + + (requireActivity() as MainActivity).supportActionBar?.title = getString(R.string.app_about_title) + } + }) + return binding.root + + } + +} + + + diff --git a/app/src/main/java/be/scri/fragments/SettingsFragment.kt b/app/src/main/java/be/scri/fragments/SettingsFragment.kt index 08f533c7..99e5ae78 100644 --- a/app/src/main/java/be/scri/fragments/SettingsFragment.kt +++ b/app/src/main/java/be/scri/fragments/SettingsFragment.kt @@ -10,6 +10,7 @@ import android.provider.Settings.ACTION_APP_LOCALE_SETTINGS import android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS import android.view.* import android.view.inputmethod.InputMethodManager +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.fragment.app.Fragment @@ -28,6 +29,10 @@ class SettingsFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = FragmentSettingsBinding.inflate(inflater, container, false) + val callback = requireActivity().onBackPressedDispatcher.addCallback(this) { + getParentFragmentManager().popBackStack() + } + callback.isEnabled = true return binding.root } diff --git a/app/src/main/res/layout/activity_privacy_policy.xml b/app/src/main/res/layout/activity_privacy_policy.xml index e8a28ace..fed627a3 100644 --- a/app/src/main/res/layout/activity_privacy_policy.xml +++ b/app/src/main/res/layout/activity_privacy_policy.xml @@ -1,40 +1,21 @@ - - - - - - - - -