Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SickDrawerActionBarOnNavigatedListener(
- private val activity: AppCompatActivity,
- private val drawerLayout: DrawerLayout?,
- private val menuItems: Menu
- ) :
- NavController.OnNavigatedListener {
- private var arrowDrawable: DrawerArrowDrawable? = null
- private var animator: ObjectAnimator? = null
- override fun onNavigated(controller: NavController, destination: NavDestination) {
- var isFromMenu = false
- for (i in 0 until menuItems.size()) {
- if (menuItems.getItem(i).itemId == destination.id)
- isFromMenu = true
- }
- activity.supportActionBar?.setDisplayHomeAsUpEnabled(drawerLayout != null || !isFromMenu)
- setActionBarUpIndicator(drawerLayout != null && isFromMenu)
- }
- private fun setActionBarUpIndicator(showAsDrawerIndicator: Boolean) {
- val delegate = activity.drawerToggleDelegate
- var animate = true
- if (arrowDrawable == null) {
- arrowDrawable = DrawerArrowDrawable(delegate?.actionBarThemedContext).also {
- delegate?.setActionBarUpIndicator(it, 0)
- }
- delegate?.setActionBarUpIndicator(arrowDrawable, 0)
- animate = false
- }
- arrowDrawable?.let {
- val endValue = if (showAsDrawerIndicator) 0f else 1f
- if (animate) {
- val startValue = it.progress
- animator?.cancel()
- animator = ObjectAnimator.ofFloat(
- it, "progress",
- startValue, endValue
- ).apply { start() }
- } else {
- it.progress == endValue
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment