ui: remove coordinatorlayout workarounds
Remove EdgeCoordinatorLayout in favor of using fitsSystemWindows when needed. EdgeCoordinatorLayout was derived from a misunderstanding about how window insets worked. Remove it.
This commit is contained in:
@@ -86,7 +86,7 @@ class AlbumDetailFragment :
|
||||
setOnMenuItemClickListener(this@AlbumDetailFragment)
|
||||
}
|
||||
|
||||
requireBinding().detailRecycler.apply {
|
||||
binding.detailRecycler.apply {
|
||||
adapter = detailAdapter
|
||||
applySpans { pos ->
|
||||
val item = detailAdapter.data.currentList[pos]
|
||||
|
||||
@@ -81,7 +81,7 @@ class ArtistDetailFragment :
|
||||
setOnMenuItemClickListener(this@ArtistDetailFragment)
|
||||
}
|
||||
|
||||
requireBinding().detailRecycler.apply {
|
||||
binding.detailRecycler.apply {
|
||||
adapter = detailAdapter
|
||||
applySpans { pos ->
|
||||
// If the item is an ActionHeader we need to also make the item full-width
|
||||
|
||||
@@ -32,13 +32,13 @@ import com.google.android.material.appbar.AppBarLayout
|
||||
import java.lang.Exception
|
||||
import java.lang.reflect.Field
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
|
||||
import org.oxycblt.auxio.ui.AuxioAppBarLayout
|
||||
import org.oxycblt.auxio.util.lazyReflectedField
|
||||
import org.oxycblt.auxio.util.logE
|
||||
import org.oxycblt.auxio.util.logTraceOrThrow
|
||||
|
||||
/**
|
||||
* An [EdgeAppBarLayout] variant that also shows the name of the toolbar whenever the detail
|
||||
* An [AuxioAppBarLayout] variant that also shows the name of the toolbar whenever the detail
|
||||
* recyclerview is scrolled beyond it's first item (a.k.a the header). This is used instead of
|
||||
* CollapsingToolbarLayout since that thing is a mess with crippling bugs and state issues. This
|
||||
* just works.
|
||||
@@ -47,7 +47,7 @@ import org.oxycblt.auxio.util.logTraceOrThrow
|
||||
class DetailAppBarLayout
|
||||
@JvmOverloads
|
||||
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
||||
EdgeAppBarLayout(context, attrs, defStyleAttr) {
|
||||
AuxioAppBarLayout(context, attrs, defStyleAttr) {
|
||||
private var titleView: AppCompatTextView? = null
|
||||
private var recycler: RecyclerView? = null
|
||||
|
||||
|
||||
@@ -147,9 +147,7 @@ val StorageVolume.isInternalCompat: Boolean
|
||||
val StorageVolume.uuidCompat: String?
|
||||
@SuppressLint("NewApi") get() = uuid
|
||||
|
||||
/*
|
||||
* Returns the state of the volume in a compatible manner.
|
||||
*/
|
||||
/** Returns the state of the volume in a compatible manner. */
|
||||
val StorageVolume.stateCompat: String
|
||||
@SuppressLint("NewApi") get() = state
|
||||
|
||||
|
||||
+3
-11
@@ -15,20 +15,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.ui.coordinator
|
||||
package org.oxycblt.auxio.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.WindowInsets
|
||||
import androidx.annotation.AttrRes
|
||||
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.systemBarInsetsCompat
|
||||
|
||||
/**
|
||||
* An [AppBarLayout] that fixes a bug with the default implementation where the lifted state will
|
||||
@@ -37,7 +34,7 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
* **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.
|
||||
*/
|
||||
open class EdgeAppBarLayout
|
||||
open class AuxioAppBarLayout
|
||||
@JvmOverloads
|
||||
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
||||
AppBarLayout(context, attrs, defStyleAttr) {
|
||||
@@ -58,15 +55,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
}
|
||||
|
||||
init {
|
||||
fitsSystemWindows = true
|
||||
viewTreeObserver.addOnPreDrawListener(onPreDraw)
|
||||
}
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
super.onApplyWindowInsets(insets)
|
||||
updatePadding(top = insets.systemBarInsetsCompat.top)
|
||||
return insets
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
viewTreeObserver.removeOnPreDrawListener(onPreDraw)
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.coordinator
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.WindowInsets
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.children
|
||||
|
||||
/**
|
||||
* Class that manually overrides the busted window inset functionality of CoordinatorLayout in favor
|
||||
* of a simple "delegate to child views" implementation.
|
||||
*
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class EdgeCoordinatorLayout
|
||||
@JvmOverloads
|
||||
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
||||
CoordinatorLayout(context, attrs, defStyleAttr) {
|
||||
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
super.dispatchApplyWindowInsets(insets)
|
||||
|
||||
for (child in children) {
|
||||
child.dispatchApplyWindowInsets(insets)
|
||||
}
|
||||
|
||||
return insets
|
||||
}
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
super.onApplyWindowInsets(insets)
|
||||
|
||||
for (child in children) {
|
||||
child.onApplyWindowInsets(insets)
|
||||
}
|
||||
|
||||
return insets
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user