Added adapitve icon and grid size change forsong
This commit is contained in:
parent
929922d228
commit
c6fc672cd1
26 changed files with 209 additions and 51 deletions
|
@ -29,7 +29,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
|||
} else R.layout.item_list
|
||||
}
|
||||
|
||||
protected abstract fun setLayoutRes(layoutRes: Int)
|
||||
|
||||
fun setAndSaveLayoutRes(layoutRes: Int) {
|
||||
setLayoutRes(layoutRes)
|
||||
|
@ -53,7 +52,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
|||
return gridSize
|
||||
}
|
||||
|
||||
protected abstract fun setGridSize(gridSize: Int)
|
||||
|
||||
fun getSortOrder(): String? {
|
||||
if (sortOrder == null) {
|
||||
|
@ -62,7 +60,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
|||
return sortOrder
|
||||
}
|
||||
|
||||
protected abstract fun setSortOrder(sortOrder: String)
|
||||
|
||||
fun setAndSaveSortOrder(sortOrder: String) {
|
||||
this.sortOrder = sortOrder
|
||||
|
@ -78,9 +75,9 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
|||
} else {
|
||||
saveGridSize(gridSize)
|
||||
}
|
||||
invalidateLayoutManager()
|
||||
// only recreate the adapter and layout manager if the layout currentLayoutRes has changed
|
||||
if (oldLayoutRes != itemLayoutRes()) {
|
||||
invalidateLayoutManager()
|
||||
invalidateAdapter()
|
||||
} else {
|
||||
setGridSize(gridSize)
|
||||
|
@ -107,6 +104,12 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
|
|||
recyclerView.setPadding(padding, padding, padding, padding)
|
||||
}
|
||||
|
||||
protected abstract fun setGridSize(gridSize: Int)
|
||||
|
||||
protected abstract fun setSortOrder(sortOrder: String)
|
||||
|
||||
protected abstract fun setLayoutRes(layoutRes: Int)
|
||||
|
||||
protected abstract fun loadSortOrder(): String
|
||||
|
||||
protected abstract fun saveSortOrder(sortOrder: String)
|
||||
|
|
|
@ -3,7 +3,7 @@ package code.name.monkey.retromusic.fragments.mainactivity
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
||||
|
@ -18,7 +18,7 @@ import java.util.*
|
|||
import javax.inject.Inject
|
||||
|
||||
class SongsFragment :
|
||||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, LinearLayoutManager>(),
|
||||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>(),
|
||||
SongView, MainActivityFragmentCallbacks {
|
||||
|
||||
@Inject
|
||||
|
@ -37,8 +37,19 @@ class SongsFragment :
|
|||
songPresenter.attachView(this)
|
||||
}
|
||||
|
||||
override fun createLayoutManager(): LinearLayoutManager {
|
||||
return LinearLayoutManager(requireActivity())
|
||||
override fun createLayoutManager(): GridLayoutManager {
|
||||
println("createLayoutManager: ${getGridSize()}")
|
||||
return GridLayoutManager(requireActivity(), getGridSize()).apply {
|
||||
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return if (position == 0) {
|
||||
getGridSize()
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun createAdapter(): SongAdapter {
|
||||
|
@ -46,7 +57,7 @@ class SongsFragment :
|
|||
return ShuffleButtonSongAdapter(
|
||||
mainActivity,
|
||||
dataSet,
|
||||
R.layout.item_list,
|
||||
itemLayoutRes(),
|
||||
mainActivity
|
||||
)
|
||||
}
|
||||
|
@ -60,7 +71,7 @@ class SongsFragment :
|
|||
}
|
||||
|
||||
override fun loadGridSize(): Int {
|
||||
return PreferenceUtil.getInstance(requireContext()).getSongGridSize(requireActivity())
|
||||
return PreferenceUtil.getInstance(requireContext()).getSongGridSize(requireContext())
|
||||
}
|
||||
|
||||
override fun saveGridSize(gridColumns: Int) {
|
||||
|
@ -68,7 +79,7 @@ class SongsFragment :
|
|||
}
|
||||
|
||||
override fun loadGridSizeLand(): Int {
|
||||
return PreferenceUtil.getInstance(requireContext()).getSongGridSizeLand(requireActivity())
|
||||
return PreferenceUtil.getInstance(requireContext()).getSongGridSizeLand(requireContext())
|
||||
}
|
||||
|
||||
override fun saveGridSizeLand(gridColumns: Int) {
|
||||
|
@ -125,10 +136,11 @@ class SongsFragment :
|
|||
|
||||
@LayoutRes
|
||||
override fun loadLayoutRes(): Int {
|
||||
return R.layout.item_list
|
||||
return PreferenceUtil.getInstance(requireContext()).songGridStyle
|
||||
}
|
||||
|
||||
override fun saveLayoutRes(@LayoutRes layoutRes: Int) {
|
||||
PreferenceUtil.getInstance(requireContext()).songGridStyle = layoutRes
|
||||
}
|
||||
|
||||
override fun handleBackPress(): Boolean {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue