Added List sort, grid size, layout changes
This commit is contained in:
parent
6f07548023
commit
ffa0749849
5 changed files with 626 additions and 7 deletions
|
@ -52,7 +52,7 @@ class LibraryViewModel(
|
|||
artists.value = loadArtists.await()
|
||||
playlists.value = loadPlaylists.await()
|
||||
roomPlaylists.value = loadPlaylistsWithSongs.await()
|
||||
//genres.value = loadGenres.await()
|
||||
genres.value = loadGenres.await()
|
||||
}
|
||||
|
||||
private val loadHome: Deferred<List<Home>>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package code.name.monkey.retromusic.fragments.albums
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.*
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.navigation.fragment.FragmentNavigatorExtras
|
||||
|
@ -12,7 +12,11 @@ import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
|||
import code.name.monkey.retromusic.extensions.findActivityNavController
|
||||
import code.name.monkey.retromusic.fragments.ReloadType
|
||||
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment
|
||||
import code.name.monkey.retromusic.helper.SortOrder
|
||||
import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
|
||||
|
||||
class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(),
|
||||
AlbumClickListener {
|
||||
|
@ -103,6 +107,181 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridL
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||
if (RetroUtil.isLandscape()) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||
}
|
||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||
val layoutItem = menu.findItem(R.id.action_layout_type)
|
||||
setupLayoutMenu(layoutItem.subMenu)
|
||||
setUpSortOrderMenu(menu.findItem(R.id.action_sort_order).subMenu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun setUpSortOrderMenu(
|
||||
sortOrderMenu: SubMenu
|
||||
) {
|
||||
val currentSortOrder: String? = getSortOrder()
|
||||
sortOrderMenu.clear()
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_album_sort_order_asc,
|
||||
0,
|
||||
R.string.sort_order_a_z
|
||||
).isChecked =
|
||||
currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z)
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_album_sort_order_desc,
|
||||
1,
|
||||
R.string.sort_order_z_a
|
||||
).isChecked =
|
||||
currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A)
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_album_sort_order_artist,
|
||||
2,
|
||||
R.string.sort_order_artist
|
||||
).isChecked =
|
||||
currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST)
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_album_sort_order_year,
|
||||
3,
|
||||
R.string.sort_order_year
|
||||
).isChecked =
|
||||
currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_YEAR)
|
||||
|
||||
sortOrderMenu.setGroupCheckable(0, true, true)
|
||||
}
|
||||
|
||||
private fun setupLayoutMenu(
|
||||
subMenu: SubMenu
|
||||
) {
|
||||
when (itemLayoutRes()) {
|
||||
R.layout.item_card -> subMenu.findItem(R.id.action_layout_card).isChecked = true
|
||||
R.layout.item_grid -> subMenu.findItem(R.id.action_layout_normal).isChecked = true
|
||||
R.layout.item_card_color ->
|
||||
subMenu.findItem(R.id.action_layout_colored_card).isChecked = true
|
||||
R.layout.item_grid_circle ->
|
||||
subMenu.findItem(R.id.action_layout_circular).isChecked = true
|
||||
R.layout.image -> subMenu.findItem(R.id.action_layout_image).isChecked = true
|
||||
R.layout.item_image_gradient ->
|
||||
subMenu.findItem(R.id.action_layout_gradient_image).isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpGridSizeMenu(
|
||||
gridSizeMenu: SubMenu
|
||||
) {
|
||||
when (getGridSize()) {
|
||||
1 -> gridSizeMenu.findItem(R.id.action_grid_size_1).isChecked =
|
||||
true
|
||||
2 -> gridSizeMenu.findItem(R.id.action_grid_size_2).isChecked = true
|
||||
3 -> gridSizeMenu.findItem(R.id.action_grid_size_3).isChecked = true
|
||||
4 -> gridSizeMenu.findItem(R.id.action_grid_size_4).isChecked = true
|
||||
5 -> gridSizeMenu.findItem(R.id.action_grid_size_5).isChecked = true
|
||||
6 -> gridSizeMenu.findItem(R.id.action_grid_size_6).isChecked = true
|
||||
7 -> gridSizeMenu.findItem(R.id.action_grid_size_7).isChecked = true
|
||||
8 -> gridSizeMenu.findItem(R.id.action_grid_size_8).isChecked = true
|
||||
}
|
||||
val gridSize: Int = maxGridSize
|
||||
if (gridSize < 8) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_8).isVisible = false
|
||||
}
|
||||
if (gridSize < 7) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_7).isVisible = false
|
||||
}
|
||||
if (gridSize < 6) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_6).isVisible = false
|
||||
}
|
||||
if (gridSize < 5) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_5).isVisible = false
|
||||
}
|
||||
if (gridSize < 4) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_4).isVisible = false
|
||||
}
|
||||
if (gridSize < 3) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_3).isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (handleGridSizeMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleLayoutResType(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleSortOrderMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun handleSortOrderMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var sortOrder: String? = null
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.action_album_sort_order_asc -> sortOrder = AlbumSortOrder.ALBUM_A_Z
|
||||
R.id.action_album_sort_order_desc -> sortOrder = AlbumSortOrder.ALBUM_Z_A
|
||||
R.id.action_album_sort_order_artist -> sortOrder = AlbumSortOrder.ALBUM_ARTIST
|
||||
R.id.action_album_sort_order_year -> sortOrder = AlbumSortOrder.ALBUM_YEAR
|
||||
}
|
||||
if (sortOrder != null) {
|
||||
item.isChecked = true
|
||||
setAndSaveSortOrder(sortOrder)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleLayoutResType(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var layoutRes = -1
|
||||
when (item.itemId) {
|
||||
R.id.action_layout_normal -> layoutRes = R.layout.item_grid
|
||||
R.id.action_layout_card -> layoutRes = R.layout.item_card
|
||||
R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color
|
||||
R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle
|
||||
R.id.action_layout_image -> layoutRes = R.layout.image
|
||||
R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient
|
||||
}
|
||||
if (layoutRes != -1) {
|
||||
item.isChecked = true
|
||||
setAndSaveLayoutRes(layoutRes)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleGridSizeMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var gridSize = 0
|
||||
when (item.itemId) {
|
||||
R.id.action_grid_size_1 -> gridSize = 1
|
||||
R.id.action_grid_size_2 -> gridSize = 2
|
||||
R.id.action_grid_size_3 -> gridSize = 3
|
||||
R.id.action_grid_size_4 -> gridSize = 4
|
||||
R.id.action_grid_size_5 -> gridSize = 5
|
||||
R.id.action_grid_size_6 -> gridSize = 6
|
||||
R.id.action_grid_size_7 -> gridSize = 7
|
||||
R.id.action_grid_size_8 -> gridSize = 8
|
||||
}
|
||||
if (gridSize > 0) {
|
||||
item.isChecked = true
|
||||
setAndSaveGridSize(gridSize)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface AlbumClickListener {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package code.name.monkey.retromusic.fragments.artists
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.*
|
||||
import android.widget.ImageView
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.lifecycle.Observer
|
||||
|
@ -12,7 +12,10 @@ import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
|||
import code.name.monkey.retromusic.extensions.findActivityNavController
|
||||
import code.name.monkey.retromusic.fragments.ReloadType
|
||||
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment
|
||||
import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
|
||||
|
||||
class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(),
|
||||
ArtistClickListener {
|
||||
|
@ -97,6 +100,161 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment<ArtistAdapter, Gri
|
|||
val controller = findActivityNavController(R.id.fragment_container)
|
||||
controller.navigate(R.id.artistDetailsFragment, bundleOf(EXTRA_ARTIST_ID to artistId))
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||
if (RetroUtil.isLandscape()) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||
}
|
||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||
val layoutItem = menu.findItem(R.id.action_layout_type)
|
||||
setupLayoutMenu(layoutItem.subMenu)
|
||||
setUpSortOrderMenu(menu.findItem(R.id.action_sort_order).subMenu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun setUpSortOrderMenu(
|
||||
sortOrderMenu: SubMenu
|
||||
) {
|
||||
val currentSortOrder: String? = getSortOrder()
|
||||
sortOrderMenu.clear()
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_artist_sort_order_asc,
|
||||
0,
|
||||
R.string.sort_order_a_z
|
||||
).isChecked = currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z)
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_artist_sort_order_desc,
|
||||
1,
|
||||
R.string.sort_order_z_a
|
||||
).isChecked = currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A)
|
||||
sortOrderMenu.setGroupCheckable(0, true, true)
|
||||
}
|
||||
|
||||
private fun setupLayoutMenu(
|
||||
subMenu: SubMenu
|
||||
) {
|
||||
when (itemLayoutRes()) {
|
||||
R.layout.item_card -> subMenu.findItem(R.id.action_layout_card).isChecked = true
|
||||
R.layout.item_grid -> subMenu.findItem(R.id.action_layout_normal).isChecked = true
|
||||
R.layout.item_card_color ->
|
||||
subMenu.findItem(R.id.action_layout_colored_card).isChecked = true
|
||||
R.layout.item_grid_circle ->
|
||||
subMenu.findItem(R.id.action_layout_circular).isChecked = true
|
||||
R.layout.image -> subMenu.findItem(R.id.action_layout_image).isChecked = true
|
||||
R.layout.item_image_gradient ->
|
||||
subMenu.findItem(R.id.action_layout_gradient_image).isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpGridSizeMenu(
|
||||
gridSizeMenu: SubMenu
|
||||
) {
|
||||
when (getGridSize()) {
|
||||
1 -> gridSizeMenu.findItem(R.id.action_grid_size_1).isChecked =
|
||||
true
|
||||
2 -> gridSizeMenu.findItem(R.id.action_grid_size_2).isChecked = true
|
||||
3 -> gridSizeMenu.findItem(R.id.action_grid_size_3).isChecked = true
|
||||
4 -> gridSizeMenu.findItem(R.id.action_grid_size_4).isChecked = true
|
||||
5 -> gridSizeMenu.findItem(R.id.action_grid_size_5).isChecked = true
|
||||
6 -> gridSizeMenu.findItem(R.id.action_grid_size_6).isChecked = true
|
||||
7 -> gridSizeMenu.findItem(R.id.action_grid_size_7).isChecked = true
|
||||
8 -> gridSizeMenu.findItem(R.id.action_grid_size_8).isChecked = true
|
||||
}
|
||||
val gridSize: Int = maxGridSize
|
||||
if (gridSize < 8) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_8).isVisible = false
|
||||
}
|
||||
if (gridSize < 7) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_7).isVisible = false
|
||||
}
|
||||
if (gridSize < 6) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_6).isVisible = false
|
||||
}
|
||||
if (gridSize < 5) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_5).isVisible = false
|
||||
}
|
||||
if (gridSize < 4) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_4).isVisible = false
|
||||
}
|
||||
if (gridSize < 3) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_3).isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (handleGridSizeMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleLayoutResType(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleSortOrderMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun handleSortOrderMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var sortOrder: String? = null
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.action_artist_sort_order_asc -> sortOrder = ArtistSortOrder.ARTIST_A_Z
|
||||
R.id.action_artist_sort_order_desc -> sortOrder = ArtistSortOrder.ARTIST_Z_A
|
||||
}
|
||||
if (sortOrder != null) {
|
||||
item.isChecked = true
|
||||
setAndSaveSortOrder(sortOrder)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleLayoutResType(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var layoutRes = -1
|
||||
when (item.itemId) {
|
||||
R.id.action_layout_normal -> layoutRes = R.layout.item_grid
|
||||
R.id.action_layout_card -> layoutRes = R.layout.item_card
|
||||
R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color
|
||||
R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle
|
||||
R.id.action_layout_image -> layoutRes = R.layout.image
|
||||
R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient
|
||||
}
|
||||
if (layoutRes != -1) {
|
||||
item.isChecked = true
|
||||
setAndSaveLayoutRes(layoutRes)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleGridSizeMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var gridSize = 0
|
||||
when (item.itemId) {
|
||||
R.id.action_grid_size_1 -> gridSize = 1
|
||||
R.id.action_grid_size_2 -> gridSize = 2
|
||||
R.id.action_grid_size_3 -> gridSize = 3
|
||||
R.id.action_grid_size_4 -> gridSize = 4
|
||||
R.id.action_grid_size_5 -> gridSize = 5
|
||||
R.id.action_grid_size_6 -> gridSize = 6
|
||||
R.id.action_grid_size_7 -> gridSize = 7
|
||||
R.id.action_grid_size_8 -> gridSize = 8
|
||||
}
|
||||
if (gridSize > 0) {
|
||||
item.isChecked = true
|
||||
setAndSaveGridSize(gridSize)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
interface ArtistClickListener {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package code.name.monkey.retromusic.fragments.songs
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.*
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
|
@ -9,7 +9,10 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||
import code.name.monkey.retromusic.fragments.ReloadType
|
||||
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment
|
||||
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
|
||||
|
||||
class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>() {
|
||||
|
||||
|
@ -35,7 +38,7 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLay
|
|||
return SongAdapter(
|
||||
requireActivity(),
|
||||
dataSet,
|
||||
R.layout.item_list,
|
||||
itemLayoutRes(),
|
||||
null
|
||||
)
|
||||
}
|
||||
|
@ -81,6 +84,213 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLay
|
|||
libraryViewModel.forceReload(ReloadType.Songs)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||
if (RetroUtil.isLandscape()) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||
}
|
||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||
val layoutItem = menu.findItem(R.id.action_layout_type)
|
||||
setupLayoutMenu(layoutItem.subMenu)
|
||||
setUpSortOrderMenu(menu.findItem(R.id.action_sort_order).subMenu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun setUpSortOrderMenu(
|
||||
sortOrderMenu: SubMenu
|
||||
) {
|
||||
val currentSortOrder: String? = getSortOrder()
|
||||
sortOrderMenu.clear()
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_asc,
|
||||
0,
|
||||
R.string.sort_order_a_z
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_A_Z
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_desc,
|
||||
1,
|
||||
R.string.sort_order_z_a
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_Z_A
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_artist,
|
||||
2,
|
||||
R.string.sort_order_artist
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_ARTIST
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_album,
|
||||
3,
|
||||
R.string.sort_order_album
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_ALBUM
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_year,
|
||||
4,
|
||||
R.string.sort_order_year
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_YEAR
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_date,
|
||||
5,
|
||||
R.string.sort_order_date
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_DATE
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_date_modified,
|
||||
6,
|
||||
R.string.sort_order_date_modified
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.SONG_DATE_MODIFIED
|
||||
sortOrderMenu.add(
|
||||
0,
|
||||
R.id.action_song_sort_order_composer,
|
||||
7,
|
||||
R.string.sort_order_composer
|
||||
).isChecked =
|
||||
currentSortOrder == SongSortOrder.COMPOSER
|
||||
|
||||
sortOrderMenu.setGroupCheckable(0, true, true)
|
||||
}
|
||||
|
||||
private fun setupLayoutMenu(
|
||||
subMenu: SubMenu
|
||||
) {
|
||||
when (itemLayoutRes()) {
|
||||
R.layout.item_card -> subMenu.findItem(R.id.action_layout_card).isChecked = true
|
||||
R.layout.item_grid -> subMenu.findItem(R.id.action_layout_normal).isChecked = true
|
||||
R.layout.item_card_color ->
|
||||
subMenu.findItem(R.id.action_layout_colored_card).isChecked = true
|
||||
R.layout.item_grid_circle ->
|
||||
subMenu.findItem(R.id.action_layout_circular).isChecked = true
|
||||
R.layout.image -> subMenu.findItem(R.id.action_layout_image).isChecked = true
|
||||
R.layout.item_image_gradient ->
|
||||
subMenu.findItem(R.id.action_layout_gradient_image).isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpGridSizeMenu(
|
||||
gridSizeMenu: SubMenu
|
||||
) {
|
||||
when (getGridSize()) {
|
||||
1 -> gridSizeMenu.findItem(R.id.action_grid_size_1).isChecked =
|
||||
true
|
||||
2 -> gridSizeMenu.findItem(R.id.action_grid_size_2).isChecked = true
|
||||
3 -> gridSizeMenu.findItem(R.id.action_grid_size_3).isChecked = true
|
||||
4 -> gridSizeMenu.findItem(R.id.action_grid_size_4).isChecked = true
|
||||
5 -> gridSizeMenu.findItem(R.id.action_grid_size_5).isChecked = true
|
||||
6 -> gridSizeMenu.findItem(R.id.action_grid_size_6).isChecked = true
|
||||
7 -> gridSizeMenu.findItem(R.id.action_grid_size_7).isChecked = true
|
||||
8 -> gridSizeMenu.findItem(R.id.action_grid_size_8).isChecked = true
|
||||
}
|
||||
val gridSize: Int = maxGridSize
|
||||
if (gridSize < 8) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_8).isVisible = false
|
||||
}
|
||||
if (gridSize < 7) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_7).isVisible = false
|
||||
}
|
||||
if (gridSize < 6) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_6).isVisible = false
|
||||
}
|
||||
if (gridSize < 5) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_5).isVisible = false
|
||||
}
|
||||
if (gridSize < 4) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_4).isVisible = false
|
||||
}
|
||||
if (gridSize < 3) {
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_3).isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (handleGridSizeMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleLayoutResType(item)) {
|
||||
return true
|
||||
}
|
||||
if (handleSortOrderMenuItem(item)) {
|
||||
return true
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun handleSortOrderMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var sortOrder: String? = null
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.action_song_sort_order_asc -> sortOrder = SongSortOrder.SONG_A_Z
|
||||
R.id.action_song_sort_order_desc -> sortOrder = SongSortOrder.SONG_Z_A
|
||||
R.id.action_song_sort_order_artist -> sortOrder = SongSortOrder.SONG_ARTIST
|
||||
R.id.action_song_sort_order_album -> sortOrder = SongSortOrder.SONG_ALBUM
|
||||
R.id.action_song_sort_order_year -> sortOrder = SongSortOrder.SONG_YEAR
|
||||
R.id.action_song_sort_order_date -> sortOrder = SongSortOrder.SONG_DATE
|
||||
R.id.action_song_sort_order_composer -> sortOrder = SongSortOrder.COMPOSER
|
||||
R.id.action_song_sort_order_date_modified -> sortOrder =
|
||||
SongSortOrder.SONG_DATE_MODIFIED
|
||||
}
|
||||
if (sortOrder != null) {
|
||||
item.isChecked = true
|
||||
setAndSaveSortOrder(sortOrder)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleLayoutResType(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var layoutRes = -1
|
||||
when (item.itemId) {
|
||||
R.id.action_layout_normal -> layoutRes = R.layout.item_grid
|
||||
R.id.action_layout_card -> layoutRes = R.layout.item_card
|
||||
R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color
|
||||
R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle
|
||||
R.id.action_layout_image -> layoutRes = R.layout.image
|
||||
R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient
|
||||
}
|
||||
if (layoutRes != -1) {
|
||||
item.isChecked = true
|
||||
setAndSaveLayoutRes(layoutRes)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleGridSizeMenuItem(
|
||||
item: MenuItem
|
||||
): Boolean {
|
||||
var gridSize = 0
|
||||
when (item.itemId) {
|
||||
R.id.action_grid_size_1 -> gridSize = 1
|
||||
R.id.action_grid_size_2 -> gridSize = 2
|
||||
R.id.action_grid_size_3 -> gridSize = 3
|
||||
R.id.action_grid_size_4 -> gridSize = 4
|
||||
R.id.action_grid_size_5 -> gridSize = 5
|
||||
R.id.action_grid_size_6 -> gridSize = 6
|
||||
R.id.action_grid_size_7 -> gridSize = 7
|
||||
R.id.action_grid_size_8 -> gridSize = 8
|
||||
}
|
||||
if (gridSize > 0) {
|
||||
item.isChecked = true
|
||||
setAndSaveGridSize(gridSize)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
var TAG: String = SongsFragment::class.java.simpleName
|
||||
|
|
|
@ -16,10 +16,82 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".DrawerActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_grid_size"
|
||||
android:icon="@drawable/ic_grid_size"
|
||||
android:title="@string/action_grid_size"
|
||||
app:showAsAction="never">
|
||||
<menu>
|
||||
<group
|
||||
android:id="@+id/group_grid_size"
|
||||
android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/action_grid_size_1"
|
||||
android:title="@string/grid_size_1" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_2"
|
||||
android:title="@string/grid_size_2" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_3"
|
||||
android:title="@string/grid_size_3" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_4"
|
||||
android:title="@string/grid_size_4" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_5"
|
||||
android:title="@string/grid_size_5" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_6"
|
||||
android:title="@string/grid_size_6" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_7"
|
||||
android:title="@string/grid_size_7" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_8"
|
||||
android:title="@string/grid_size_8" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/action_layout_type"
|
||||
android:icon="@drawable/ic_dashboard"
|
||||
android:title="@string/grid_style_label"
|
||||
app:showAsAction="never">
|
||||
<menu>
|
||||
<group
|
||||
android:id="@+id/group_layout_type"
|
||||
android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/action_layout_normal"
|
||||
android:title="@string/normal" />
|
||||
<item
|
||||
android:id="@+id/action_layout_card"
|
||||
android:title="@string/card" />
|
||||
<item
|
||||
android:id="@+id/action_layout_colored_card"
|
||||
android:title="@string/card_color_style" />
|
||||
<item
|
||||
android:id="@+id/action_layout_circular"
|
||||
android:title="@string/circular" />
|
||||
<item
|
||||
android:id="@+id/action_layout_image"
|
||||
android:title="@string/image" />
|
||||
<item
|
||||
android:id="@+id/action_layout_gradient_image"
|
||||
android:title="@string/image_gradient" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/action_sort_order"
|
||||
android:icon="@drawable/ic_sort"
|
||||
android:title="@string/action_sort_order"
|
||||
app:showAsAction="never">
|
||||
<menu></menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
Loading…
Reference in a new issue