Code cleanup
This commit is contained in:
parent
5ee9c04924
commit
9d93d700be
6 changed files with 21 additions and 31 deletions
|
@ -89,9 +89,9 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
navController.graph = navGraph
|
navController.graph = navGraph
|
||||||
getBottomNavigationView().setupWithNavController(navController)
|
bottomNavigationView.setupWithNavController(navController)
|
||||||
// Scroll Fragment to top
|
// Scroll Fragment to top
|
||||||
getBottomNavigationView().setOnItemReselectedListener {
|
bottomNavigationView.setOnItemReselectedListener {
|
||||||
currentFragment(R.id.fragment_container)
|
currentFragment(R.id.fragment_container)
|
||||||
.also {
|
.also {
|
||||||
if (it is AbsRecyclerViewFragment<*, *>) {
|
if (it is AbsRecyclerViewFragment<*, *>) {
|
||||||
|
@ -118,7 +118,6 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
||||||
}
|
}
|
||||||
else -> setBottomNavVisibility(visible = false, animate = true) // Hide Bottom Navigation Bar
|
else -> setBottomNavVisibility(visible = false, animate = true) // Hide Bottom Navigation Bar
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.model.CategoryInfo
|
import code.name.monkey.retromusic.model.CategoryInfo
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.*
|
import com.google.android.material.bottomsheet.BottomSheetBehavior.*
|
||||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
}
|
}
|
||||||
STATE_SETTLING, STATE_DRAGGING -> {
|
STATE_SETTLING, STATE_DRAGGING -> {
|
||||||
if (fromNotification) {
|
if (fromNotification) {
|
||||||
getBottomNavigationView().isVisible = true
|
bottomNavigationView.isVisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -125,7 +124,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
windowInsets = insets
|
windowInsets = insets
|
||||||
insets
|
insets
|
||||||
}
|
}
|
||||||
binding.bottomNavigationView.drawAboveSystemBarsWithPadding()
|
bottomNavigationView.drawAboveSystemBarsWithPadding()
|
||||||
if (RetroUtil.isLandscape()) {
|
if (RetroUtil.isLandscape()) {
|
||||||
binding.slidingPanel.drawAboveSystemBarsWithPadding(true)
|
binding.slidingPanel.drawAboveSystemBarsWithPadding(true)
|
||||||
}
|
}
|
||||||
|
@ -214,9 +213,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBottomNavigationView(): BottomNavigationView {
|
val bottomNavigationView get() = binding.bottomNavigationView
|
||||||
return binding.bottomNavigationView
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
|
@ -357,7 +354,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
bottomSheetBehavior.peekHeightAnimate(heightOfBar)
|
bottomSheetBehavior.peekHeightAnimate(heightOfBar)
|
||||||
bottomNavAnimator?.end()
|
bottomNavAnimator?.end()
|
||||||
bottomNavAnimator =
|
bottomNavAnimator =
|
||||||
getBottomNavigationView().translateYAnimate(dip(R.dimen.bottom_nav_height).toFloat())
|
bottomNavigationView.translateYAnimate(dip(R.dimen.bottom_nav_height).toFloat())
|
||||||
bottomNavAnimator?.doOnEnd {
|
bottomNavAnimator?.doOnEnd {
|
||||||
binding.slidingPanel.bringToFront()
|
binding.slidingPanel.bringToFront()
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ abstract class AbsRecyclerViewCustomGridSizeFragment<A : RecyclerView.Adapter<*>
|
||||||
} else {
|
} else {
|
||||||
saveGridSize(gridSize)
|
saveGridSize(gridSize)
|
||||||
}
|
}
|
||||||
recyclerView().isVisible = false
|
recyclerView.isVisible = false
|
||||||
invalidateLayoutManager()
|
invalidateLayoutManager()
|
||||||
// only recreate the adapter and layout manager if the layout currentLayoutRes has changed
|
// only recreate the adapter and layout manager if the layout currentLayoutRes has changed
|
||||||
if (oldLayoutRes != itemLayoutRes()) {
|
if (oldLayoutRes != itemLayoutRes()) {
|
||||||
|
@ -95,10 +95,10 @@ abstract class AbsRecyclerViewCustomGridSizeFragment<A : RecyclerView.Adapter<*>
|
||||||
setGridSize(gridSize)
|
setGridSize(gridSize)
|
||||||
}
|
}
|
||||||
val transition = MaterialFade().apply {
|
val transition = MaterialFade().apply {
|
||||||
addTarget(recyclerView())
|
addTarget(recyclerView)
|
||||||
}
|
}
|
||||||
TransitionManager.beginDelayedTransition(getContainer(), transition)
|
TransitionManager.beginDelayedTransition(container, transition)
|
||||||
recyclerView().isVisible = true
|
recyclerView.isVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun setGridSize(gridSize: Int)
|
protected abstract fun setGridSize(gridSize: Int)
|
||||||
|
|
|
@ -19,7 +19,6 @@ import android.view.*
|
||||||
import androidx.annotation.NonNull
|
import androidx.annotation.NonNull
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
||||||
import androidx.core.view.doOnPreDraw
|
import androidx.core.view.doOnPreDraw
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
@ -57,7 +56,6 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
|
||||||
_binding = FragmentMainRecyclerBinding.bind(view)
|
_binding = FragmentMainRecyclerBinding.bind(view)
|
||||||
postponeEnterTransition()
|
postponeEnterTransition()
|
||||||
view.doOnPreDraw { startPostponedEnterTransition() }
|
view.doOnPreDraw { startPostponedEnterTransition() }
|
||||||
|
|
||||||
mainActivity.setSupportActionBar(binding.toolbar)
|
mainActivity.setSupportActionBar(binding.toolbar)
|
||||||
mainActivity.supportActionBar?.title = null
|
mainActivity.supportActionBar?.title = null
|
||||||
initLayoutManager()
|
initLayoutManager()
|
||||||
|
@ -198,16 +196,12 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
fun recyclerView(): RecyclerView {
|
val recyclerView get() = binding.recyclerView
|
||||||
return binding.recyclerView
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getContainer(): CoordinatorLayout {
|
val container get() = binding.root
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
fun scrollToTop() {
|
fun scrollToTop() {
|
||||||
recyclerView().scrollToPosition(0)
|
recyclerView.scrollToPosition(0)
|
||||||
binding.appBarLayout.setExpanded(true, true)
|
binding.appBarLayout.setExpanded(true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
|
||||||
navGraph.setStartDestination(categoryInfo.category.id)
|
navGraph.setStartDestination(categoryInfo.category.id)
|
||||||
}
|
}
|
||||||
navController.graph = navGraph
|
navController.graph = navGraph
|
||||||
NavigationUI.setupWithNavController(mainActivity.getBottomNavigationView(), navController)
|
NavigationUI.setupWithNavController(mainActivity.bottomNavigationView, navController)
|
||||||
navController.addOnDestinationChangedListener { _, _, _ ->
|
navController.addOnDestinationChangedListener { _, _, _ ->
|
||||||
binding.appBarLayout.setExpanded(true, true)
|
binding.appBarLayout.setExpanded(true, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,12 +70,12 @@ class PlayingQueueRVFragment : AbsRecyclerViewFragment<PlayingQueueAdapter, Line
|
||||||
recyclerViewDragDropManager?.createWrappedAdapter(adapter!!) as RecyclerView.Adapter<*>
|
recyclerViewDragDropManager?.createWrappedAdapter(adapter!!) as RecyclerView.Adapter<*>
|
||||||
wrappedAdapter =
|
wrappedAdapter =
|
||||||
recyclerViewSwipeManager?.createWrappedAdapter(wrappedAdapter) as RecyclerView.Adapter<*>
|
recyclerViewSwipeManager?.createWrappedAdapter(wrappedAdapter) as RecyclerView.Adapter<*>
|
||||||
recyclerView().layoutManager = layoutManager
|
recyclerView.layoutManager = layoutManager
|
||||||
recyclerView().adapter = wrappedAdapter
|
recyclerView.adapter = wrappedAdapter
|
||||||
recyclerView().itemAnimator = animator
|
recyclerView.itemAnimator = animator
|
||||||
recyclerViewTouchActionGuardManager?.attachRecyclerView(recyclerView())
|
recyclerViewTouchActionGuardManager?.attachRecyclerView(recyclerView)
|
||||||
recyclerViewDragDropManager?.attachRecyclerView(recyclerView())
|
recyclerViewDragDropManager?.attachRecyclerView(recyclerView)
|
||||||
recyclerViewSwipeManager?.attachRecyclerView(recyclerView())
|
recyclerViewSwipeManager?.attachRecyclerView(recyclerView)
|
||||||
|
|
||||||
layoutManager?.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
layoutManager?.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class PlayingQueueRVFragment : AbsRecyclerViewFragment<PlayingQueueAdapter, Line
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetToCurrentPosition() {
|
private fun resetToCurrentPosition() {
|
||||||
recyclerView().stopScroll()
|
recyclerView.stopScroll()
|
||||||
layoutManager?.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
layoutManager?.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue