ui: remove windowinsetscompat
Remove WindowInsetsCompat from the project, as it is a pile of garbage. WindowInsetsCompat refuses to actually update the correct fields when you transform it back into a WindowInsets. This makes it impossible to use in Auxio. The fact that Google decided to make such an overengineered wrapper to some version-specific methods is an absolute joke. All you needed were some extension functions, but no, let's make an entire wrapper class filled with so many gotchas as to be unusable.
This commit is contained in:
parent
631120dafc
commit
3663396b97
14 changed files with 80 additions and 42 deletions
|
@ -25,6 +25,7 @@ finished saving
|
|||
- Fixed crash that would occur when opening a file on some devices [#176]
|
||||
- Fixed issue where the search filter menu would not display the correct mode
|
||||
- Fixed crash when search filter mode was changed
|
||||
- Fixed shuffle button appearing below playback bar on Android 10 and lower
|
||||
|
||||
#### What's Changed
|
||||
- Reworked typography and iconography to be more aligned with material design guidelines
|
||||
|
|
|
@ -31,9 +31,9 @@ import org.oxycblt.auxio.playback.PlaybackViewModel
|
|||
import org.oxycblt.auxio.playback.system.PlaybackService
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.util.androidViewModels
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.isNight
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* The single [AppCompatActivity] for Auxio.
|
||||
|
@ -118,7 +118,7 @@ class MainActivity : AppCompatActivity() {
|
|||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
contentView.setOnApplyWindowInsetsListener { view, insets ->
|
||||
val bars = insets.getSystemBarInsetsCompat(view)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
view.updatePadding(left = bars.left, right = bars.right)
|
||||
insets
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import android.view.WindowInsets
|
|||
import android.widget.FrameLayout
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.core.view.updatePadding
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* A container for a FloatingActionButton that enables edge-to-edge support.
|
||||
|
@ -42,7 +42,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
}
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
updatePadding(bottom = insets.getSystemBarInsetsCompat(this).bottom)
|
||||
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||
return insets
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,11 +60,11 @@ import org.oxycblt.auxio.util.androidActivityViewModels
|
|||
import org.oxycblt.auxio.util.collect
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.getColorStateListSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -108,7 +108,7 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
|
|||
updateTabConfiguration()
|
||||
|
||||
binding.homeIndexingContainer.setOnApplyWindowInsetsListener { view, insets ->
|
||||
view.updatePadding(bottom = insets.getSystemBarInsetsCompat(view).bottom)
|
||||
view.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,9 @@ import org.oxycblt.auxio.util.clamp
|
|||
import org.oxycblt.auxio.util.getDimenOffsetSafe
|
||||
import org.oxycblt.auxio.util.getDimenSizeSafe
|
||||
import org.oxycblt.auxio.util.getDrawableSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.isRtl
|
||||
import org.oxycblt.auxio.util.isUnder
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* A [RecyclerView] that enables better fast-scrolling. This is fundamentally a implementation of
|
||||
|
@ -283,7 +283,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
super.onApplyWindowInsets(insets)
|
||||
val bars = insets.getSystemBarInsetsCompat(this)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
thumbPadding.bottom = bars.bottom
|
||||
return insets
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ import org.oxycblt.auxio.ui.fragment.ViewBindingFragment
|
|||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.getColorStateListSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.getSystemGestureInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemGestureInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
|
@ -64,8 +64,8 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
|||
// any gesture events. So, apply the system gesture insets if present as long
|
||||
// as they are *larger* than the bar insets. This is to resolve issues where
|
||||
// the gesture insets are not sane on OEM devices.
|
||||
val bars = insets.getSystemBarInsetsCompat(view)
|
||||
val gestures = insets.getSystemGestureInsetsCompat(view)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
val gestures = insets.systemGestureInsetsCompat
|
||||
view.updatePadding(bottom = max(bars.bottom, gestures.bottom))
|
||||
insets
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ import org.oxycblt.auxio.ui.fragment.ViewBindingFragment
|
|||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.getDrawableSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.getSystemGestureInsetsCompat
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemGestureInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,8 @@ class PlaybackPanelFragment :
|
|||
// just for quality of life. While the old 3-button navigation does this for us, when
|
||||
// bar navigation is used, we use the gesture padding to add that extra portion of
|
||||
// space.
|
||||
val bars = insets.getSystemBarInsetsCompat(view)
|
||||
val gestures = insets.getSystemGestureInsetsCompat(view)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
val gestures = insets.systemGestureInsetsCompat
|
||||
view.updatePadding(top = bars.top, bottom = max(gestures.bottom, bars.bottom))
|
||||
insets
|
||||
}
|
||||
|
|
|
@ -101,7 +101,6 @@ class NotificationComponent(
|
|||
object : BitmapProvider.Target {
|
||||
override fun onCompleted(bitmap: Bitmap?) {
|
||||
logD("writing ${song.rawName} to notif")
|
||||
setLargeIcon(bitmap)
|
||||
setContentTitle(song.resolveName(context))
|
||||
setContentText(song.resolveIndividualArtistName(context))
|
||||
|
||||
|
@ -115,6 +114,8 @@ class NotificationComponent(
|
|||
setSubText(song.album.resolveName(context))
|
||||
}
|
||||
|
||||
setLargeIcon(bitmap)
|
||||
|
||||
callback.onNotificationChanged(song, this@NotificationComponent)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -39,9 +39,9 @@ import org.oxycblt.auxio.ui.fragment.ViewBindingFragment
|
|||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.formatDuration
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ class AboutFragment : ViewBindingFragment<FragmentAboutBinding>() {
|
|||
|
||||
override fun onBindingCreated(binding: FragmentAboutBinding, savedInstanceState: Bundle?) {
|
||||
binding.aboutContents.setOnApplyWindowInsetsListener { view, insets ->
|
||||
view.updatePadding(bottom = insets.getSystemBarInsetsCompat(view).bottom)
|
||||
view.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@ import org.oxycblt.auxio.settings.ui.IntListPreferenceDialog
|
|||
import org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
||||
import org.oxycblt.auxio.ui.accent.AccentCustomizeDialog
|
||||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.hardRestart
|
||||
import org.oxycblt.auxio.util.isNight
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* The actual fragment containing the settings menu. Inherits [PreferenceFragmentCompat].
|
||||
|
@ -68,7 +68,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
|||
clipToPadding = false
|
||||
|
||||
setOnApplyWindowInsetsListener { _, insets ->
|
||||
updatePadding(bottom = insets.getSystemBarInsetsCompat(this).bottom)
|
||||
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||
insets
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,13 +45,13 @@ import org.oxycblt.auxio.util.disableDropShadowCompat
|
|||
import org.oxycblt.auxio.util.getAttrColorSafe
|
||||
import org.oxycblt.auxio.util.getDimenSafe
|
||||
import org.oxycblt.auxio.util.getDimenSizeSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.isUnder
|
||||
import org.oxycblt.auxio.util.lazyReflectedField
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.pxOfDp
|
||||
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.stateList
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* A layout that *properly* handles bottom sheet functionality.
|
||||
|
@ -387,7 +387,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
|||
// space the sheet has consumed, and then combine that with the existing bottom inset to
|
||||
// see which one should be applied. Note that we do not include the expanded sheet into
|
||||
// this calculation, as it should be covered up by the bottom sheet.
|
||||
val bars = insets.getSystemBarInsetsCompat(this)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
val consumedByNonExpandedSheet =
|
||||
measuredHeight - calculateSheetTopPosition(min(sheetOffset, 0f))
|
||||
val adjustedBottomInset = max(consumedByNonExpandedSheet, bars.bottom)
|
||||
|
@ -544,7 +544,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
|||
// window insets as it goes upwards. Do this by progressively modifying the y
|
||||
// translation with a fraction of the said inset.
|
||||
lastInsets?.let { insets ->
|
||||
val bars = insets.getSystemBarInsetsCompat(this)
|
||||
val bars = insets.systemBarInsetsCompat
|
||||
translationY = bars.top * halfOutRatio
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* An [AppBarLayout] that fixes a bug with the default implementation where the lifted state will
|
||||
|
@ -63,7 +63,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
super.onApplyWindowInsets(insets)
|
||||
updatePadding(top = insets.getSystemBarInsetsCompat(this).top)
|
||||
updatePadding(top = insets.systemBarInsetsCompat.top)
|
||||
return insets
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import android.view.WindowInsets
|
|||
import androidx.annotation.AttrRes
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
/** A [RecyclerView] that automatically applies insets to itself. */
|
||||
open class EdgeRecyclerView
|
||||
|
@ -48,7 +48,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
initialPadding.left,
|
||||
initialPadding.top,
|
||||
initialPadding.right,
|
||||
initialPadding.bottom + insets.getSystemBarInsetsCompat(this).bottom)
|
||||
initialPadding.bottom + insets.systemBarInsetsCompat.bottom)
|
||||
|
||||
return insets
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import android.content.Context
|
|||
import android.content.res.ColorStateList
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.graphics.Insets
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
|
@ -30,9 +32,7 @@ import android.widget.TextView
|
|||
import androidx.activity.viewModels
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
|
@ -243,25 +243,61 @@ fun <R> SQLiteDatabase.queryAll(tableName: String, block: (Cursor) -> R) =
|
|||
* Resolve system bar insets in a version-aware manner. This can be used to apply padding to a view
|
||||
* that properly follows all the frustrating changes that were made between Android 8-11.
|
||||
*/
|
||||
fun WindowInsets.getSystemBarInsetsCompat(view: View) =
|
||||
WindowInsetsCompat.toWindowInsetsCompat(this, view)
|
||||
.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
val WindowInsets.systemBarInsetsCompat: Rect
|
||||
get() =
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
getInsets(WindowInsets.Type.systemBars()).run { Rect(left, top, right, bottom) }
|
||||
}
|
||||
else -> {
|
||||
@Suppress("DEPRECATION")
|
||||
Rect(
|
||||
systemWindowInsetLeft,
|
||||
systemWindowInsetTop,
|
||||
systemWindowInsetRight,
|
||||
systemWindowInsetBottom)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve gesture insets in a version-aware manner. This can be used to apply padding to a view
|
||||
* that properly follows all the frustrating changes that were made between Android 8-11.
|
||||
*/
|
||||
fun WindowInsets.getSystemGestureInsetsCompat(view: View) =
|
||||
WindowInsetsCompat.toWindowInsetsCompat(this, view)
|
||||
.getInsets(WindowInsetsCompat.Type.systemGestures())
|
||||
val WindowInsets.systemGestureInsetsCompat: Rect
|
||||
get() =
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
getInsets(WindowInsets.Type.systemGestures()).run { Rect(left, top, right, bottom) }
|
||||
}
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {
|
||||
@Suppress("DEPRECATION") val gestureInsets = systemGestureInsets
|
||||
Rect(
|
||||
gestureInsets.left,
|
||||
gestureInsets.top,
|
||||
gestureInsets.right,
|
||||
gestureInsets.bottom)
|
||||
}
|
||||
else -> Rect(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the system bar insets in a version-aware manner. This can be used to modify the insets
|
||||
* for child views in a way that follows all of the frustrating changes that were made between 8-11.
|
||||
*/
|
||||
fun WindowInsets.replaceSystemBarInsetsCompat(left: Int, top: Int, right: Int, bottom: Int) =
|
||||
requireNotNull(
|
||||
WindowInsetsCompat.Builder(WindowInsetsCompat.toWindowInsetsCompat(this))
|
||||
.setInsets(WindowInsetsCompat.Type.systemBars(), Insets.of(left, top, right, bottom))
|
||||
.build()
|
||||
.toWindowInsets())
|
||||
fun WindowInsets.replaceSystemBarInsetsCompat(
|
||||
left: Int,
|
||||
top: Int,
|
||||
right: Int,
|
||||
bottom: Int
|
||||
): WindowInsets {
|
||||
return when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
WindowInsets.Builder(this)
|
||||
.setInsets(WindowInsets.Type.systemBars(), Insets.of(left, top, right, bottom))
|
||||
.build()
|
||||
}
|
||||
else -> {
|
||||
@Suppress("DEPRECATION") replaceSystemWindowInsets(left, top, right, bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue