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
|
@ -229,18 +229,14 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
if (fragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) {
|
||||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment currentFragment
|
||||
= (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) fragment;
|
||||
if (currentFragment instanceof SongsFragment) {
|
||||
menu.removeItem(R.id.action_grid_size);
|
||||
menu.removeItem(R.id.action_layout_type);
|
||||
} else {
|
||||
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
|
||||
if (RetroUtil.isLandscape()) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land);
|
||||
}
|
||||
setUpGridSizeMenu(currentFragment, gridSizeItem.getSubMenu());
|
||||
MenuItem layoutItem = menu.findItem(R.id.action_layout_type);
|
||||
setupLayoutMenu(currentFragment, layoutItem.getSubMenu());
|
||||
|
||||
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
|
||||
if (RetroUtil.isLandscape()) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land);
|
||||
}
|
||||
setUpGridSizeMenu(currentFragment, gridSizeItem.getSubMenu());
|
||||
MenuItem layoutItem = menu.findItem(R.id.action_layout_type);
|
||||
setupLayoutMenu(currentFragment, layoutItem.getSubMenu());
|
||||
setUpSortOrderMenu(currentFragment, menu.findItem(R.id.action_sort_order).getSubMenu());
|
||||
} else {
|
||||
menu.removeItem(R.id.action_layout_type);
|
||||
|
|
|
@ -17,10 +17,16 @@ package code.name.monkey.retromusic.extensions
|
|||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.AdaptiveIconDrawable
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import androidx.annotation.DimenRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
|
||||
fun Context.scaledDrawableResources(@DrawableRes id: Int, @DimenRes width: Int, @DimenRes height: Int): Drawable {
|
||||
val w = resources.getDimension(width).toInt()
|
||||
|
@ -34,3 +40,20 @@ fun Context.scaledDrawable(@DrawableRes id: Int, width: Int, height: Int): Drawa
|
|||
return BitmapDrawable(resources, bmpScaled)
|
||||
}
|
||||
|
||||
fun Drawable.getBitmapDrawable(): Bitmap {
|
||||
val bmp = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bmp)
|
||||
draw(canvas)
|
||||
return bmp
|
||||
}
|
||||
|
||||
fun getAdaptiveIconDrawable(context: Context): Drawable {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
AdaptiveIconDrawable(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_launcher_background),
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)
|
||||
)
|
||||
} else {
|
||||
ContextCompat.getDrawable(context, R.drawable.color_circle_gradient)!!
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -396,11 +396,9 @@ public final class PreferenceUtil {
|
|||
.getInt(ALBUM_GRID_SIZE_LAND, context.getResources().getInteger(R.integer.default_grid_columns_land));
|
||||
}
|
||||
|
||||
|
||||
@LayoutRes
|
||||
public int getAlbumGridStyle() {
|
||||
if (mPreferences.contains(ALBUM_GRID_STYLE)) {
|
||||
Log.i(TAG, "getAlbumGridStyle: " + mPreferences.getInt(ALBUM_GRID_STYLE, -10));
|
||||
}
|
||||
return mPreferences.getInt(ALBUM_GRID_STYLE, R.layout.item_grid);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ import android.graphics.Color
|
|||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.getAdaptiveIconDrawable
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
|
||||
|
@ -44,15 +44,16 @@ class ColorIconsImageView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
fun setIconBackgroundColor(color: Int) {
|
||||
setBackgroundResource(R.drawable.color_circle_gradient)
|
||||
background = getAdaptiveIconDrawable(context)
|
||||
if (ATHUtil.isWindowBackgroundDark(context) && PreferenceUtil.getInstance(context).desaturatedColor()) {
|
||||
val desaturatedColor = RetroColorUtil.desaturateColor(color, 0.4f)
|
||||
backgroundTintList = ColorStateList.valueOf(desaturatedColor)
|
||||
imageTintList =
|
||||
ColorStateList.valueOf(ATHUtil.resolveColor(context, R.attr.colorSurface))
|
||||
} else {
|
||||
backgroundTintList = ColorStateList.valueOf(ColorUtil.adjustAlpha(color, 0.22f))
|
||||
imageTintList = ColorStateList.valueOf(ColorUtil.withAlpha(color, 0.75f))
|
||||
backgroundTintList = ColorStateList.valueOf(color)
|
||||
imageTintList =
|
||||
ColorStateList.valueOf(ATHUtil.resolveColor(context, R.attr.colorSurface))
|
||||
}
|
||||
requestLayout()
|
||||
invalidate()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue