all: misc ui reworks

Miscellanious UI reworks that accumulated over the past few days.
This commit is contained in:
OxygenCobalt
2022-07-07 10:40:18 -06:00
parent 1730a73eac
commit 83d6c529e2
42 changed files with 236 additions and 252 deletions
@@ -191,7 +191,6 @@ class GenreDetailFragment :
if (parent is Genre && parent.id == unlikelyToBeNull(detailModel.currentGenre.value).id) {
detailAdapter.highlightSong(song)
} else {
// Clear any highlighting if playback is not occuring from this item.
detailAdapter.highlightSong(null)
}
}
@@ -26,10 +26,10 @@ import androidx.core.view.updatePadding
import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
* A container for a FloatingActionButton that enables edge-to-edge support.
* A [FrameLayout] that automatically applies bottom insets.
* @author OxygenCobalt
*/
class EdgeFabContainer
class EdgeFrameLayout
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
FrameLayout(context, attrs, defStyleAttr) {
@@ -64,7 +64,6 @@ import org.oxycblt.auxio.util.lazyReflectedField
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.logE
import org.oxycblt.auxio.util.logTraceOrThrow
import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.auxio.util.textSafe
/**
@@ -98,7 +97,7 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
binding.homeToolbar.alpha = 1f - (abs(offset.toFloat()) / (range.toFloat() / 2))
binding.homePager.updatePadding(
binding.homeContent.updatePadding(
bottom = binding.homeAppbar.totalScrollRange + offset)
}
}
@@ -107,11 +106,6 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
updateTabConfiguration()
binding.homeIndexingWrapper.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
insets
}
// Load the track color in manually as it's unclear whether the track actually supports
// using a ColorStateList in the resources
binding.homeIndexingProgress.trackColor =
@@ -141,7 +135,7 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
// --- VIEWMODEL SETUP ---
collect(homeModel.isFastScrolling) { updateFab() }
collectImmediately(homeModel.songs, homeModel.isFastScrolling, ::updateFab)
collect(homeModel.recreateTabs, ::handleRecreateTabs)
collectImmediately(homeModel.currentTab, ::updateCurrentTab)
collectImmediately(indexerModel.state, ::handleIndexerState)
@@ -265,8 +259,6 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
binding.homeIndexingContainer.visibility = View.INVISIBLE
}
}
updateFab()
}
private fun handleIndexerResponse(binding: FragmentHomeBinding, response: Indexer.Response) {
@@ -336,12 +328,9 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
}
}
private fun updateFab() {
private fun updateFab(songs: List<Song>, isFastScrolling: Boolean) {
val binding = requireBinding()
val fastScrolling = homeModel.isFastScrolling.value
val state = indexerModel.state.value
if (fastScrolling ||
!(state is Indexer.State.Complete && state.response is Indexer.Response.Ok)) {
if (isFastScrolling || songs.isEmpty()) {
binding.homeFab.hide()
} else {
binding.homeFab.show()
@@ -30,7 +30,8 @@ import org.oxycblt.auxio.util.unlikelyToBeNull
/** [Item] variant that represents a music item. */
sealed class Music : Item() {
// TODO: Split ID into an ID derived from all fields and a persistent ID derived from stable fields
// TODO: Split ID into an ID derived from all fields and a persistent ID derived from stable
// fields
/** The raw name of this item. Null if unknown. */
abstract val rawName: String?
@@ -61,7 +61,7 @@ val Long.albumCoverUri: Uri
* they are invalid.
*/
val String.plainTrackNo: Int?
get() = toIntOrNull()?.let { if (it > 0) it else null }
get() = toIntOrNull()?.nonZeroOrNull()
/**
* Parse out the track number field as if the given Int is formatted as DTTT, where D Is the disc
@@ -69,28 +69,28 @@ val String.plainTrackNo: Int?
* invalid.
*/
val Int.packedTrackNo: Int?
get() = div(1000).let { if (it > 0) it else null }
get() = div(1000).nonZeroOrNull()
/**
* Parse out the disc number field as if the given Int is formatted as DTTT, where D Is the disc and
* T is the track number. Values of zero will be ignored under the assumption that they are invalid.
*/
val Int.packedDiscNo: Int?
get() = mod(1000).let { if (it > 0) it else null }
get() = mod(1000).nonZeroOrNull()
/**
* Parse out the number field from an NN/TT string that is typically found in DISC_NUMBER and
* CD_TRACK_NUMBER. Values of zero will be ignored under the assumption that they are invalid.
*/
val String.trackDiscNo: Int?
get() = split('/', limit = 2)[0].toIntOrNull()?.let { if (it > 0) it else null }
get() = split('/', limit = 2)[0].toIntOrNull()?.nonZeroOrNull()
/**
* Parse out a plain year from a string. Values of 0 will be ignored under the assumption that they
* are invalid.
*/
val String.year: Int?
get() = toIntOrNull()?.let { if (it > 0) it else null }
get() = toIntOrNull()?.nonZeroOrNull()
/**
* Parse out the year field from a (presumably) ISO-8601-like date. This differs across tag formats
@@ -99,7 +99,9 @@ val String.year: Int?
* under the assumption that they are invalid.
*/
val String.iso8601year: Int?
get() = split('-', limit = 2)[0].toIntOrNull()?.let { if (it > 0) it else null }
get() = split('-', limit = 2)[0].toIntOrNull()?.nonZeroOrNull()
private fun Int.nonZeroOrNull() = if (this > 0) this else null
/**
* Slice a string so that any preceding articles like The/A(n) are truncated. This is hilariously
@@ -181,6 +183,7 @@ private val GENRE_RE = Regex("((?:\\(([0-9]+|RX|CR)\\))*)(.+)?")
/**
* A complete table of all the constant genre values for ID3(v2), including non-standard extensions.
* Note that we do not translate these, as that greatly increases technical complexity.
*/
private val GENRE_TABLE =
arrayOf(
@@ -35,7 +35,7 @@ import android.widget.FrameLayout
*
* @author OxygenCobalt
*/
open class NoRtlFrameLayout
open class ForcedLTRFrameLayout
@JvmOverloads
constructor(
context: Context,
@@ -44,7 +44,7 @@ constructor(
) : FrameLayout(context, attrs, defStyleAttr) {
override fun onFinishInflate() {
super.onFinishInflate()
check(childCount == 1) { "This view should only contain one child" }
check(childCount == 1) { "This layout should only contain one child" }
getChildAt(0).layoutDirection = View.LAYOUT_DIRECTION_LTR
}
}
@@ -282,7 +282,10 @@ class PlaybackViewModel(application: Application) :
}
}
/** Force restore the last [PlaybackStateManager] saved state */
/**
* Force restore the last [PlaybackStateManager] saved state, regardless of if a library exists
* or not.
*/
fun restorePlaybackState(onDone: (Boolean) -> Unit) {
viewModelScope.launch {
val restored =
@@ -51,7 +51,7 @@ constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) :
NoRtlFrameLayout(context, attrs, defStyleAttr),
ForcedLTRFrameLayout(context, attrs, defStyleAttr),
Slider.OnSliderTouchListener,
Slider.OnChangeListener {
private val binding = ViewSeekBarBinding.inflate(context.inflater, this, true)
@@ -387,8 +387,7 @@ class PlaybackStateManager private constructor() {
suspend fun sanitize(database: PlaybackStateDatabase, newLibrary: MusicStore.Library) {
// Since we need to sanitize the state and re-save it for consistency, take the
// easy way out and just write a new state and restore from it. Don't really care.
// FIXME: This hack actually creates bugs if a user were to save the state at just
// the right time, replace it with something that operates at runtime
// TODO: Do we even need to save here? Doesn't seem like it's required for
logD("Sanitizing state")
val state = synchronized(this) { makeStateImpl() }
@@ -69,6 +69,8 @@ import org.oxycblt.auxio.widgets.WidgetProvider
*
* TODO: Android Auto
*
* TODO: Attempt to re-unify delayed actions again
*
* @author OxygenCobalt
*/
class PlaybackService :
@@ -285,10 +287,10 @@ class PlaybackService :
// --- SETTINGSMANAGER OVERRIDES ---
override fun onSettingChanged(key: String) {
when (key) {
getString(R.string.set_key_replay_gain),
getString(R.string.set_key_pre_amp_with),
getString(R.string.set_key_pre_amp_without) -> onTracksChanged(player.currentTracks)
if (key == getString(R.string.set_key_replay_gain) ||
key == getString(R.string.set_key_pre_amp_with) ||
key == getString(R.string.set_key_pre_amp_without)) {
onTracksChanged(player.currentTracks)
}
}
@@ -1,53 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.ui
import android.content.Context
import android.util.AttributeSet
import androidx.annotation.AttrRes
import androidx.core.view.updatePaddingRelative
import com.google.android.material.appbar.MaterialToolbar
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.getDimenSizeSafe
/**
* [MaterialToolbar] that automatically fixes padding in order to align with the M3 specs.
* @author OxygenCobalt
*/
class M3Toolbar : MaterialToolbar {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(
context: Context,
attrs: AttributeSet?,
@AttrRes defStyleAttr: Int
) : super(context, attrs, defStyleAttr)
init {
val tinySpacing = context.getDimenSizeSafe(R.dimen.spacing_tiny)
if (navigationIcon != null) {
updatePaddingRelative(start = tinySpacing)
}
if (menu != null) {
updatePaddingRelative(end = tinySpacing)
}
}
}
@@ -26,6 +26,7 @@ import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
// TODO: Differentiate between replace and diffing w/item updates
/**
* An adapter for one viewholder tied to one type of data. All functionality is derived from the
* overridden values.
@@ -40,7 +41,7 @@ abstract class MonoAdapter<T, L, VH : BindingViewHolder<T, L>>(private val liste
/**
* An optional override to further modify the given [viewHolder]. The normal operation is to
* bind the viewholder, with nothing more.
* bind the viewholder.
*/
open fun onBind(viewHolder: VH, item: T, listener: L, payload: List<Any>) {
viewHolder.bind(item, listener)
@@ -34,7 +34,7 @@ import org.oxycblt.auxio.util.getDimenSizeSafe
* used in dialogs.
* @author OxygenCobalt
*/
class DialogRecyclerView
class ScrollIndicatorRecyclerView
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
RecyclerView(context, attrs, defStyleAttr) {
@@ -97,7 +97,7 @@ private fun RemoteViews.applyRoundingToBackground(context: Context): RemoteViews
private fun RemoteViews.applyRoundingToBar(context: Context): RemoteViews {
if (Settings(context).roundMode && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
setInt(R.id.widget_controls, "setBackgroundResource", R.drawable.ui_widget_bg_round)
setInt(R.id.widget_controls, "setBackgroundResource", R.drawable.ui_widget_bar_round)
} else {
setInt(R.id.widget_controls, "setBackgroundResource", R.drawable.ui_widget_bar)
}
@@ -88,7 +88,7 @@ class WidgetComponent(private val context: Context) :
context.getDimenSizeSafe(android.R.dimen.system_app_widget_inner_radius)
} else if (settings.roundMode) {
// < Android 12, but the user still enabled round mode.
context.getDimenSizeSafe(R.dimen.size_corners_large)
context.getDimenSizeSafe(R.dimen.size_corners_medium)
} else {
// User did not enable round mode.
0