@ -13,6 +13,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.findNavController
@ -36,6 +38,11 @@ class SetupFragment : Fragment() {
private lateinit var mainActivity : MainActivity
companion object {
const val KEY _NEXT _VISIBILITY = " NextButtonVisibility "
const val KEY _BACK _VISIBILITY = " BackButtonVisibility "
}
override fun onCreate ( savedInstanceState : Bundle ? ) {
super . onCreate ( savedInstanceState )
exitTransition = MaterialFadeThrough ( )
@ -134,14 +141,27 @@ class SetupFragment : Fragment() {
binding . buttonNext . setOnClickListener { pageForward ( ) }
binding . buttonBack . setOnClickListener { pageBackward ( ) }
if ( binding . viewPager2 . currentItem == 0 ) {
binding . buttonNext . visibility = View . INVISIBLE
binding . buttonBack . visibility = View . INVISIBLE
if ( savedInstanceState != null ) {
val nextIsVisible = savedInstanceState . getBoolean ( KEY _NEXT _VISIBILITY )
val backIsVisible = savedInstanceState . getBoolean ( KEY _BACK _VISIBILITY )
if ( nextIsVisible ) {
binding . buttonNext . visibility = View . VISIBLE
}
if ( backIsVisible ) {
binding . buttonBack . visibility = View . VISIBLE
}
}
setInsets ( )
}
override fun onSaveInstanceState ( outState : Bundle ) {
super . onSaveInstanceState ( outState )
outState . putBoolean ( KEY _NEXT _VISIBILITY , binding . buttonNext . isVisible )
outState . putBoolean ( KEY _BACK _VISIBILITY , binding . buttonBack . isVisible )
}
override fun onDestroyView ( ) {
super . onDestroyView ( )
_binding = null
@ -190,7 +210,7 @@ class SetupFragment : Fragment() {
}
private fun setInsets ( ) =
ViewCompat . setOnApplyWindowInsetsListener ( binding . setupR oot) { view : View , windowInsets : WindowInsetsCompat ->
ViewCompat . setOnApplyWindowInsetsListener ( binding . r oot) { view : View , windowInsets : WindowInsetsCompat ->
val insets = windowInsets . getInsets ( WindowInsetsCompat . Type . systemBars ( ) )
view . setPadding (
insets . left ,