ui: fix misc issues
Fix miscellanious code style/compat/ui issues.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-7
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user