From 444e4299d6697fd658261465f7cfb34d2db54bbd Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Wed, 25 May 2022 11:03:59 -0600 Subject: [PATCH] widgets: revert most widget changes Revert the introduction of the thin/tiny widgets, but keep the new cover layout I created while working on them. There is simply no way I can cram controls and metadata within the size bucket that the thin widget occupies. I have decided to give up and revert the widget to it's old form. I understand why the thin widget is not appealing. However, the sizing at which a widget can properly accomodate a taller widget is just too precise and not really large enough to justify it's existance. --- CHANGELOG.md | 2 +- app/build.gradle | 11 +-- .../org/oxycblt/auxio/home/HomeViewModel.kt | 2 +- .../auxio/playback/PlaybackPanelFragment.kt | 2 - .../{Models.kt => ReplayGainMode.kt} | 13 +-- .../playback/replaygain/ReplayGainPreAmp.kt | 26 +++++ .../auxio/playback/state/RepeatMode.kt | 6 +- .../playback/system/MediaSessionComponent.kt | 16 ++- .../oxycblt/auxio/settings/SettingsCompat.kt | 2 +- .../oxycblt/auxio/settings/SettingsManager.kt | 6 +- .../org/oxycblt/auxio/ui/StyledImageButton.kt | 2 +- .../org/oxycblt/auxio/ui/StyledImageView.kt | 11 ++- .../auxio/ui/ViewBindingDialogFragment.kt | 35 +++++-- .../oxycblt/auxio/ui/ViewBindingFragment.kt | 23 ++++- .../org/oxycblt/auxio/ui/accent/Accent.kt | 23 ++++- .../oxycblt/auxio/ui/accent/AccentAdapter.kt | 25 ++--- .../auxio/ui/accent/AccentCustomizeDialog.kt | 10 +- .../org/oxycblt/auxio/util/ContextUtil.kt | 12 +-- .../java/org/oxycblt/auxio/widgets/Forms.kt | 15 +-- .../oxycblt/auxio/widgets/WidgetProvider.kt | 3 +- app/src/main/res/layout/widget_large.xml | 2 +- app/src/main/res/layout/widget_medium.xml | 2 +- app/src/main/res/layout/widget_small.xml | 2 +- app/src/main/res/layout/widget_thin.xml | 80 +++++++-------- app/src/main/res/layout/widget_tiny.xml | 99 ------------------- app/src/main/res/layout/widget_wide.xml | 2 +- 26 files changed, 201 insertions(+), 231 deletions(-) rename app/src/main/java/org/oxycblt/auxio/playback/replaygain/{Models.kt => ReplayGainMode.kt} (82%) create mode 100644 app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainPreAmp.kt delete mode 100644 app/src/main/res/layout/widget_tiny.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index be7d57f16..6d98172e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ #### What's Improved - Re-enabled theme customization on Android 12 - The tab selector now hides itself when there is only one tab -- Added more buttons to the smallest widget form +- Made the cover on the thin widget larger #### What's Fixed - Fixed incorrect ellipsizing on song items diff --git a/app/build.gradle b/app/build.gradle index 465ca89a9..d753ead3b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,15 +24,15 @@ android { // ExoPlayer needs Java 8 to compile. + compileOptions { + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { jvmTarget = "1.8" freeCompilerArgs += "-Xjvm-default=all" } - compileOptions { - targetCompatibility JavaVersion.VERSION_1_8 - } - buildTypes { debug { debuggable true @@ -94,8 +94,7 @@ dependencies { // Exoplayer // WARNING: THE EXOPLAYER VERSION MUST BE KEPT IN LOCK-STEP WITH THE FLAC EXTENSION. // IF NOT, VERY UNFRIENDLY BUILD FAILURES AND CRASHES MAY ENSUE. - def exoplayerVersion = "2.17.1" - implementation "com.google.android.exoplayer:exoplayer-core:$exoplayerVersion" + implementation "com.google.android.exoplayer:exoplayer-core:2.17.1" implementation fileTree(dir: "libs", include: ["extension-*.aar"]) // Image loading diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt index 23c7fd490..b32b9dc47 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt @@ -145,7 +145,7 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback, MusicStore.Callback } } - override fun onLibraryChanged() { + override fun onLibrarySettingsChanged() { tabs = visibleTabs _shouldRecreateTabs.value = true } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt index 23bce6afe..dd8bfcee1 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt @@ -66,8 +66,6 @@ class PlaybackPanelFragment : ) { // --- UI SETUP --- - logD(binding.root.paddingBottom) - binding.root.setOnApplyWindowInsetsListener { _, insets -> val bars = insets.systemBarInsetsCompat val gestures = insets.systemGestureInsetsCompat diff --git a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/Models.kt b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainMode.kt similarity index 82% rename from app/src/main/java/org/oxycblt/auxio/playback/replaygain/Models.kt rename to app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainMode.kt index 87ffc95dd..04c1b05d1 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/Models.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainMode.kt @@ -31,8 +31,9 @@ enum class ReplayGainMode { DYNAMIC; companion object { - fun fromIntCode(value: Int): ReplayGainMode? { - return when (value) { + /** Convert an int [code] into an instance, or null if it isn't valid. */ + fun fromIntCode(code: Int): ReplayGainMode? { + return when (code) { IntegerTable.REPLAY_GAIN_MODE_OFF -> OFF IntegerTable.REPLAY_GAIN_MODE_TRACK -> TRACK IntegerTable.REPLAY_GAIN_MODE_ALBUM -> ALBUM @@ -42,11 +43,3 @@ enum class ReplayGainMode { } } } - -/** Represents the ReplayGain pre-amp values. */ -data class ReplayGainPreAmp( - /** The value to use when ReplayGain tags are present. */ - val with: Float, - /** The value to use when ReplayGain tags are not present. */ - val without: Float, -) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainPreAmp.kt b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainPreAmp.kt new file mode 100644 index 000000000..33fb3d412 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainPreAmp.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Auxio Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.oxycblt.auxio.playback.replaygain + +/** Represents the ReplayGain pre-amp values. */ +data class ReplayGainPreAmp( + /** The value to use when ReplayGain tags are present. */ + val with: Float, + /** The value to use when ReplayGain tags are not present. */ + val without: Float, +) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/RepeatMode.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/RepeatMode.kt index 1162e308c..5ac7adcf2 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/RepeatMode.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/RepeatMode.kt @@ -59,9 +59,9 @@ enum class RepeatMode { } companion object { - /** Convert an int [constant] into a LoopMode, or null if it isn't valid. */ - fun fromIntCode(constant: Int): RepeatMode? { - return when (constant) { + /** Convert an int [code] into an instance, or null if it isn't valid. */ + fun fromIntCode(code: Int): RepeatMode? { + return when (code) { IntegerTable.REPEAT_MODE_NONE -> NONE IntegerTable.REPEAT_MODE_ALL -> ALL IntegerTable.REPEAT_MODE_TRACK -> TRACK diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt index a455289bf..e46085d00 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt @@ -32,6 +32,7 @@ import org.oxycblt.auxio.playback.state.PlaybackStateManager import org.oxycblt.auxio.playback.state.RepeatMode import org.oxycblt.auxio.settings.SettingsManager import org.oxycblt.auxio.util.logD +import org.oxycblt.auxio.util.unlikelyToBeNull /** */ @@ -106,10 +107,21 @@ class MediaSessionComponent(private val context: Context, private val player: Pl .putText(MediaMetadataCompat.METADATA_KEY_COMPOSER, artist) .putText(MediaMetadataCompat.METADATA_KEY_WRITER, artist) .putText(MediaMetadataCompat.METADATA_KEY_GENRE, song.genre.resolveName(context)) - .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, song.track?.toLong() ?: 0L) - .putText(MediaMetadataCompat.METADATA_KEY_DATE, song.album.year?.toString()) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.durationMs) + if (song.track != null) { + metadata.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, song.track.toLong()) + } + + if (song.disc != null) { + metadata.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, song.disc.toLong()) + } + + if (song.album.year != null) { + metadata.putString( + MediaMetadataCompat.METADATA_KEY_DATE, unlikelyToBeNull(song.album.year).toString()) + } + // Normally, android expects one to provide a URI to the metadata instance instead of // a full blown bitmap. In practice, this is not ideal in the slightest, as we cannot // provide any user customization or quality of life improvements with a flat URI. diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt index 38d652046..9c6781e67 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt @@ -66,7 +66,7 @@ fun handleAccentCompat(prefs: SharedPreferences): Accent { } } - return Accent(prefs.getInt(SettingsManager.KEY_ACCENT, 5)) + return Accent.from(prefs.getInt(SettingsManager.KEY_ACCENT, 5)) } /** Cache of the old keys used in Auxio. */ diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt index ac8251a10..5c658d1ca 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt @@ -65,7 +65,7 @@ class SettingsManager private constructor(context: Context) : } /** - * Whether to display the LoopMode or the shuffle status on the notification. False if loop, + * Whether to display the RepeatMode or the shuffle status on the notification. False if repeat, * true if shuffle. */ val useAltNotifAction: Boolean @@ -256,7 +256,7 @@ class SettingsManager private constructor(context: Context) : when (key) { KEY_USE_ALT_NOTIFICATION_ACTION -> callbacks.forEach { it.onNotifSettingsChanged() } KEY_SHOW_COVERS, KEY_QUALITY_COVERS -> callbacks.forEach { it.onCoverSettingsChanged() } - KEY_LIB_TABS -> callbacks.forEach { it.onLibraryChanged() } + KEY_LIB_TABS -> callbacks.forEach { it.onLibrarySettingsChanged() } KEY_REPLAY_GAIN, KEY_PRE_AMP_WITH, KEY_PRE_AMP_WITHOUT -> callbacks.forEach { it.onReplayGainSettingsChanged() } } @@ -268,7 +268,7 @@ class SettingsManager private constructor(context: Context) : * context. */ interface Callback { - fun onLibraryChanged() {} + fun onLibrarySettingsChanged() {} fun onNotifSettingsChanged() {} fun onCoverSettingsChanged() {} fun onReplayGainSettingsChanged() {} diff --git a/app/src/main/java/org/oxycblt/auxio/ui/StyledImageButton.kt b/app/src/main/java/org/oxycblt/auxio/ui/StyledImageButton.kt index 7d187c8e8..7243523e1 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/StyledImageButton.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/StyledImageButton.kt @@ -77,7 +77,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - // TODO: Scale this drawable based on available space after padding + // FIXME: Scale this drawable based on available space after padding imageMatrix = centerMatrix.apply { diff --git a/app/src/main/java/org/oxycblt/auxio/ui/StyledImageView.kt b/app/src/main/java/org/oxycblt/auxio/ui/StyledImageView.kt index 2349271bd..30bdc9af6 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/StyledImageView.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/StyledImageView.kt @@ -63,6 +63,12 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr styledAttrs.recycle() + // Use clipToOutline and a background drawable to crop images. While Coil's transformation + // could theoretically be used to round corners, the corner radius is dependent on the + // dimensions of the image, which will result in inconsistent corners across different + // album covers unless we resize all covers to be the same size. clipToOutline is both + // cheaper and more elegant. As a side-note, this also allows us to re-use the same + // background for both the tonal background color and the corner rounding. clipToOutline = true background = MaterialShapeDrawable().apply { @@ -79,11 +85,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr override fun onAttachedToWindow() { super.onAttachedToWindow() - // Use clipToOutline and a background drawable to crop images. While Coil's transformation - // could theoretically be used to round corners, the corner radius is dependent on the - // dimensions of the image, which will result in inconsistent corners across different - // album covers unless we resize all covers to be the same size. clipToOutline is both - // cheaper and more elegant. if (!isInEditMode) { val settingsManager = SettingsManager.getInstance() if (settingsManager.roundCovers) { diff --git a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingDialogFragment.kt b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingDialogFragment.kt index c5aff2564..e4e22118e 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingDialogFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingDialogFragment.kt @@ -17,7 +17,6 @@ package org.oxycblt.auxio.ui -import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -35,17 +34,39 @@ import org.oxycblt.auxio.util.logD abstract class ViewBindingDialogFragment : DialogFragment() { private var _binding: T? = null + /** + * Inflate the binding from the given [inflater]. This should usually be done by the binding + * implementation's inflate function. + */ protected abstract fun onCreateBinding(inflater: LayoutInflater): T - protected open fun onBindingCreated(binding: T, savedInstanceState: Bundle?) {} - protected open fun onDestroyBinding(binding: T) {} + + /** Called during [onCreateDialog]. Dialog elements should be configured here. */ protected open fun onConfigDialog(builder: AlertDialog.Builder) {} + /** + * Called during [onViewCreated] when the binding was successfully inflated and set as the view. + * This is where view setup should occur. + */ + protected open fun onBindingCreated(binding: T, savedInstanceState: Bundle?) {} + + /** + * Called during [onDestroyView] when the binding should be destroyed and all callbacks or + * leaking elements be released. + */ + protected open fun onDestroyBinding(binding: T) {} + + /** Maybe get the binding. This will be null outside of the fragment view lifecycle. */ protected val binding: T? get() = _binding + /** + * Get the binding under the assumption that the fragment has a view at this state in the + * lifecycle. This will throw an exception if the fragment is not in a valid lifecycle. + */ protected fun requireBinding(): T { return requireNotNull(_binding) { - "ViewBinding was not available, as the fragment was not in a valid state" + "ViewBinding was available. Fragment should be a valid state " + + "right now, but instead it was ${lifecycle.currentState}" } } @@ -55,12 +76,11 @@ abstract class ViewBindingDialogFragment : DialogFragment() { savedInstanceState: Bundle? ): View = onCreateBinding(inflater).also { _binding = it }.root - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return MaterialAlertDialogBuilder(requireActivity(), theme).run { + override fun onCreateDialog(savedInstanceState: Bundle?) = + MaterialAlertDialogBuilder(requireActivity(), theme).run { onConfigDialog(this) create() } - } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -73,5 +93,6 @@ abstract class ViewBindingDialogFragment : DialogFragment() { super.onDestroyView() onDestroyBinding(requireBinding()) _binding = null + logD("Fragment destroyed") } } diff --git a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingFragment.kt b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingFragment.kt index 4497abac4..3267dc6a2 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingFragment.kt @@ -32,16 +32,36 @@ import org.oxycblt.auxio.util.logD abstract class ViewBindingFragment : Fragment() { private var _binding: T? = null + /** + * Inflate the binding from the given [inflater]. This should usually be done by the binding + * implementation's inflate function. + */ protected abstract fun onCreateBinding(inflater: LayoutInflater): T + + /** + * Called during [onViewCreated] when the binding was successfully inflated and set as the view. + * This is where view setup should occur. + */ protected open fun onBindingCreated(binding: T, savedInstanceState: Bundle?) {} + + /** + * Called during [onDestroyView] when the binding should be destroyed and all callbacks or + * leaking elements be released. + */ protected open fun onDestroyBinding(binding: T) {} + /** Maybe get the binding. This will be null outside of the fragment view lifecycle. */ protected val binding: T? get() = _binding + /** + * Get the binding under the assumption that the fragment has a view at this state in the + * lifecycle. This will throw an exception if the fragment is not in a valid lifecycle. + */ protected fun requireBinding(): T { return requireNotNull(_binding) { - "ViewBinding was not available, as the fragment was not in a valid state" + "ViewBinding was available. Fragment should be a valid state " + + "right now, but instead it was ${lifecycle.currentState}" } } @@ -61,5 +81,6 @@ abstract class ViewBindingFragment : Fragment() { super.onDestroyView() onDestroyBinding(requireBinding()) _binding = null + logD("Fragment destroyed") } } diff --git a/app/src/main/java/org/oxycblt/auxio/ui/accent/Accent.kt b/app/src/main/java/org/oxycblt/auxio/ui/accent/Accent.kt index ac44ebe0f..d70ac06c6 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/accent/Accent.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/accent/Accent.kt @@ -19,9 +19,7 @@ package org.oxycblt.auxio.ui.accent import android.os.Build import org.oxycblt.auxio.R - -val ACCENT_COUNT: Int - get() = ACCENT_NAMES.size +import org.oxycblt.auxio.util.logW private val ACCENT_NAMES = intArrayOf( @@ -116,7 +114,7 @@ private val ACCENT_PRIMARY_COLORS = * @property primary The primary color resource for this accent * @author OxygenCobalt */ -data class Accent(val index: Int) { +class Accent private constructor(val index: Int) { val name: Int get() = ACCENT_NAMES[index] val theme: Int @@ -126,7 +124,24 @@ data class Accent(val index: Int) { val primary: Int get() = ACCENT_PRIMARY_COLORS[index] + override fun equals(other: Any?) = other is Accent && index == other.index + + override fun hashCode() = index.hashCode() + companion object { + fun from(index: Int): Accent { + if (index > (MAX - 1)) { + logW("Account outside of bounds [idx: $index, max: $MAX") + return Accent(5) + } + + return Accent(index) + } + + /** + * The maximum amount of accents that are valid. This excludes the dynamic accent on + * versions that do not support it. + */ val MAX = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ACCENT_THEMES.size diff --git a/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentAdapter.kt b/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentAdapter.kt index 684928e37..ee8066e04 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentAdapter.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentAdapter.kt @@ -30,7 +30,10 @@ import org.oxycblt.auxio.util.getColorSafe import org.oxycblt.auxio.util.inflater import org.oxycblt.auxio.util.stateList -/** An adapter that displays the accent palette. */ +/** + * An adapter that displays the accent palette. + * @author OxygenCobalt + */ class AccentAdapter(listener: Listener) : MonoAdapter(listener) { var selectedAccent: Accent? = null @@ -64,7 +67,7 @@ class AccentAdapter(listener: Listener) : } class AccentData : BackingData() { - override fun getItem(position: Int) = Accent(position) + override fun getItem(position: Int) = Accent.from(position) override fun getItemCount() = Accent.MAX } } @@ -84,15 +87,15 @@ class AccentViewHolder private constructor(private val binding: ItemAccentBindin } fun setSelected(isSelected: Boolean) { - val context = binding.accent.context - - binding.accent.isEnabled = !isSelected - binding.accent.imageTintList = - if (isSelected) { - context.getAttrColorSafe(R.attr.colorSurface).stateList - } else { - context.getColorSafe(android.R.color.transparent).stateList - } + binding.accent.apply { + isEnabled = !isSelected + imageTintList = + if (isSelected) { + context.getAttrColorSafe(R.attr.colorSurface).stateList + } else { + context.getColorSafe(android.R.color.transparent).stateList + } + } } companion object { diff --git a/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentCustomizeDialog.kt b/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentCustomizeDialog.kt index ff2629cd4..c255603b1 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentCustomizeDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/accent/AccentCustomizeDialog.kt @@ -55,17 +55,17 @@ class AccentCustomizeDialog : } override fun onBindingCreated(binding: DialogAccentBinding, savedInstanceState: Bundle?) { + // --- UI SETUP --- + + binding.accentRecycler.adapter = accentAdapter + accentAdapter.setSelectedAccent( if (savedInstanceState != null) { - Accent(savedInstanceState.getInt(KEY_PENDING_ACCENT)) + Accent.from(savedInstanceState.getInt(KEY_PENDING_ACCENT)) } else { settingsManager.accent }, binding.accentRecycler) - - // --- UI SETUP --- - - binding.accentRecycler.adapter = accentAdapter } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/org/oxycblt/auxio/util/ContextUtil.kt b/app/src/main/java/org/oxycblt/auxio/util/ContextUtil.kt index fccea789b..970e83742 100644 --- a/app/src/main/java/org/oxycblt/auxio/util/ContextUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/util/ContextUtil.kt @@ -222,22 +222,20 @@ fun Context.showToast(@StringRes str: Int) { } /** Create a [PendingIntent] that leads to Auxio's [MainActivity] */ -fun Context.newMainIntent(): PendingIntent { - return PendingIntent.getActivity( +fun Context.newMainIntent(): PendingIntent = + PendingIntent.getActivity( this, IntegerTable.REQUEST_CODE, Intent(this, MainActivity::class.java), if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0) -} /** Create a broadcast [PendingIntent] */ -fun Context.newBroadcastIntent(what: String): PendingIntent { - return PendingIntent.getBroadcast( +fun Context.newBroadcastIntent(what: String): PendingIntent = + PendingIntent.getBroadcast( this, IntegerTable.REQUEST_CODE, - Intent(what), + Intent(what).setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0) -} /** Hard-restarts the app. Useful for forcing the app to reload music. */ fun Context.hardRestart() { diff --git a/app/src/main/java/org/oxycblt/auxio/widgets/Forms.kt b/app/src/main/java/org/oxycblt/auxio/widgets/Forms.kt index fc36fb2d0..5f73c4e20 100644 --- a/app/src/main/java/org/oxycblt/auxio/widgets/Forms.kt +++ b/app/src/main/java/org/oxycblt/auxio/widgets/Forms.kt @@ -33,20 +33,13 @@ import org.oxycblt.auxio.util.newMainIntent fun createDefaultWidget(context: Context) = createViews(context, R.layout.widget_default) /** - * The tiny widget like a small or medium widget, but for landscape or exceptionally small screens. - */ -fun createTinyWidget(context: Context, state: WidgetComponent.WidgetState) = - createViews(context, R.layout.widget_tiny) - .applyCover(context, state) - .applyBasicControls(context, state) - -/** - * The thin widget is like a wide or large widget, but for landscape or exceptionally small screens. + * The thin widget is a weird outlier widget intended to work well on strange launchers or + * landscape grid launchers that allow really thin widget sizing. */ fun createThinWidget(context: Context, state: WidgetComponent.WidgetState) = createViews(context, R.layout.widget_thin) - .applyCover(context, state) - .applyFullControls(context, state) + .applyMeta(context, state) + .applyBasicControls(context, state) /** * The small widget is for 2x2 widgets and just shows the cover art and playback controls. This is diff --git a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt index 9b327c96f..3e34adc99 100644 --- a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt +++ b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt @@ -58,8 +58,7 @@ class WidgetProvider : AppWidgetProvider() { // Map each widget form to the cells where it would look at least okay. val views = mapOf( - SizeF(180f, 100f) to createTinyWidget(context, state), - SizeF(372f, 100f) to createThinWidget(context, state), + SizeF(180f, 100f) to createThinWidget(context, state), SizeF(180f, 152f) to createSmallWidget(context, state), SizeF(272f, 152f) to createWideWidget(context, state), SizeF(180f, 270f) to createMediumWidget(context, state), diff --git a/app/src/main/res/layout/widget_large.xml b/app/src/main/res/layout/widget_large.xml index 68f566278..3c1ddc8cf 100644 --- a/app/src/main/res/layout/widget_large.xml +++ b/app/src/main/res/layout/widget_large.xml @@ -8,7 +8,7 @@ android:theme="@style/Theme.Widget"> - - + + + android:layout_weight="2" + android:orientation="horizontal"> - + android:layout_marginEnd="@dimen/spacing_small" + android:orientation="vertical"> - + - + - + + + - diff --git a/app/src/main/res/layout/widget_tiny.xml b/app/src/main/res/layout/widget_tiny.xml deleted file mode 100644 index 5fc01ab16..000000000 --- a/app/src/main/res/layout/widget_tiny.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/widget_wide.xml b/app/src/main/res/layout/widget_wide.xml index 8f64ab103..1c48a33d6 100644 --- a/app/src/main/res/layout/widget_wide.xml +++ b/app/src/main/res/layout/widget_wide.xml @@ -8,7 +8,7 @@ android:theme="@style/Theme.Widget">