[Playlists] Added Grid size selection for Playlists

This commit is contained in:
Prathamesh More 2021-11-27 01:29:36 +05:30
parent c52d02ea10
commit d6bc78619b
5 changed files with 99 additions and 13 deletions

View file

@ -118,6 +118,8 @@ const val ALBUM_GRID_SIZE_LAND = "album_grid_size_land"
const val SONG_GRID_SIZE_LAND = "song_grid_size_land" const val SONG_GRID_SIZE_LAND = "song_grid_size_land"
const val ARTIST_GRID_SIZE = "artist_grid_size" const val ARTIST_GRID_SIZE = "artist_grid_size"
const val ARTIST_GRID_SIZE_LAND = "artist_grid_size_land" const val ARTIST_GRID_SIZE_LAND = "artist_grid_size_land"
const val PLAYLIST_GRID_SIZE = "playlist_grid_size"
const val PLAYLIST_GRID_SIZE_LAND = "playlist_grid_size_land"
const val COLORED_APP_SHORTCUTS = "colored_app_shortcuts" const val COLORED_APP_SHORTCUTS = "colored_app_shortcuts"
const val AUDIO_DUCKING = "audio_ducking" const val AUDIO_DUCKING = "audio_ducking"
const val LAST_ADDED_CUTOFF = "last_added_interval" const val LAST_ADDED_CUTOFF = "last_added_interval"

View file

@ -22,6 +22,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.setPadding
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
@ -29,6 +30,7 @@ import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
import code.name.monkey.retromusic.db.PlaylistEntity import code.name.monkey.retromusic.db.PlaylistEntity
import code.name.monkey.retromusic.db.PlaylistWithSongs import code.name.monkey.retromusic.db.PlaylistWithSongs
import code.name.monkey.retromusic.db.toSongs import code.name.monkey.retromusic.db.toSongs
import code.name.monkey.retromusic.extensions.dipToPix
import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.glide.GlideApp import code.name.monkey.retromusic.glide.GlideApp
@ -42,7 +44,7 @@ import code.name.monkey.retromusic.util.MusicUtil
class PlaylistAdapter( class PlaylistAdapter(
override val activity: FragmentActivity, override val activity: FragmentActivity,
private var dataSet: List<PlaylistWithSongs>, var dataSet: List<PlaylistWithSongs>,
private var itemLayoutRes: Int, private var itemLayoutRes: Int,
ICabHolder: ICabHolder?, ICabHolder: ICabHolder?,
private val listener: IPlaylistClickListener private val listener: IPlaylistClickListener
@ -94,7 +96,12 @@ class PlaylistAdapter(
holder.menu?.show() holder.menu?.show()
} }
GlideApp.with(activity) GlideApp.with(activity)
.load(PlaylistPreview(playlist)) .load(
if (itemLayoutRes == R.layout.item_list) {
holder.image?.setPadding(activity.dipToPix(8F).toInt())
R.drawable.ic_playlist_play
} else PlaylistPreview(playlist)
)
.playlistOptions() .playlistOptions()
.into(holder.image!!) .into(holder.image!!)
} }

View file

