style: migrate to Material3

Mostly migrate to Material 3/Material You.

- Auxio should now follow dynamic colors on Android 12
- Accents have been regenerated to align with the new color roles
- Some colors have been tweaked here and there to line up with the
new design system
- Dialogs were not fully migrated, but that's because Material3 dialogs
look god-awful.
- Accent class was reworked to take up less memory

Now that this is out of the way, I can focus on other UI things before
the release of 2.0.0.
This commit is contained in:
OxygenCobalt
2021-10-10 16:44:17 -06:00
parent 5ebe17d0ad
commit 8c7f0867f9
87 changed files with 1013 additions and 529 deletions
@@ -90,18 +90,21 @@ class MainActivity : AppCompatActivity() {
}
private fun setupTheme() {
// Update the current accent and theme
val settingsManager = SettingsManager.getInstance()
AppCompatDelegate.setDefaultNightMode(settingsManager.theme)
// We only use Material You theming on Android 12 and above.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
// Update the current accent and theme
val settingsManager = SettingsManager.getInstance()
AppCompatDelegate.setDefaultNightMode(settingsManager.theme)
val newAccent = Accent.set(settingsManager.accent)
val newAccent = Accent.set(settingsManager.accent)
// The black theme has a completely separate set of styles since style attributes cannot
// be modified at runtime.
if (isNight && settingsManager.useBlackTheme) {
setTheme(newAccent.blackTheme)
} else {
setTheme(newAccent.theme)
// The black theme has a completely separate set of styles since style attributes cannot
// be modified at runtime.
if (isNight && settingsManager.useBlackTheme) {
setTheme(newAccent.blackTheme)
} else {
setTheme(newAccent.theme)
}
}
}
@@ -22,76 +22,108 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.text.Spanned
import androidx.annotation.ColorRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
import androidx.core.text.HtmlCompat
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.resolveStateList
/**
* A list of all possible accents.
*/
val ACCENTS = arrayOf(
Accent(R.color.red, R.style.Theme_Auxio_Red, R.style.Theme_Auxio_Black_Red, R.string.clr_red),
Accent(R.color.pink, R.style.Theme_Auxio_Pink, R.style.Theme_Auxio_Black_Pink, R.string.clr_pink),
Accent(R.color.purple, R.style.Theme_Auxio_Purple, R.style.Theme_Auxio_Black_Purple, R.string.clr_purple),
Accent(
R.color.deep_purple,
R.style.Theme_Auxio_DeepPurple,
R.style.Theme_Auxio_Black_DeepPurple,
R.string.clr_deep_purple
),
Accent(R.color.indigo, R.style.Theme_Auxio_Indigo, R.style.Theme_Auxio_Black_Indigo, R.string.clr_indigo),
Accent(R.color.blue, R.style.Theme_Auxio_Blue, R.style.Theme_Auxio_Black_Blue, R.string.clr_blue),
Accent(
R.color.light_blue,
R.style.Theme_Auxio_LightBlue,
R.style.Theme_Auxio_Black_LightBlue,
R.string.clr_light_blue
),
Accent(R.color.cyan, R.style.Theme_Auxio_Cyan, R.style.Theme_Auxio_Black_Cyan, R.string.clr_cyan),
Accent(R.color.teal, R.style.Theme_Auxio_Teal, R.style.Theme_Auxio_Black_Teal, R.string.clr_teal),
Accent(R.color.green, R.style.Theme_Auxio_Green, R.style.Theme_Auxio_Black_Green, R.string.clr_green),
Accent(
R.color.light_green,
R.style.Theme_Auxio_LightGreen,
R.style.Theme_Auxio_Black_LightGreen,
R.string.clr_light_green
),
Accent(R.color.lime, R.style.Theme_Auxio_Lime, R.style.Theme_Auxio_Black_Lime, R.string.clr_lime),
Accent(R.color.yellow, R.style.Theme_Auxio_Yellow, R.style.Theme_Auxio_Black_Yellow, R.string.clr_yellow),
Accent(R.color.orange, R.style.Theme_Auxio_Orange, R.style.Theme_Auxio_Black_Orange, R.string.clr_orange),
Accent(
R.color.deep_orange,
R.style.Theme_Auxio_DeepOrange,
R.style.Theme_Auxio_Black_DeepOrange,
R.string.clr_deep_orange
),
Accent(R.color.brown, R.style.Theme_Auxio_Brown, R.style.Theme_Auxio_Brown, R.string.clr_label_brown),
Accent(R.color.grey, R.style.Theme_Auxio_Grey, R.style.Theme_Auxio_Black_Grey, R.string.clr_label_grey),
Accent(
R.color.blue_grey,
R.style.Theme_Auxio_BlueGrey,
R.style.Theme_Auxio_Black_BlueGrey,
R.string.clr_blue_grey
),
val ACCENT_PRIMARY_COLORS = arrayOf(
R.color.red_primary,
R.color.pink_primary,
R.color.purple_primary,
R.color.deep_purple_primary,
R.color.indigo_primary,
R.color.blue_primary,
R.color.light_blue_primary,
R.color.cyan_primary,
R.color.teal_primary,
R.color.green_primary,
R.color.light_green_primary,
R.color.lime_primary,
R.color.yellow_primary,
R.color.orange_primary,
R.color.deep_orange_primary,
R.color.brown_primary,
R.color.grey_primary,
R.color.blue_grey_primary
)
val ACCENT_THEMES = arrayOf(
R.style.Theme_Auxio_Red,
R.style.Theme_Auxio_Pink,
R.style.Theme_Auxio_Purple,
R.style.Theme_Auxio_DeepPurple,
R.style.Theme_Auxio_Indigo,
R.style.Theme_Auxio_Blue,
R.style.Theme_Auxio_LightBlue,
R.style.Theme_Auxio_Cyan,
R.style.Theme_Auxio_Teal,
R.style.Theme_Auxio_Green,
R.style.Theme_Auxio_LightGreen,
R.style.Theme_Auxio_Lime,
R.style.Theme_Auxio_Yellow,
R.style.Theme_Auxio_Orange,
R.style.Theme_Auxio_DeepOrange,
R.style.Theme_Auxio_Brown,
R.style.Theme_Auxio_Grey,
R.style.Theme_Auxio_BlueGrey
)
val ACCENT_BLACK_THEMES = arrayOf(
R.style.Theme_Auxio_Black_Red,
R.style.Theme_Auxio_Black_Pink,
R.style.Theme_Auxio_Black_Purple,
R.style.Theme_Auxio_Black_DeepPurple,
R.style.Theme_Auxio_Black_Indigo,
R.style.Theme_Auxio_Black_Blue,
R.style.Theme_Auxio_Black_LightBlue,
R.style.Theme_Auxio_Black_Cyan,
R.style.Theme_Auxio_Black_Teal,
R.style.Theme_Auxio_Black_Green,
R.style.Theme_Auxio_Black_LightGreen,
R.style.Theme_Auxio_Black_Lime,
R.style.Theme_Auxio_Black_Yellow,
R.style.Theme_Auxio_Black_Orange,
R.style.Theme_Auxio_Black_DeepOrange,
R.style.Theme_Auxio_Black_Brown,
R.style.Theme_Auxio_Black_Grey,
R.style.Theme_Auxio_Black_BlueGrey
)
val ACCENT_NAMES = arrayOf(
R.string.clr_red,
R.string.clr_pink,
R.string.clr_purple,
R.string.clr_deep_purple,
R.string.clr_indigo,
R.string.clr_blue,
R.string.clr_light_blue,
R.string.clr_cyan,
R.string.clr_teal,
R.string.clr_green,
R.string.clr_light_green,
R.string.clr_lime,
R.string.clr_yellow,
R.string.clr_orange,
R.string.clr_deep_orange,
R.string.clr_brown,
R.string.clr_grey,
R.string.clr_blue_grey
)
/**
* The data object for an accent.
* @property color The color resource for this accent
* @property color The primary color resource for this accent
* @property theme The theme resource for this accent
* @property blackTheme The black theme resource for this accent
* @property name The name of this accent
* @author OxygenCobalt
*/
data class Accent(
@ColorRes val color: Int,
@StyleRes val theme: Int,
@StyleRes val blackTheme: Int,
@StringRes val name: Int
) {
data class Accent(val index: Int) {
val color: Int get() = ACCENT_PRIMARY_COLORS[index]
val theme: Int get() = ACCENT_THEMES[index]
val blackTheme: Int get() = ACCENT_BLACK_THEMES[index]
val name: Int get() = ACCENT_NAMES[index]
/**
* Get a [ColorStateList] of the accent
*/
@@ -38,14 +38,14 @@ class AccentAdapter(
) : RecyclerView.Adapter<AccentAdapter.ViewHolder>() {
private var selectedViewHolder: ViewHolder? = null
override fun getItemCount(): Int = ACCENTS.size
override fun getItemCount(): Int = ACCENT_PRIMARY_COLORS.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(ItemAccentBinding.inflate(parent.context.inflater))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(ACCENTS[position])
holder.bind(Accent(position))
}
private fun setAccent(accent: Accent) {
@@ -47,7 +47,7 @@ class AccentDialog : LifecycleDialog() {
val binding = DialogAccentBinding.inflate(inflater)
savedInstanceState?.getInt(KEY_PENDING_ACCENT)?.let { index ->
pendingAccent = ACCENTS.getOrElse(index) { pendingAccent }
pendingAccent = Accent(index)
}
// --- UI SETUP ---
@@ -70,7 +70,7 @@ class AccentDialog : LifecycleDialog() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(KEY_PENDING_ACCENT, ACCENTS.indexOf(pendingAccent))
outState.putInt(KEY_PENDING_ACCENT, pendingAccent.index)
}
override fun onConfigDialog(builder: AlertDialog.Builder) {
@@ -46,7 +46,7 @@ import kotlin.system.exitProcess
* @author OxygenCobalt
*/
class ExcludedDialog : LifecycleDialog() {
private val blacklistModel: ExcludedViewModel by viewModels {
private val excludedModel: ExcludedViewModel by viewModels {
ExcludedViewModel.Factory(requireContext())
}
@@ -60,7 +60,7 @@ class ExcludedDialog : LifecycleDialog() {
val binding = DialogExcludedBinding.inflate(inflater)
val adapter = ExcludedEntryAdapter { path ->
blacklistModel.removePath(path)
excludedModel.removePath(path)
}
val launcher = registerForActivityResult(
@@ -83,7 +83,7 @@ class ExcludedDialog : LifecycleDialog() {
}
dialog.getButton(AlertDialog.BUTTON_POSITIVE)?.setOnClickListener {
if (blacklistModel.isModified()) {
if (excludedModel.isModified()) {
saveAndRestart()
} else {
dismiss()
@@ -93,7 +93,7 @@ class ExcludedDialog : LifecycleDialog() {
// --- VIEWMODEL SETUP ---
blacklistModel.paths.observe(viewLifecycleOwner) { paths ->
excludedModel.paths.observe(viewLifecycleOwner) { paths ->
adapter.submitList(paths)
binding.excludedEmpty.isVisible = paths.isEmpty()
@@ -122,7 +122,7 @@ class ExcludedDialog : LifecycleDialog() {
val path = parseDocTreePath(uri)
if (path != null) {
blacklistModel.addPath(path)
excludedModel.addPath(path)
} else {
// TODO: Tolerate this once the excluded system is modernized
requireContext().showToast(R.string.err_bad_dir)
@@ -149,7 +149,7 @@ class ExcludedDialog : LifecycleDialog() {
}
private fun saveAndRestart() {
blacklistModel.save {
excludedModel.save {
playbackModel.savePlaybackState(requireContext(), ::hardRestart)
}
}
@@ -37,7 +37,7 @@ class ExcludedViewModel(context: Context) : ViewModel() {
private val mPaths = MutableLiveData(mutableListOf<String>())
val paths: LiveData<MutableList<String>> get() = mPaths
private val blacklistDatabase = ExcludedDatabase.getInstance(context)
private val excludedDatabase = ExcludedDatabase.getInstance(context)
private var dbPaths = listOf<String>()
init {
@@ -69,7 +69,7 @@ class ExcludedViewModel(context: Context) : ViewModel() {
*/
fun save(onDone: () -> Unit) {
viewModelScope.launch(Dispatchers.IO) {
blacklistDatabase.writePaths(mPaths.value!!)
excludedDatabase.writePaths(mPaths.value!!)
dbPaths = mPaths.value!!
onDone()
@@ -81,7 +81,7 @@ class ExcludedViewModel(context: Context) : ViewModel() {
*/
private fun loadDatabasePaths() {
viewModelScope.launch(Dispatchers.IO) {
dbPaths = blacklistDatabase.readPaths()
dbPaths = excludedDatabase.readPaths()
withContext(Dispatchers.Main) {
mPaths.value = dbPaths.toMutableList()
@@ -97,7 +97,7 @@ class ExcludedViewModel(context: Context) : ViewModel() {
class Factory(private val context: Context) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
check(modelClass.isAssignableFrom(ExcludedViewModel::class.java)) {
"BlacklistViewModel.Factory does not support this class"
"ExcludedViewModel.Factory does not support this class"
}
@Suppress("UNCHECKED_CAST")
@@ -23,7 +23,6 @@ import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.view.iterator
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@@ -29,7 +29,6 @@ import org.oxycblt.auxio.music.ActionHeader
import org.oxycblt.auxio.music.BaseModel
import org.oxycblt.auxio.music.Header
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.ui.ActionHeaderViewHolder
import org.oxycblt.auxio.ui.BaseViewHolder
import org.oxycblt.auxio.ui.DiffCallback
@@ -41,7 +40,6 @@ import org.oxycblt.auxio.util.logE
/**
* The single adapter for both the Next Queue and the User Queue.
* @param touchHelper The [ItemTouchHelper] ***containing*** [QueueDragCallback] to be used
* @param playbackModel The [PlaybackViewModel] for updates to be dispatched to
* @author OxygenCobalt
*/
class QueueAdapter(
@@ -27,7 +27,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.ItemTouchHelper
import kotlinx.coroutines.NonDisposableHandle.parent
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentQueueBinding
import org.oxycblt.auxio.music.ActionHeader
@@ -53,7 +53,7 @@ class AboutFragment : Fragment() {
val musicStore = MusicStore.getInstance()
binding.applyEdge { bars ->
binding.aboutAppbar.updatePadding(top = bars.top,)
binding.aboutAppbar.updatePadding(top = bars.top)
binding.aboutContents.updatePadding(bottom = bars.bottom)
}
@@ -20,12 +20,8 @@ package org.oxycblt.auxio.settings
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.updatePadding
import androidx.preference.PreferenceFragmentCompat
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.LifecycleDialog
class IntListPrefDialog : LifecycleDialog() {
@@ -37,23 +33,7 @@ class IntListPrefDialog : LifecycleDialog() {
.findPreference<IntListPreference>(requireArguments().getString(ARG_KEY, null))
)
// Don't set the title. Instead, Set a custom title view so that the padding is actually a
// uniform 16dp between the title and the list of options. I can't believe I have to do this.
val titleView = AppCompatTextView(
ContextThemeWrapper(
requireContext(),
R.style.Widget_Auxio_Dialog_TextView
)
).apply {
text = pref.title
val padding = resources.getDimension(R.dimen.spacing_medium).toInt()
val paddingHack = resources.getDimension(R.dimen.spacing_small).toInt()
updatePadding(left = padding, top = padding, right = padding, bottom = paddingHack)
}
builder.setCustomTitle(titleView)
builder.setTitle(pref.title)
builder.setSingleChoiceItems(pref.entries, pref.getValueIndex()) { _, index ->
pref.setValueIndex(index)
@@ -21,7 +21,7 @@ package org.oxycblt.auxio.settings
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import org.oxycblt.auxio.accent.ACCENTS
import org.oxycblt.auxio.accent.ACCENT_PRIMARY_COLORS
import org.oxycblt.auxio.accent.Accent
import org.oxycblt.auxio.playback.state.PlaybackMode
@@ -70,8 +70,8 @@ fun handleAccentCompat(prefs: SharedPreferences): Accent {
}
// If there are still any issues with indices, just correct them so a crash doesnt occur.
if (accent > ACCENTS.lastIndex) {
accent = ACCENTS.lastIndex
if (accent > ACCENT_PRIMARY_COLORS.lastIndex) {
accent = ACCENT_PRIMARY_COLORS.lastIndex
}
prefs.edit {
@@ -80,10 +80,10 @@ fun handleAccentCompat(prefs: SharedPreferences): Accent {
apply()
}
return ACCENTS[accent]
return Accent(accent)
}
return ACCENTS[prefs.getInt(SettingsManager.KEY_ACCENT, 5)]
return Accent(prefs.getInt(SettingsManager.KEY_ACCENT, 5))
}
fun handleSongPlayModeCompat(prefs: SharedPreferences): PlaybackMode {
@@ -22,7 +22,6 @@ import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import org.oxycblt.auxio.accent.ACCENTS
import org.oxycblt.auxio.accent.Accent
import org.oxycblt.auxio.playback.state.PlaybackMode
import org.oxycblt.auxio.ui.DisplayMode
@@ -58,12 +57,8 @@ class SettingsManager private constructor(context: Context) :
var accent: Accent
get() = handleAccentCompat(sharedPrefs)
set(value) {
val accentIndex = ACCENTS.indexOf(value)
check(accentIndex != -1) { "Invalid accent" }
sharedPrefs.edit {
putInt(KEY_ACCENT, accentIndex)
putInt(KEY_ACCENT, value.index)
apply()
}
}
@@ -23,11 +23,8 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.core.graphics.drawable.toDrawable
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.resolveAttr
/**
* A wrapper around [DialogFragment] that allows the usage of the standard Auxio lifecycle
@@ -37,9 +34,6 @@ abstract class LifecycleDialog : AppCompatDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = MaterialAlertDialogBuilder(requireActivity(), theme)
// Apply a custom background to avoid rounded corners.
builder.background = R.attr.colorSurface.resolveAttr(requireContext()).toDrawable()
onConfigDialog(builder)
return builder.create()
@@ -107,16 +107,6 @@ fun Context.isLandscape(): Boolean {
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
/**
* Determine if we are in tablet mode or not
*/
fun Context.isTablet(): Boolean {
val layout = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return layout == Configuration.SCREENLAYOUT_SIZE_XLARGE ||
layout == Configuration.SCREENLAYOUT_SIZE_LARGE
}
/**
* Determine if the tablet is XLARGE, ignoring normal tablets.
*/
@@ -21,7 +21,6 @@ package org.oxycblt.auxio.util
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.os.Looper
import org.oxycblt.auxio.R
/**
* Shortcut for querying all items in a database and running [block] with the cursor returned.
@@ -27,7 +27,6 @@ import android.os.Build
import android.util.TypedValue
import android.view.View
import android.view.WindowInsets
import android.widget.ImageButton
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
@@ -86,17 +85,6 @@ fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
*/
fun RecyclerView.canScroll(): Boolean = computeVerticalScrollRange() > height
/**
* Disable an image button.
* TODO: Replace this fragile function with something else.
*/
fun ImageButton.disable() {
if (isEnabled) {
imageTintList = ContextCompat.getColorStateList(context, R.color.overlay_disabled)
isEnabled = false
}
}
/**
* Resolve a color.
* @param context [Context] required