1
1
package com.smarttoolfactory.tutorial3_1transitions.chapter2_fragment_transitions
2
2
3
3
import android.os.Bundle
4
+ import android.view.View
5
+ import android.widget.Toast
4
6
import androidx.appcompat.app.AppCompatActivity
7
+ import androidx.coordinatorlayout.widget.CoordinatorLayout
8
+ import androidx.core.view.updatePadding
9
+ import androidx.navigation.findNavController
10
+ import com.google.android.material.bottomnavigation.BottomNavigationView
11
+ import com.google.android.material.floatingactionbutton.FloatingActionButton
5
12
import com.smarttoolfactory.tutorial3_1transitions.R
6
13
7
14
15
+ @Suppress(" DEPRECATION" )
8
16
class Activity2_6FragmentExpandCollapseTransitions : AppCompatActivity () {
9
17
18
+ private lateinit var fab: FloatingActionButton
19
+
10
20
override fun onCreate (savedInstanceState : Bundle ? ) {
11
21
12
22
super .onCreate(savedInstanceState)
13
23
setContentView(R .layout.activity2_6_rv_transitions_expand)
14
24
title = getString(R .string.activity2_6)
15
25
16
- // window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
17
- // View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
18
- // View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
26
+ val rootView = findViewById<CoordinatorLayout >(R .id.coordinatorLayout)
27
+
28
+
29
+ hideSystemUI(rootView, true )
30
+
31
+ val bottomNavigationView = findViewById<BottomNavigationView >(R .id.bottom_navigation)
32
+
33
+ bottomNavigationView.setOnApplyWindowInsetsListener { view, insets ->
34
+ view.updatePadding(bottom = 0 )
35
+ insets
36
+ }
37
+
38
+ fab = findViewById<FloatingActionButton >(R .id.fab)
39
+
40
+ val navController = findNavController(R .id.nav_host_fragment)
41
+
42
+
43
+ navController.addOnDestinationChangedListener { controller, destination, arguments ->
44
+
45
+ when (destination.id) {
46
+ R .id.fragment2_6ExpandCollapseList -> {
47
+ fab.setImageState(intArrayOf(- android.R .attr.state_activated), true )
48
+ }
49
+
50
+ R .id.fragment2_6ExpandCollapseDetails -> {
51
+ fab.setImageState(intArrayOf(android.R .attr.state_activated), true )
52
+ }
53
+ }
54
+ }
55
+
56
+ fab.setOnClickListener {
57
+
58
+ if (navController.currentDestination?.id == R .id.fragment2_6ExpandCollapseList) {
59
+ Toast .makeText(applicationContext, " Compose" , Toast .LENGTH_SHORT ).show()
60
+ } else if (navController.currentDestination?.id == R .id.fragment2_6ExpandCollapseDetails) {
61
+ onBackPressed()
62
+ }
63
+
64
+ }
65
+ }
66
+
67
+ private fun hideSystemUI (view : View = window.decorView, isFullScreen : Boolean ) {
68
+
69
+ var uiOptions = View .SYSTEM_UI_FLAG_LAYOUT_STABLE
70
+
71
+ if (isFullScreen) {
72
+ // hide status bar
73
+ uiOptions = (
74
+ uiOptions
75
+ // or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
76
+ // Views can use nav bar space if set
77
+ or View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
78
+ or View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
79
+ // // Removes Status bar
80
+ // or View.SYSTEM_UI_FLAG_FULLSCREEN
81
+ // // hide nav bar
82
+ // or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
83
+ )
84
+ }
19
85
86
+ view.systemUiVisibility = uiOptions
20
87
}
21
88
}
0 commit comments