ui: fix misc issues

Fix miscellanious code style/compat/ui issues.
This commit is contained in:
OxygenCobalt 2021-10-31 16:06:00 -06:00
parent 7c1382db49
commit b50a23a47f
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
24 changed files with 140 additions and 112 deletions

View file

@ -98,6 +98,7 @@ class MainFragment : Fragment(), PlaybackBarLayout.ActionCallback {
// Error, show the error to the user
is MusicStore.Response.Err -> {
logD("Received Error")
val errorRes = when (response.kind) {

View file

@ -30,6 +30,10 @@ class FloatingActionButtonContainer @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = -1
) : FrameLayout(context, attrs, defStyleAttr) {
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
return onApplyWindowInsets(insets)
}
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
updatePadding(bottom = insets.systemBarsCompat.bottom)

View file

@ -110,13 +110,8 @@ class FastScrollRecyclerView @JvmOverloads constructor(
hideScrollbar()
}
private val initialPadding = Rect(
paddingLeft, paddingTop, paddingRight, paddingBottom
)
private val scrollerPadding = Rect(
0, 0, 0, 0
)
private val initialPadding = Rect(paddingLeft, paddingTop, paddingRight, paddingBottom)
private val scrollerPadding = Rect(0, 0, 0, 0)
init {
val thumbDrawable = R.drawable.ui_scroll_thumb.resolveDrawable(context)
@ -213,23 +208,23 @@ class FastScrollRecyclerView @JvmOverloads constructor(
popupView.layoutDirection = layoutDirection
val trackLeft = if (isRtl) {
paddingLeft
scrollerPadding.left
} else {
width - paddingRight - thumbWidth
width - scrollerPadding.right - thumbWidth
}
trackView.layout(
trackLeft, paddingTop, trackLeft + thumbWidth,
trackLeft, scrollerPadding.top, trackLeft + thumbWidth,
height - scrollerPadding.bottom
)
val thumbLeft = if (isRtl) {
paddingLeft
scrollerPadding.left
} else {
width - paddingRight - thumbWidth
width - scrollerPadding.right - thumbWidth
}
val thumbTop = paddingTop + thumbOffset
val thumbTop = scrollerPadding.top + thumbOffset
thumbView.layout(thumbLeft, thumbTop, thumbLeft + thumbWidth, thumbTop + thumbHeight)
@ -342,40 +337,10 @@ class FastScrollRecyclerView @JvmOverloads constructor(
return
}
// Getting a pixel-perfect scroll position from a recyclerview is a bit of an involved
// process. It's kind of expected given how RecyclerView well...recycles views, but it's
// still very annoying how many hoops one has to jump through.
// First, we need to get the first visible child. We will use this to extrapolate a rough
// scroll range/position for the view.
// Doing this does mean that the fast scroller will break if you have a header view that's
// a different height, but Auxio's home UI doesn't have something like that so we're okay.
val firstChild = getChildAt(0)
val itemPos = firstAdapterPos
val itemCount = itemCount
// Now get the bounds of the first child. These are the dimensions we use to extrapolate
// information for the whole recyclerview.
getDecoratedBoundsWithMargins(firstChild, childRect)
val itemHeight = childRect.height()
val itemTop = childRect.top
// This is where things get messy. We have to take everything we just calculated and
// do some arithmetic to get it into a working thumb position.
// The total scroll range based on the initial item
val scrollRange = paddingTop + (itemCount * itemHeight) + paddingBottom
// The scroll range where the items aren't visible
val scrollOffsetRange = scrollRange - height
// The scroll offset, or basically the y of the current item + the height of all
// the previous items
val scrollOffset = paddingTop + (itemPos * itemHeight) - itemTop
// The range of pixels where the thumb is not present
val thumbOffsetRange = height - scrollerPadding.top - scrollerPadding.bottom - thumbHeight
// Combine the previous item dimensions with the current item top to find our scroll
// position
getDecoratedBoundsWithMargins(getChildAt(0), childRect)
val scrollOffset = paddingTop + (firstAdapterPos * itemHeight) - childRect.top
// Finally, we can calculate the thumb position, which is just:
// [proportion of scroll position to scroll range] * [total thumb range]

View file

@ -92,11 +92,11 @@ class CompactPlaybackView @JvmOverloads constructor(
fun setPosition(position: Long) {
if (binding.song == null) {
binding.playbackProgress.progress = 0
binding.playbackProgressBar.progress = 0
return
}
binding.playbackProgress.progress = position.toInt()
binding.playbackProgressBar.progress = position.toInt()
}
fun setCallback(callback: PlaybackBarLayout.ActionCallback) {

View file

@ -43,19 +43,19 @@ class PlaybackSeekBar @JvmOverloads constructor(
var onConfirmListener: ((Long) -> Unit)? = null
init {
binding.playbackSeekBar.setOnSeekBarChangeListener(this)
binding.seekBar.setOnSeekBarChangeListener(this)
}
fun setProgress(seconds: Long) {
// Don't update the progress while we are seeking, that will make the SeekBar jump around.
if (!isSeeking) {
binding.playbackSeekBar.progress = seconds.toInt()
binding.seekBar.progress = seconds.toInt()
binding.playbackDurationCurrent.text = seconds.toDuration()
}
}
fun setDuration(seconds: Long) {
binding.playbackSeekBar.max = seconds.toInt()
binding.seekBar.max = seconds.toInt()
binding.playbackSongDuration.text = seconds.toDuration()
}

View file

@ -85,21 +85,21 @@ class SearchViewModel : ViewModel(), MusicStore.MusicCallback {
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_ALBUMS) {
musicStore.albums.filterByOrNull(query)?.let { albums ->
results.add(Header(-1, HeaderString.Single(R.string.lbl_albums)))
results.add(Header(-2, HeaderString.Single(R.string.lbl_albums)))
results.addAll(albums)
}
}
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_GENRES) {
musicStore.genres.filterByOrNull(query)?.let { genres ->
results.add(Header(-1, HeaderString.Single(R.string.lbl_genres)))
results.add(Header(-3, HeaderString.Single(R.string.lbl_genres)))
results.addAll(genres)
}
}
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_SONGS) {
musicStore.songs.filterByOrNull(query)?.let { songs ->
results.add(Header(-1, HeaderString.Single(R.string.lbl_songs)))
results.add(Header(-4, HeaderString.Single(R.string.lbl_songs)))
results.addAll(songs)
}
}

View file

@ -38,7 +38,7 @@ import org.oxycblt.auxio.util.systemBarsCompat
* **Note:** This layout relies on [AppBarLayout.liftOnScrollTargetViewId] to figure out what
* scrolling view to use. Failure to specify this will result in the layout not working.
*/
class LiftAppBarLayout @JvmOverloads constructor(
class EdgeAppBarLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
@StyleRes defStyleAttr: Int = -1
@ -64,12 +64,6 @@ class LiftAppBarLayout @JvmOverloads constructor(
viewTreeObserver.addOnPreDrawListener(onPreDraw)
}
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
super.dispatchApplyWindowInsets(insets)
return onApplyWindowInsets(insets)
}
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
super.onApplyWindowInsets(insets)

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 Auxio Project
* FuckedCoordinatorLayout.kt is part of Auxio.
*
* 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 android.view.WindowInsets
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.children
/**
* Class that fixes an issue where [CoordinatorLayout] will override [onApplyWindowInsets]
* and delegate the job to ***LAYOUT BEHAVIOR INSTANCES*** instead of the actual views.
*
* I can't believe I have to do this.
*/
class EdgeCoordinatorLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = -1
) : CoordinatorLayout(context, attrs, defStyleAttr) {
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
for (child in children) {
child.onApplyWindowInsets(insets)
}
return insets
}
}

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.16" android:color="?attr/colorOnSurface" />
</selector>

View file

@ -4,13 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".settings.AboutFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:orientation="vertical">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/about_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -22,7 +22,7 @@
style="@style/Widget.Auxio.Toolbar.Icon.Down"
app:title="@string/lbl_about" />
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/about_contents"
@ -188,5 +188,5 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</layout>

View file

@ -9,11 +9,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/detail_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -25,7 +25,7 @@
android:id="@+id/detail_toolbar"
style="@style/Widget.Auxio.Toolbar.Icon" />
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<org.oxycblt.auxio.ui.EdgeRecyclerView
android:id="@+id/detail_recycler"
@ -36,6 +36,6 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="@layout/item_detail" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</FrameLayout>
</layout>

View file

@ -4,13 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".home.HomeFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/home_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -36,7 +36,7 @@
app:tabTextAppearance="@style/TextAppearance.Auxio.TabLayout.Label"
app:tabTextColor="@color/sel_accented_primary"/>
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/home_pager"
@ -64,5 +64,5 @@
</org.oxycblt.auxio.home.FloatingActionButtonContainer>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</layout>

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".playback.queue.QueueFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:id="@+id/queue_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -12,7 +12,7 @@
android:background="?attr/colorSurface"
android:orientation="vertical">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/queue_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -27,7 +27,7 @@
app:navigationIcon="@drawable/ic_down"
app:title="@string/lbl_queue" />
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<org.oxycblt.auxio.ui.EdgeRecyclerView
android:id="@+id/queue_recycler"
@ -39,5 +39,5 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="@layout/item_queue_song" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</layout>

View file

@ -3,11 +3,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/search_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -35,6 +35,7 @@
android:id="@+id/search_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:color/transparent"
android:hint="@string/hint_search_library"
android:padding="@dimen/spacing_medium"
@ -45,7 +46,7 @@
</com.google.android.material.appbar.MaterialToolbar>
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<org.oxycblt.auxio.ui.EdgeRecyclerView
android:id="@+id/search_recycler"
@ -56,5 +57,5 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="@layout/item_song" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</layout>

View file

@ -4,14 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".settings.SettingsFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<org.oxycblt.auxio.ui.EdgeCoordinatorLayout
android:id="@+id/settings_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<org.oxycblt.auxio.ui.LiftAppBarLayout
<org.oxycblt.auxio.ui.EdgeAppBarLayout
android:id="@+id/settings_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -25,7 +25,7 @@
style="@style/Widget.Auxio.Toolbar.Icon.Down"
app:title="@string/set_title" />
</org.oxycblt.auxio.ui.LiftAppBarLayout>
</org.oxycblt.auxio.ui.EdgeAppBarLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/settings_list_fragment"
@ -35,5 +35,5 @@
android:clipToPadding="false"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
</layout>

View file

@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{header.string.resolve(context)}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/header_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Songs" />
@ -38,10 +38,16 @@
android:paddingEnd="@dimen/spacing_medium"
android:background="@drawable/ui_small_unbounded_ripple"
android:src="@{context.getDrawable(header.icon)}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/header_divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_sort" />
<com.google.android.material.divider.MaterialDivider
android:id="@+id/header_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.HeaderViewHolder">
<data>
@ -10,11 +11,26 @@
type="org.oxycblt.auxio.music.Header" />
</data>
<TextView
android:id="@android:id/title"
style="@style/Widget.Auxio.TextView.Header"
android:layout_height="wrap_content"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:text="@{header.string.resolve(context)}"
tools:text="Songs" />
android:layout_height="wrap_content">
<TextView
android:id="@android:id/title"
style="@style/Widget.Auxio.TextView.Header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{header.string.resolve(context)}"
app:layout_constraintBottom_toTopOf="@id/header_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Songs" />
<com.google.android.material.divider.MaterialDivider
android:id="@+id/header_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -71,7 +71,7 @@
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/playback_progress"
android:id="@+id/playback_progress_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/size_stroke_large"
android:max="@{(int) song.seconds}"

View file

@ -9,7 +9,7 @@
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<SeekBar
android:id="@+id/playback_seek_bar"
android:id="@+id/seek_bar"
style="@style/Widget.Auxio.SeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="surface">@color/surface_night</color>
<color name="surface_inverse">@color/surface_day</color>
<color name="surface_variant">@color/surface_day</color>
<color name="control">#ffffff</color>
<color name="nav_bar">#01151515</color>

View file

@ -2,7 +2,7 @@
<resources>
<!-- Base app colors -->
<color name="surface">#fafafa</color>
<color name="surface_inverse">@color/surface_night</color>
<color name="surface_variant">@color/surface_night</color>
<color name="control">#202020</color>
<color name="nav_bar">#01fafafa</color>

View file

@ -5,7 +5,6 @@
<!-- Dialog theme where all fixes are applied -->
<style name="Theme.Auxio.Dialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:checkedTextViewStyle">@style/Widget.Auxio.Dialog.CheckedTextView</item>
<item name="colorControlHighlight">@color/overlay_selection</item>
<item name="materialAlertDialogTitleTextStyle">@style/Widget.Auxio.Dialog.TextView</item>
<item name="buttonBarPositiveButtonStyle">@style/Widget.Auxio.Dialog.Button</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.Auxio.Dialog.Button</item>

View file

@ -8,7 +8,7 @@
<style name="Theme.Auxio.V31" parent="Theme.Auxio.V27">
<!-- Make sure to apply more accent-friendly values on older versions -->
<item name="colorSurface">@color/surface</item>
<item name="colorSurfaceInverse">@color/surface_inverse</item>
<item name="colorSurfaceVariant">@color/surface_variant</item>
<item name="colorSecondary">?attr/colorPrimary</item>
<item name="colorOnSecondary">?attr/colorOnPrimary</item>
@ -24,22 +24,24 @@
<!-- Base theme -->
<style name="Theme.Auxio.App" parent="Theme.Auxio.V31">
<!-- Values -->
<item name="colorOutline">@color/overlay_stroke</item>
<item name="colorAccent">?attr/colorSecondary</item>
<item name="colorControlNormal">?attr/colorSurfaceInverse</item>
<item name="colorControlHighlight">@color/overlay_selection</item>
<item name="colorOutline">@color/overlay_stroke</item>
<item name="colorControlNormal">?attr/colorOnSurfaceVariant</item>
<item name="colorControlActivated">?attr/colorSecondary</item>
<!-- Android component magic -->
<item name="android:textColorHighlight">@color/overlay_text_highlight</item>
<item name="android:textColorHighlightInverse">@color/overlay_text_highlight_inverse</item>
<item name="android:colorBackground">?attr/colorSurface</item>
<item name="android:windowBackground">?attr/colorSurface</item>
<item name="android:fontFamily">@font/inter</item>
<item name="android:scrollbars">none</item>
<!-- Material -->
<item name="textInputStyle">@null</item>
<!--
Temporary workaround where the material components text highlight colors are
hard-coded instead of following app colors
-->
<item name="android:textColorHighlight">@color/overlay_text_highlight</item>
<item name="android:textColorHighlightInverse">@color/overlay_text_highlight_inverse</item>
<item name="materialAlertDialogTheme">@style/Theme.Auxio.Dialog</item>
</style>

View file

@ -137,7 +137,6 @@
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:background">@drawable/ui_header_dividers</item>
</style>
<style name="Widget.Auxio.TextView.Detail" parent="Widget.Auxio.TextView.Base">