all: misc changes

Miscellanious changes that accumulated over time.
This commit is contained in:
OxygenCobalt
2022-07-31 15:51:12 -06:00
parent 170cdf80ef
commit b42dfd0b53
14 changed files with 105 additions and 83 deletions
@@ -29,10 +29,21 @@ import org.oxycblt.auxio.ui.AuxioSheetBehavior
import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.auxio.util.systemGestureInsetsCompat
/**
* The coordinator layout behavior used for the playback sheet, hacking in the many fixes required
* to make bottom sheets like this work.
* @author OxygenCobalt
*
* TODO: Implement hiding because I have to
*/
class PlaybackSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
AuxioSheetBehavior<V>(context, attributeSet) {
private var lastInsets: WindowInsets? = null
init {
isHideable = true
}
// Hack around issue where the playback sheet will try to intercept nested scrolling events
// before the queue sheet.
override fun onInterceptTouchEvent(
@@ -58,13 +69,16 @@ class PlaybackSheetBehavior<V : View>(context: Context, attributeSet: AttributeS
}
fun hideSafe() {
isDraggable = false
isHideable = true
state = STATE_HIDDEN
if (state != STATE_HIDDEN) {
isDraggable = false
state = STATE_HIDDEN
}
}
fun unhideSafe() {
isHideable = false
isDraggable = true
if (state == STATE_HIDDEN) {
state = STATE_COLLAPSED
isDraggable = true
}
}
}
@@ -58,8 +58,8 @@ private constructor(
elevation = binding.context.getDimenSafe(R.dimen.elevation_normal) * 5
}
val isEnabled: Boolean
get() = binding.songDragHandle.isEnabled
val isPrevious: Boolean
get() = binding.songDragHandle.alpha == 0.5f
init {
binding.body.background =
@@ -87,17 +87,11 @@ private constructor(
binding.body.setOnClickListener { listener.onClick(this) }
if (item.previous) {
binding.songName.alpha = 0.5f
binding.songInfo.alpha = 0.5f
binding.songAlbumCover.alpha = 0.5f
binding.songDragHandle.isEnabled = false
} else {
binding.songName.alpha = 1f
binding.songInfo.alpha = 1f
binding.songAlbumCover.alpha = 1f
binding.songDragHandle.isEnabled = true
}
val alpha = if (item.previous) 0.5f else 1f
binding.songAlbumCover.alpha = alpha
binding.songName.alpha = alpha
binding.songInfo.alpha = alpha
binding.songDragHandle.alpha = alpha
// Roll our own drag handlers as the default ones suck
binding.songDragHandle.setOnTouchListener { _, motionEvent ->
@@ -40,7 +40,7 @@ class QueueDragCallback(private val playbackModel: QueueViewModel) : ItemTouchHe
viewHolder: RecyclerView.ViewHolder
): Int {
val queueHolder = viewHolder as QueueSongViewHolder
return if (queueHolder.isEnabled) {
return if (!queueHolder.isPrevious) {
makeFlag(
ItemTouchHelper.ACTION_STATE_DRAG, ItemTouchHelper.UP or ItemTouchHelper.DOWN) or
makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE, ItemTouchHelper.START)
@@ -19,6 +19,7 @@ package org.oxycblt.auxio.playback.queue
import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.view.isInvisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.ItemTouchHelper
@@ -31,6 +32,13 @@ import org.oxycblt.auxio.util.collectImmediately
/**
* A [Fragment] that shows the queue and enables editing as well.
*
* TODO: Improve index updates
*
* TODO: Test older versions
*
* TODO: Test restoration and song loss
*
* @author OxygenCobalt
*/
class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueItemListener {
@@ -46,6 +54,14 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueItemList
binding.queueRecycler.apply {
adapter = queueAdapter
touchHelper.attachToRecyclerView(this)
addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
binding.queueDivider.isInvisible =
(layoutManager as LinearLayoutManager)
.findFirstCompletelyVisibleItemPosition() < 1
}
})
}
// --- VIEWMODEL SETUP ----
@@ -78,11 +94,12 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueItemList
if (instructions.scrollTo != null) {
val binding = requireBinding()
val lmm = binding.queueRecycler.layoutManager as LinearLayoutManager
val indices =
lmm.findFirstCompletelyVisibleItemPosition()..lmm
.findLastCompletelyVisibleItemPosition()
val start = lmm.findFirstCompletelyVisibleItemPosition()
val end = lmm.findLastCompletelyVisibleItemPosition()
if (instructions.scrollTo !in indices) {
if (start != RecyclerView.NO_POSITION &&
end != RecyclerView.NO_POSITION &&
instructions.scrollTo !in start..end) {
binding.queueRecycler.scrollToPosition(instructions.scrollTo)
}
}
@@ -73,7 +73,7 @@ class QueueViewModel : ViewModel(), PlaybackStateManager.Callback {
playbackManager.moveQueueItem(adapterFrom, adapterTo)
return false
return true
}
fun finishInstructions() {
@@ -25,7 +25,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.bottomsheet.NeoBottomSheetBehavior
import kotlin.math.abs
import org.oxycblt.auxio.util.coordinatorLayoutBehavior
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
import org.oxycblt.auxio.util.systemBarInsetsCompat
@@ -61,7 +60,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
layoutContent(child)
if (!setup) {
child.setOnApplyWindowInsetsListener { v, insets ->
lastInsets = insets
val dep = dep ?: return@setOnApplyWindowInsetsListener insets
@@ -94,8 +92,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
}
private fun layoutContent(child: View) {
logD("Measure")
child.layout(0, 0, child.measuredWidth, child.measuredHeight)
}
@@ -126,8 +122,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
child: V,
dependency: View
): Boolean {
logD("Dependent view changed $child")
val behavior = dependency.coordinatorLayoutBehavior as NeoBottomSheetBehavior
val consumed = behavior.calculateConsumedByBar()
if (consumed < Int.MIN_VALUE) {
@@ -135,8 +129,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
}
if (consumed != lastConsumed) {
logD("Dependent view changed important $child")
lastConsumed = consumed
val insets = lastInsets
@@ -95,16 +95,14 @@ class WidgetComponent(private val context: Context) :
}
// Resize the image in a such a way that we don't hit the RemoteView size
// limit. The limit is technically the byte-size of an RGB_8888 bitmap 1.5x
// the screen size, but the size of a RemoteView can for some reason be 10x
// the size of the binded bitmaps, which means we need to heavily reduce
// our image size as to make sure we stay around an order of magnitude below
// the memory limit. This fixed size is also needed to ensure consistent
// outlines on rounded images.
// limit, which is the size of an RGB_8888 bitmap 1.5x the screen size. Note
// that we actually set the limit to be half the memory limit so that it's
// less likely for us to hit it. it to really ensure we don't hit the limit.
// This also creates the consistent sizes required for round bitmaps.
val metrics = context.resources.displayMetrics
val sw = metrics.widthPixels
val sh = metrics.heightPixels
builder.size((sqrt((6f * sw * sh)) / 8f).toInt())
builder.size((sqrt((6f * sw * sh) / 8f)).toInt())
return if (cornerRadius > 0) {
this@WidgetComponent.logD("Loading round covers: $cornerRadius")
@@ -63,7 +63,7 @@ class WidgetProvider : AppWidgetProvider() {
SizeF(180f, 272f) to createMediumWidget(context, state),
SizeF(272f, 272f) to createLargeWidget(context, state))
AppWidgetManager.getInstance(context).applyViewsCompat(context, views)
AppWidgetManager.getInstance(context).updateAppWidgetCompat(context, views)
}
/*
@@ -114,7 +114,7 @@ class WidgetProvider : AppWidgetProvider() {
context.sendBroadcast(intent)
}
private fun AppWidgetManager.applyViewsCompat(
private fun AppWidgetManager.updateAppWidgetCompat(
context: Context,
views: Map<SizeF, RemoteViews>
) {