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:
parent
4af45031b0
commit
f27b798e33
13 changed files with 52 additions and 124 deletions
|
@ -14,9 +14,9 @@ android {
|
|||
versionName "2.5.0"
|
||||
versionCode 19
|
||||
|
||||
minSdk 21
|
||||
// API 33 is still busted, waiting until the XML element issue is fixed
|
||||
// noinspection OldTargetApi
|
||||
minSdk 21
|
||||
targetSdk 32
|
||||
|
||||
buildFeatures {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -8,7 +8,7 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".settings.AboutFragment">
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
|
||||
<org.oxycblt.auxio.ui.AuxioAppBarLayout
|
||||
android:id="@+id/about_appbar"
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
app:liftOnScroll="true">
|
||||
|
@ -20,7 +20,7 @@
|
|||
app:navigationIcon="@drawable/ic_back_24"
|
||||
app:title="@string/lbl_about" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout>
|
||||
</org.oxycblt.auxio.ui.AuxioAppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/about_contents"
|
||||
|
@ -248,4 +248,4 @@
|
|||
</com.google.android.material.card.MaterialCardView>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -1,36 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurface">
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<org.oxycblt.auxio.detail.DetailAppBarLayout
|
||||
android:id="@+id/detail_appbar"
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
app:liftOnScroll="true"
|
||||
app:liftOnScrollTargetViewId="@id/detail_recycler">
|
||||
|
||||
<org.oxycblt.auxio.detail.DetailAppBarLayout
|
||||
android:id="@+id/detail_appbar"
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
app:liftOnScroll="true"
|
||||
app:liftOnScrollTargetViewId="@id/detail_recycler">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/detail_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:navigationIcon="@drawable/ic_back_24" />
|
||||
|
||||
</org.oxycblt.auxio.detail.DetailAppBarLayout>
|
||||
|
||||
<org.oxycblt.auxio.ui.recycler.EdgeRecyclerView
|
||||
android:id="@+id/detail_recycler"
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/detail_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||
tools:listitem="@layout/item_detail" />
|
||||
android:layout_height="wrap_content"
|
||||
app:navigationIcon="@drawable/ic_back_24" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</FrameLayout>
|
||||
</org.oxycblt.auxio.detail.DetailAppBarLayout>
|
||||
|
||||
<org.oxycblt.auxio.ui.recycler.EdgeRecyclerView
|
||||
android:id="@+id/detail_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||
tools:listitem="@layout/item_detail" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/home_layout"
|
||||
|
@ -7,10 +7,10 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurface">
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
|
||||
<org.oxycblt.auxio.ui.AuxioAppBarLayout
|
||||
android:id="@+id/home_appbar"
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
app:liftOnScroll="true">
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/home_toolbar"
|
||||
|
@ -29,7 +29,7 @@
|
|||
app:tabGravity="start"
|
||||
app:tabMode="scrollable" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout>
|
||||
</org.oxycblt.auxio.ui.AuxioAppBarLayout>
|
||||
|
||||
|
||||
<FrameLayout
|
||||
|
@ -127,4 +127,4 @@
|
|||
|
||||
</org.oxycblt.auxio.home.EdgeFrameLayout>
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_layout"
|
||||
|
@ -16,7 +16,7 @@
|
|||
app:navGraph="@navigation/nav_explore"
|
||||
tools:layout="@layout/fragment_home" />
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/playback_sheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -80,6 +80,6 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurface">
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
|
||||
<org.oxycblt.auxio.ui.AuxioAppBarLayout
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
app:liftOnScroll="true"
|
||||
app:liftOnScrollTargetViewId="@id/search_recycler">
|
||||
|
@ -43,7 +43,7 @@
|
|||
|
||||
</com.google.android.material.appbar.MaterialToolbar>
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout>
|
||||
</org.oxycblt.auxio.ui.AuxioAppBarLayout>
|
||||
|
||||
<org.oxycblt.auxio.ui.recycler.EdgeRecyclerView
|
||||
android:id="@+id/search_recycler"
|
||||
|
@ -53,4 +53,4 @@
|
|||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||
tools:listitem="@layout/item_song" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurface"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
|
||||
<org.oxycblt.auxio.ui.AuxioAppBarLayout
|
||||
android:id="@+id/settings_appbar"
|
||||
style="@style/Widget.Auxio.AppBarLayout"
|
||||
android:clickable="true"
|
||||
|
@ -21,7 +20,7 @@
|
|||
app:navigationIcon="@drawable/ic_back_24"
|
||||
app:title="@string/set_title" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout>
|
||||
</org.oxycblt.auxio.ui.AuxioAppBarLayout>
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/settings_list_fragment"
|
||||
|
@ -30,4 +29,4 @@
|
|||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
|
||||
|
||||
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Reference in a new issue