Advertisement
BlackZerg

Untitled

May 12th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 5.04 KB | None | 0 0
  1. // RootActivity
  2.     var baseFragment: BaseFragment? = null
  3.     var currentFragmentId: Int = 0
  4.  
  5.     var isAdvancedFab = true
  6.     var isRotate = false
  7.  
  8.     @ExperimentalCoroutinesApi
  9.     override fun onCreate(savedInstanceState: Bundle?) {
  10.         super.onCreate(savedInstanceState)
  11.  
  12.         ActivityRootBinding.inflate(layoutInflater).apply {
  13.             binding = this
  14.             setContentView(root)
  15.  
  16.             navController.navInflater.inflate(R.navigation.contact_graph).apply {
  17.                 startDestination = R.id.menuContacts
  18.             }
  19.             mainBottomNavigationMenu.setupWithNavController(navController)
  20.  
  21.             registeredServiceCallInterceptor()
  22.             registerFAB(this)
  23.             registerDynamicLinksListener()
  24.             checkPermissions()
  25.         }
  26.     }
  27.  
  28.     override fun onResume() {
  29.         super.onResume()
  30.         binding?.apply {
  31.             fabContainer.floatButton.visibility = setViewVisibility(false)
  32.             navController.addOnDestinationChangedListener { _, destination, _ ->
  33.                 destinationListener(this, destination)
  34.             }
  35.         }
  36.     }
  37.  
  38.     override fun onDestroy() {
  39.         super.onDestroy()
  40.         binding = null
  41.     }
  42.  
  43.     fun fabState(state: FabState) {
  44.         binding?.let { bind ->
  45.             bind.fabContainer.apply {
  46.                 when (state) {
  47.                     is FabState.InitState -> {
  48.                         viewAnimation.init(fabOpenKeypad)
  49.                         viewAnimation.init(fabAddContact)
  50.                     }
  51.                     is FabState.OpenState -> {
  52.                         viewAnimation.showIn(fabOpenKeypad)
  53.                         viewAnimation.showIn(fabAddContact)
  54.                     }
  55.                     is FabState.CloseState -> {
  56.                         viewAnimation.showOut(fabOpenKeypad)
  57.                         viewAnimation.showOut(fabAddContact)
  58.                     }
  59.                     is FabState.SimpleState -> Unit
  60.                     is FabState.ResetState -> {
  61.                         viewAnimation.reset(fabOpenKeypad)
  62.                         viewAnimation.reset(fabAddContact)
  63.                         isRotate = viewAnimation.rotateFab(floatButton, false)
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.     }
  69.  
  70.     private fun registerFAB(binding: ActivityRootBinding) {
  71.         binding.apply {
  72.             fabState(FabState.InitState)
  73.             fabContainer.apply {
  74.                 floatButton.setOnClickListener { fab -> baseFragment?.floatClick(fab) }
  75.                 fabOpenKeypad.setOnClickListener { baseFragment?.keypadClick() }
  76.                 fabAddContact.setOnClickListener { baseFragment?.addContactClick() }
  77.             }
  78.         }
  79.     }
  80.  
  81.     private fun destinationListener(binding: ActivityRootBinding, destination: NavDestination) {
  82.         binding.apply {
  83.             Log.v("RootActivity!!!!", " destinationListener...")
  84.             fabState(FabState.ResetState)
  85.             mainBottomNavigationMenu.visibility = setViewVisibility(
  86.                 when (destination.id) {
  87.                     R.id.menuContacts -> true
  88.                     R.id.groupsFragment -> true
  89.                     R.id.menuJournal -> true
  90.                     R.id.menuCalendar -> true
  91.                     R.id.menuSettings -> true
  92.                     else -> false
  93.                 }
  94.             )
  95.             fabContainer.floatButton.visibility = setViewVisibility(
  96.                 when (destination.id) {
  97.                     R.id.menuContacts -> true
  98.                     R.id.menuCalendar -> true
  99.                     else -> false
  100.                 }
  101.             )
  102.             isAdvancedFab = when (destination.id) {
  103.                 R.id.groupsFragment -> false
  104.                 R.id.filtersContainerFragment -> false
  105.                 R.id.menuCalendar -> false
  106.                 R.id.calendarDayFragment -> false
  107.                 R.id.calendarWeekFragment -> false
  108.                 R.id.calendarMonthFragment -> false
  109.                 R.id.newEventFragment -> false
  110.                 R.id.repeatSettingsFragment -> false
  111.                 else -> true
  112.             }
  113.         }
  114.     }
  115.  
  116. // BaseFragment
  117.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  118.         super.onViewCreated(view, savedInstanceState)
  119.         setupFAB()
  120.         setupUI(view)
  121.         setupObserver()
  122.     }
  123.  
  124.     override fun onResume() {
  125.         super.onResume()
  126.         activity?.let { fa ->
  127.             if (fa is RootActivity) {
  128.                 fa.baseFragment = this
  129.                 fa.currentFragmentId = currentDestination()
  130.                 fa.fabState(FabState.ResetState)
  131.             }
  132.         }
  133.     }
  134.  
  135.     open fun floatClick(fab: View) {
  136.         activity?.let { fa ->
  137.             if (fa is RootActivity) {
  138.                 if (fa.isAdvancedFab) fa.isRotate = viewAnimation.rotateFab(fab, !fa.isRotate)
  139.                 fabAction(fa)
  140.                 mainFabNavigate(fa.currentFragmentId)
  141.             }
  142.         }
  143.     }
  144.  
  145.     open fun addContactClick() {  }
  146.     open fun keypadClick() {  }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement