Added new theme for Material You & a toggle

This commit is contained in:
Prathamesh More 2021-09-26 15:59:32 +05:30
parent 289557898e
commit f23b102e41
34 changed files with 243 additions and 123 deletions

View file

@ -20,6 +20,7 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.util.PreferenceUtil
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
import com.google.android.material.color.DynamicColors
@ -46,7 +47,9 @@ class App : Application() {
.commit()
}
DynamicColors.applyToActivitiesIfAvailable(this)
if (PreferenceUtil.materialYou) {
DynamicColors.applyToActivitiesIfAvailable(this)
}
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).initDynamicShortcuts()

View file

@ -148,3 +148,4 @@ const val SHOW_LYRICS = "show_lyrics"
const val REMEMBER_LAST_TAB = "remember_last_tab"
const val LAST_USED_TAB = "last_used_tab"
const val WHITELIST_MUSIC = "whitelist_music"
const val MATERIAL_YOU = "material_you"

View file

@ -33,6 +33,7 @@ import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ActivityAlbumTagEditorBinding
import code.name.monkey.retromusic.extensions.appHandleColor
import code.name.monkey.retromusic.extensions.setTint
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
import code.name.monkey.retromusic.model.ArtworkInfo
@ -62,8 +63,6 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
}
override fun loadImageFromFile(selectedFile: Uri?) {
GlideApp.with(this@AlbumTagEditorActivity).asBitmapPalette().load(selectedFile)
.diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true)
.into(object : ImageViewTarget<BitmapPaletteWrapper>(binding.editorImage) {
@ -119,10 +118,10 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
private fun setUpViews() {
fillViewsWithFileTags()
MaterialUtil.setTint(binding.yearContainer, false)
MaterialUtil.setTint(binding.genreContainer, false)
MaterialUtil.setTint(binding.albumTitleContainer, false)
MaterialUtil.setTint(binding.albumArtistContainer, false)
binding.yearContainer.setTint(false)
binding.genreContainer.setTint(false)
binding.albumTitleContainer.setTint(false)
binding.albumArtistContainer.setTint(false)
binding.albumText.appHandleColor().addTextChangedListener(this)
binding.albumArtistText.appHandleColor().addTextChangedListener(this)

View file

@ -22,10 +22,10 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.widget.ImageView
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ActivitySongTagEditorBinding
import code.name.monkey.retromusic.extensions.appHandleColor
import code.name.monkey.retromusic.extensions.setTint
import code.name.monkey.retromusic.repository.SongRepository
import org.jaudiotagger.tag.FieldKey
import org.koin.android.ext.android.inject
@ -50,15 +50,15 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
@SuppressLint("ClickableViewAccessibility")
private fun setUpViews() {
fillViewsWithFileTags()
MaterialUtil.setTint(binding.songTextContainer, false)
MaterialUtil.setTint(binding.composerContainer, false)
MaterialUtil.setTint(binding.albumTextContainer, false)
MaterialUtil.setTint(binding.artistContainer, false)
MaterialUtil.setTint(binding.albumArtistContainer, false)
MaterialUtil.setTint(binding.yearContainer, false)
MaterialUtil.setTint(binding.genreContainer, false)
MaterialUtil.setTint(binding.trackNumberContainer, false)
MaterialUtil.setTint(binding.lyricsContainer, false)
binding.songTextContainer.setTint(false)
binding.composerContainer.setTint(false)
binding.albumTextContainer.setTint(false)
binding.artistContainer.setTint(false)
binding.albumArtistContainer.setTint(false)
binding.yearContainer.setTint(false)
binding.genreContainer.setTint(false)
binding.trackNumberContainer.setTint(false)
binding.lyricsContainer.setTint(false)
binding.songText.appHandleColor().addTextChangedListener(this)
binding.albumText.appHandleColor().addTextChangedListener(this)

View file

@ -21,6 +21,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.findFragment
import androidx.navigation.findNavController
@ -30,6 +31,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
@ -190,7 +192,11 @@ class HomeAdapter(
)
fun bindView(home: Home) {
val color = ThemeStore.accentColor(activity)
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(App.getContext(), R.color.m3_accent_color)
} else {
ThemeStore.accentColor(activity)
}
itemView.findViewById<TextView>(R.id.message).apply {
setTextColor(color)
setOnClickListener {

View file

@ -16,10 +16,9 @@ package code.name.monkey.retromusic.adapter.song
import android.view.View
import androidx.fragment.app.FragmentActivity
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.applyColor
import code.name.monkey.retromusic.extensions.applyOutlineColor
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.accentOutlineColor
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.ICabHolder
import code.name.monkey.retromusic.model.Song
@ -45,19 +44,18 @@ class ShuffleButtonSongAdapter(
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
if (holder.itemViewType == OFFSET_ITEM) {
val color = ThemeStore.accentColor(activity)
val viewHolder = holder as ViewHolder
viewHolder.playAction?.let {
it.setOnClickListener {
MusicPlayerRemote.openQueue(dataSet, 0, true)
}
it.applyOutlineColor(color)
it.accentOutlineColor()
}
viewHolder.shuffleAction?.let {
it.setOnClickListener {
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
}
it.applyColor(color)
it.accentColor()
}
} else {
super.onBindViewHolder(holder, position - 1)

View file

@ -37,6 +37,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtil.materialYou
import com.google.android.material.button.MaterialButton
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.floatingactionbutton.FloatingActionButton
@ -84,23 +85,32 @@ fun Fragment.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
fun Dialog.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
ATHUtil.resolveColor(context, attr, fallBackColor)
// Don't apply accent colors if Material You is enabled
// Material Components will take care of applying material you colors
fun CheckBox.addAccentColor() {
if (materialYou) return
buttonTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
}
fun SeekBar.addAccentColor() {
if (materialYou) return
val colorState = ColorStateList.valueOf(ThemeStore.accentColor(context))
progressTintList = colorState
thumbTintList = colorState
}
fun Button.accentTextColor() = setTextColor(ThemeStore.accentColor(App.getContext()))
fun Button.accentTextColor() {
if (materialYou) return
setTextColor(ThemeStore.accentColor(App.getContext()))
}
fun MaterialButton.accentBackgroundColor() {
if (materialYou) return
backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(App.getContext()))
}
fun MaterialButton.accentOutlineColor() {
if (materialYou) return
val color = ThemeStore.accentColor(context)
val colorStateList = ColorStateList.valueOf(color)
iconTint = colorStateList
@ -116,6 +126,7 @@ fun SeekBar.applyColor(@ColorInt color: Int) {
}
fun ExtendedFloatingActionButton.accentColor() {
if (materialYou) return
val color = ThemeStore.accentColor(context)
val textColor = MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))
val colorStateList = ColorStateList.valueOf(color)
@ -126,6 +137,7 @@ fun ExtendedFloatingActionButton.accentColor() {
}
fun FloatingActionButton.accentColor() {
if (materialYou) return
val color = ThemeStore.accentColor(context)
val textColor = MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))
backgroundTintList = ColorStateList.valueOf(color)
@ -145,15 +157,21 @@ fun MaterialButton.applyColor(color: Int) {
iconTint = textColorColorStateList
}
fun MaterialButton.accentColor() = applyColor(ThemeStore.accentColor(context))
fun MaterialButton.accentColor() {
if (materialYou) return
applyColor(ThemeStore.accentColor(context))
}
fun MaterialButton.applyOutlineColor(color: Int) {
val textColorColorStateList = ColorStateList.valueOf(color)
setTextColor(textColorColorStateList)
iconTint = textColorColorStateList
val colorStateList = ColorStateList.valueOf(color)
iconTint = colorStateList
strokeColor = colorStateList
setTextColor(colorStateList)
rippleColor = colorStateList
}
fun TextInputLayout.accentColor() {
if (materialYou) return
val accentColor = ThemeStore.accentColor(context)
val colorState = ColorStateList.valueOf(accentColor)
boxStrokeColor = accentColor
@ -162,6 +180,7 @@ fun TextInputLayout.accentColor() {
}
fun CircularProgressIndicator.accentColor() {
if (materialYou) return
val color = ThemeStore.accentColor(context)
setIndicatorColor(color)
trackColor = ColorUtil.withAlpha(color, 0.2f)
@ -174,6 +193,21 @@ fun CircularProgressIndicator.applyColor(color: Int) {
fun AppCompatImageView.accentColor(): Int = ThemeStore.accentColor(context)
fun TextInputLayout.setTint(background: Boolean = true) {
if (materialYou) return
val accentColor = ThemeStore.accentColor(context)
val colorState = ColorStateList.valueOf(accentColor)
if (background) {
backgroundTintList = colorState
defaultHintTextColor = colorState
} else {
boxStrokeColor = accentColor
defaultHintTextColor = colorState
isHintAnimationEnabled = true
}
}
@CheckResult
fun Drawable.tint(@ColorInt color: Int): Drawable {
val tintedDrawable = DrawableCompat.wrap(this).mutate()

View file

@ -27,6 +27,7 @@ import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.imageview.ShapeableImageView
import com.google.android.material.shape.ShapeAppearanceModel
@ -51,6 +52,7 @@ fun View.hidden() {
fun View.showOrHide(show: Boolean) = if (show) show() else hide()
fun EditText.appHandleColor(): EditText {
if (PreferenceUtil.materialYou) return this
TintHelper.colorHandles(this, ThemeStore.accentColor(context))
return this
}

View file

@ -20,6 +20,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.MenuItem.SHOW_AS_ACTION_IF_ROOM
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.view.doOnPreDraw
@ -29,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.adapter.HomeAdapter
import code.name.monkey.retromusic.databinding.FragmentBannerHomeBinding
@ -139,7 +141,11 @@ class HomeFragment :
MaterialSharedAxis(MaterialSharedAxis.Z, false)
findNavController().navigate(R.id.searchFragment, null, navOptions)
}
val color = ThemeStore.accentColor(requireContext())
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(App.getContext(), R.color.m3_accent_color)
} else {
ThemeStore.accentColor(requireContext())
}
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val appName = HtmlCompat.fromHtml(
"Retro <span style='color:$hexColor';>Music</span>",

View file

@ -111,6 +111,12 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
true
}
}
val materialYou: ATESwitchPreference? = findPreference(MATERIAL_YOU)
materialYou?.setOnPreferenceChangeListener { _, _ ->
restartActivity()
true
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

View file

@ -1,8 +1,10 @@
package code.name.monkey.retromusic.glide
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.App.Companion.getContext
import code.name.monkey.retromusic.Constants.USER_BANNER
import code.name.monkey.retromusic.Constants.USER_PROFILE
@ -17,6 +19,7 @@ import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getFile
import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getInstance
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.PreferenceUtil.materialYou
import com.bumptech.glide.GenericTransitionOptions
import com.bumptech.glide.Priority
import com.bumptech.glide.RequestBuilder
@ -185,7 +188,11 @@ object RetroGlideExtension {
return TintHelper.createTintedDrawable(
getContext(),
R.drawable.ic_account,
accentColor(getContext())
if (materialYou && VersionUtils.hasS()) {
ContextCompat.getColor(getContext(), R.color.m3_accent_color)
} else {
accentColor(getContext())
}
)
}

View file

@ -613,4 +613,7 @@ object PreferenceUtil {
val crossFadeDuration
get() = sharedPreferences
.getInt(CROSS_FADE_DURATION, 0)
val materialYou
get() = sharedPreferences.getBoolean(MATERIAL_YOU, false)
}

View file

@ -18,6 +18,7 @@ import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor
import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight
import code.name.monkey.appthemehelper.util.MaterialValueHelper.getPrimaryTextColor
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.views.PopupBackground
import me.zhanghai.android.fastscroll.FastScroller
import me.zhanghai.android.fastscroll.FastScrollerBuilder
@ -27,13 +28,17 @@ import me.zhanghai.android.fastscroll.R
object ThemedFastScroller {
fun create(view: ViewGroup): FastScroller {
val context = view.context
val color = accentColor(context)
val color = if (PreferenceUtil.materialYou && VersionUtils.hasS()) {
context.getColor(code.name.monkey.retromusic.R.color.m3_accent_color)
} else {
accentColor(context)
}
val textColor = getPrimaryTextColor(context, isColorLight(color))
val fastScrollerBuilder = FastScrollerBuilder(view)
fastScrollerBuilder.useMd2Style()
fastScrollerBuilder.setPopupStyle { popupText ->
PopupStyles.MD2.accept(popupText)
popupText.background = PopupBackground(context)
popupText.background = PopupBackground(context, color)
popupText.setTextColor(textColor)
}

View file

@ -5,6 +5,7 @@ import androidx.annotation.StyleRes
import androidx.appcompat.app.AppCompatDelegate
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.generalThemeValue
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.theme.ThemeMode.*
object ThemeManager {
@ -12,11 +13,16 @@ object ThemeManager {
@StyleRes
fun getThemeResValue(
context: Context
): Int = when (context.generalThemeValue) {
LIGHT -> R.style.Theme_RetroMusic_Light
DARK -> R.style.Theme_RetroMusic_Base
BLACK -> R.style.Theme_RetroMusic_Black
AUTO -> R.style.Theme_RetroMusic_FollowSystem
): Int =
if (PreferenceUtil.materialYou) {
R.style.Theme_RetroMusic_MD3
} else {
when (context.generalThemeValue) {
LIGHT -> R.style.Theme_RetroMusic_Light
DARK -> R.style.Theme_RetroMusic_Base
BLACK -> R.style.Theme_RetroMusic_Black
AUTO -> R.style.Theme_RetroMusic_FollowSystem
}
}
fun getNightMode(

View file

@ -35,23 +35,26 @@ class BottomNavigationBarTinted @JvmOverloads constructor(
init {
labelVisibilityMode = PreferenceUtil.tabTitleMode
val iconColor = ATHUtil.resolveColor(context, android.R.attr.colorControlNormal)
val accentColor = ThemeStore.accentColor(context)
NavigationViewUtil.setItemIconColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
NavigationViewUtil.setItemTextColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
itemRippleColor = ColorStateList.valueOf(accentColor.addAlpha())
background = ColorDrawable(ATHUtil.resolveColor(context, R.attr.colorSurface))
if (!PreferenceUtil.materialYou) {
val iconColor = ATHUtil.resolveColor(context, android.R.attr.colorControlNormal)
val accentColor = ThemeStore.accentColor(context)
NavigationViewUtil.setItemIconColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
NavigationViewUtil.setItemTextColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
itemRippleColor = ColorStateList.valueOf(accentColor.addAlpha(0.08F))
background = ColorDrawable(ATHUtil.resolveColor(context, R.attr.colorSurface))
itemActiveIndicatorColor = ColorStateList.valueOf(accentColor.addAlpha(0.12F))
}
}
}
fun Int.addAlpha(): Int {
return ColorUtil.withAlpha(this, 0.12f)
fun Int.addAlpha(alpha: Float): Int {
return ColorUtil.withAlpha(this, alpha)
}

View file

@ -32,7 +32,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.retromusic.R;
public class PopupBackground extends Drawable {
@ -47,10 +46,10 @@ public class PopupBackground extends Drawable {
@NonNull private final Matrix mTempMatrix = new Matrix();
public PopupBackground(@NonNull Context context) {
public PopupBackground(@NonNull Context context, int color) {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(ThemeStore.Companion.accentColor(context));
mPaint.setColor(color);
mPaint.setStyle(Paint.Style.FILL);
Resources resources = context.getResources();
mPaddingStart = resources.getDimensionPixelOffset(R.dimen.afs_md2_popup_padding_start);