@ -25,12 +25,12 @@ import code.name.monkey.retromusic.EXTRA_PLAYLIST
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
import code.name.monkey.retromusic.db.PlaylistWithSongs import code.name.monkey.retromusic.db.PlaylistWithSongs
import code.name.monkey.retromusic.extensions.navigate
import code.name.monkey.retromusic.fragments.ReloadType import code.name.monkey.retromusic.fragments.ReloadType
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.helper.SortOrder.PlaylistSortOrder import code.name.monkey.retromusic.helper.SortOrder.PlaylistSortOrder
import code.name.monkey.retromusic.interfaces.IPlaylistClickListener import code.name.monkey.retromusic.interfaces.IPlaylistClickListener
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroUtil
import com.google.android.gms.cast.framework.CastButtonFactory import com.google.android.gms.cast.framework.CastButtonFactory
import com.google.android.material.transition.MaterialSharedAxis import com.google.android.material.transition.MaterialSharedAxis
@ -66,9 +66,10 @@ class PlaylistsFragment :
} }
override fun createAdapter(): PlaylistAdapter { override fun createAdapter(): PlaylistAdapter {
val dataSet = if (adapter == null) mutableListOf() else adapter!!.dataSet
return PlaylistAdapter( return PlaylistAdapter(
requireActivity(), requireActivity(),
ArrayList(), dataSet,
itemLayoutRes(), itemLayoutRes(),
null, null,
this this
@ -77,7 +78,11 @@ class PlaylistsFragment :
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) super.onCreateOptionsMenu(menu, inflater)
menu.removeItem(R.id.action_grid_size) val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
if (RetroUtil.isLandscape()) {
gridSizeItem.setTitle(R.string.action_grid_size_land)
}
setupGridSizeMenu(gridSizeItem.subMenu)
menu.removeItem(R.id.action_layout_type) menu.removeItem(R.id.action_layout_type)
menu.add(0, R.id.action_add_to_playlist, 0, R.string.new_playlist_title) menu.add(0, R.id.action_add_to_playlist, 0, R.string.new_playlist_title)
menu.add(0, R.id.action_import_playlist, 0, R.string.import_playlist) menu.add(0, R.id.action_import_playlist, 0, R.string.import_playlist)
@ -89,12 +94,46 @@ class PlaylistsFragment :
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (handleGridSizeMenuItem(item)) {
return true
}
if (handleSortOrderMenuItem(item)) { if (handleSortOrderMenuItem(item)) {
return true return true
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
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 = if (RetroUtil.isLandscape()) 4 else 2
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
}
}
private fun setUpSortOrderMenu(subMenu: SubMenu) { private fun setUpSortOrderMenu(subMenu: SubMenu) {
val order: String? = getSortOrder() val order: String? = getSortOrder()
@ -142,13 +181,32 @@ class PlaylistsFragment :
return false return false
} }
private fun handleGridSizeMenuItem(item: MenuItem): Boolean {
val gridSize = when (item.itemId) {
R.id.action_grid_size_1 -> 1
R.id.action_grid_size_2 -> 2
R.id.action_grid_size_3 -> 3
R.id.action_grid_size_4 -> 4
R.id.action_grid_size_5 -> 5
R.id.action_grid_size_6 -> 6
R.id.action_grid_size_7 -> 7
R.id.action_grid_size_8 -> 8
else -> 0
}
if (gridSize > 0) {
item.isChecked = true
setAndSaveGridSize(gridSize)
return true
}
return false
}
private fun createId(menu: SubMenu, id: Int, title: Int, checked: Boolean) { private fun createId(menu: SubMenu, id: Int, title: Int, checked: Boolean) {
menu.add(0, id, 0, title).isChecked = checked menu.add(0, id, 0, title).isChecked = checked
} }
override fun setGridSize(gridSize: Int) { override fun setGridSize(gridSize: Int) {
TODO("Not yet implemented") adapter?.notifyDataSetChanged()
} }
override fun setSortOrder(sortOrder: String) { override fun setSortOrder(sortOrder: String) {
@ -164,23 +222,23 @@ class PlaylistsFragment :
} }
override fun loadGridSize(): Int { override fun loadGridSize(): Int {
return 2 return PreferenceUtil.playlistGridSize
} }
override fun saveGridSize(gridColumns: Int) { override fun saveGridSize(gridColumns: Int) {
//Add grid save PreferenceUtil.playlistGridSize = gridColumns
} }
override fun loadGridSizeLand(): Int { override fun loadGridSizeLand(): Int {
return 4 return PreferenceUtil.playlistGridSizeLand
} }
override fun saveGridSizeLand(gridColumns: Int) { override fun saveGridSizeLand(gridColumns: Int) {
//Add land grid save PreferenceUtil.playlistGridSizeLand = gridColumns
} }
override fun loadLayoutRes(): Int { override fun loadLayoutRes(): Int {
return R.layout.item_card return R.layout.item_grid
} }
override fun saveLayoutRes(layoutRes: Int) { override fun saveLayoutRes(layoutRes: Int) {

View file

@ -40,7 +40,7 @@ public class AutoGeneratedPlaylistBitmap {
List<Bitmap> art = new ArrayList<>(); List<Bitmap> art = new ArrayList<>();
for (Long id : albumID) { for (Long id : albumID) {
Bitmap bitmap = getBitmapWithAlbumId(context, id); Bitmap bitmap = getBitmapWithAlbumId(context, id);
if (bitmap != null) art.add(BitmapEditor.getRoundedCornerBitmap(bitmap, 10)); if (bitmap != null) art.add(BitmapEditor.getRoundedCornerBitmap(bitmap, 20));
if (art.size() == 9) break; if (art.size() == 9) break;
} }
return MergedImageUtils.INSTANCE.joinImages(art); return MergedImageUtils.INSTANCE.joinImages(art);

View file

@ -498,6 +498,25 @@ object PreferenceUtil {
} }
var playlistGridSize
get() = sharedPreferences.getInt(
PLAYLIST_GRID_SIZE,
App.getContext().getIntRes(R.integer.default_grid_columns)
)
set(value) = sharedPreferences.edit {
putInt(PLAYLIST_GRID_SIZE, value)
}
var playlistGridSizeLand
get() = sharedPreferences.getInt(
PLAYLIST_GRID_SIZE_LAND,
App.getContext().getIntRes(R.integer.default_grid_columns_land)
)
set(value) = sharedPreferences.edit {
putInt(PLAYLIST_GRID_SIZE, value)
}
var albumCoverStyle: AlbumCoverStyle var albumCoverStyle: AlbumCoverStyle
get() { get() {
val id: Int = sharedPreferences.getInt(ALBUM_COVER_STYLE, 0) val id: Int = sharedPreferences.getInt(ALBUM_COVER_STYLE, 0)