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:
OxygenCobalt 2022-08-04 14:30:33 -06:00
parent 4af45031b0
commit f27b798e33
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
13 changed files with 52 additions and 124 deletions

View file

@ -14,9 +14,9 @@ android {
versionName "2.5.0" versionName "2.5.0"
versionCode 19 versionCode 19
minSdk 21
// API 33 is still busted, waiting until the XML element issue is fixed // API 33 is still busted, waiting until the XML element issue is fixed
// noinspection OldTargetApi // noinspection OldTargetApi
minSdk 21
targetSdk 32 targetSdk 32
buildFeatures { buildFeatures {

View file

@ -86,7 +86,7 @@ class AlbumDetailFragment :
setOnMenuItemClickListener(this@AlbumDetailFragment) setOnMenuItemClickListener(this@AlbumDetailFragment)
} }
requireBinding().detailRecycler.apply { binding.detailRecycler.apply {
adapter = detailAdapter adapter = detailAdapter
applySpans { pos -> applySpans { pos ->
val item = detailAdapter.data.currentList[pos] val item = detailAdapter.data.currentList[pos]

View file

@ -81,7 +81,7 @@ class ArtistDetailFragment :
setOnMenuItemClickListener(this@ArtistDetailFragment) setOnMenuItemClickListener(this@ArtistDetailFragment)
} }
requireBinding().detailRecycler.apply { binding.detailRecycler.apply {
adapter = detailAdapter adapter = detailAdapter
applySpans { pos -> applySpans { pos ->
// If the item is an ActionHeader we need to also make the item full-width // If the item is an ActionHeader we need to also make the item full-width

View file

@ -32,13 +32,13 @@ import com.google.android.material.appbar.AppBarLayout
import java.lang.Exception import java.lang.Exception
import java.lang.reflect.Field import java.lang.reflect.Field
import org.oxycblt.auxio.R 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.lazyReflectedField
import org.oxycblt.auxio.util.logE import org.oxycblt.auxio.util.logE
import org.oxycblt.auxio.util.logTraceOrThrow 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 * 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 * CollapsingToolbarLayout since that thing is a mess with crippling bugs and state issues. This
* just works. * just works.
@ -47,7 +47,7 @@ import org.oxycblt.auxio.util.logTraceOrThrow
class DetailAppBarLayout class DetailAppBarLayout
@JvmOverloads @JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) : 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 titleView: AppCompatTextView? = null
private var recycler: RecyclerView? = null private var recycler: RecyclerView? = null

View file

@ -147,9 +147,7 @@ val StorageVolume.isInternalCompat: Boolean
val StorageVolume.uuidCompat: String? val StorageVolume.uuidCompat: String?
@SuppressLint("NewApi") get() = uuid @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 val StorageVolume.stateCompat: String
@SuppressLint("NewApi") get() = state @SuppressLint("NewApi") get() = state

View file

@ -15,20 +15,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.view.WindowInsets
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.updatePadding
import com.google.android.material.appbar.AppBarLayout 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 * 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 * **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. * scrolling view to use. Failure to specify this will result in the layout not working.
*/ */
open class EdgeAppBarLayout open class AuxioAppBarLayout
@JvmOverloads @JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) : constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
AppBarLayout(context, attrs, defStyleAttr) { AppBarLayout(context, attrs, defStyleAttr) {
@ -58,15 +55,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
init { init {
fitsSystemWindows = true
viewTreeObserver.addOnPreDrawListener(onPreDraw) viewTreeObserver.addOnPreDrawListener(onPreDraw)
} }
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
super.onApplyWindowInsets(insets)
updatePadding(top = insets.systemBarInsetsCompat.top)
return insets
}
override fun onDetachedFromWindow() { override fun onDetachedFromWindow() {
super.onDetachedFromWindow() super.onDetachedFromWindow()
viewTreeObserver.removeOnPreDrawListener(onPreDraw) viewTreeObserver.removeOnPreDrawListener(onPreDraw)

View file

@ -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
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -8,7 +8,7 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".settings.AboutFragment"> tools:context=".settings.AboutFragment">
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout <org.oxycblt.auxio.ui.AuxioAppBarLayout
android:id="@+id/about_appbar" android:id="@+id/about_appbar"
style="@style/Widget.Auxio.AppBarLayout" style="@style/Widget.Auxio.AppBarLayout"
app:liftOnScroll="true"> app:liftOnScroll="true">
@ -20,7 +20,7 @@
app:navigationIcon="@drawable/ic_back_24" app:navigationIcon="@drawable/ic_back_24"
app:title="@string/lbl_about" /> app:title="@string/lbl_about" />
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout> </org.oxycblt.auxio.ui.AuxioAppBarLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/about_contents" android:id="@+id/about_contents"
@ -248,4 +248,4 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,15 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface"> 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 <org.oxycblt.auxio.detail.DetailAppBarLayout
android:id="@+id/detail_appbar" android:id="@+id/detail_appbar"
style="@style/Widget.Auxio.AppBarLayout" style="@style/Widget.Auxio.AppBarLayout"
@ -32,5 +28,4 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="@layout/item_detail" /> tools:listitem="@layout/item_detail" />
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/home_layout" android:id="@+id/home_layout"
@ -7,10 +7,10 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface"> android:background="?attr/colorSurface">
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout <org.oxycblt.auxio.ui.AuxioAppBarLayout
android:id="@+id/home_appbar" android:id="@+id/home_appbar"
style="@style/Widget.Auxio.AppBarLayout" style="@style/Widget.Auxio.AppBarLayout"
app:liftOnScroll="true"> android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/home_toolbar" android:id="@+id/home_toolbar"
@ -29,7 +29,7 @@
app:tabGravity="start" app:tabGravity="start"
app:tabMode="scrollable" /> app:tabMode="scrollable" />
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout> </org.oxycblt.auxio.ui.AuxioAppBarLayout>
<FrameLayout <FrameLayout
@ -127,4 +127,4 @@
</org.oxycblt.auxio.home.EdgeFrameLayout> </org.oxycblt.auxio.home.EdgeFrameLayout>
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout" android:id="@+id/main_layout"
@ -16,7 +16,7 @@
app:navGraph="@navigation/nav_explore" app:navGraph="@navigation/nav_explore"
tools:layout="@layout/fragment_home" /> tools:layout="@layout/fragment_home" />
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/playback_sheet" android:id="@+id/playback_sheet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -80,6 +80,6 @@
</LinearLayout> </LinearLayout>
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface"> android:background="?attr/colorSurface">
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout <org.oxycblt.auxio.ui.AuxioAppBarLayout
style="@style/Widget.Auxio.AppBarLayout" style="@style/Widget.Auxio.AppBarLayout"
app:liftOnScroll="true" app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/search_recycler"> app:liftOnScrollTargetViewId="@id/search_recycler">
@ -43,7 +43,7 @@
</com.google.android.material.appbar.MaterialToolbar> </com.google.android.material.appbar.MaterialToolbar>
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout> </org.oxycblt.auxio.ui.AuxioAppBarLayout>
<org.oxycblt.auxio.ui.recycler.EdgeRecyclerView <org.oxycblt.auxio.ui.recycler.EdgeRecyclerView
android:id="@+id/search_recycler" android:id="@+id/search_recycler"
@ -53,4 +53,4 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="@layout/item_song" /> tools:listitem="@layout/item_song" />
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:orientation="vertical"> android:orientation="vertical">
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout <org.oxycblt.auxio.ui.AuxioAppBarLayout
android:id="@+id/settings_appbar" android:id="@+id/settings_appbar"
style="@style/Widget.Auxio.AppBarLayout" style="@style/Widget.Auxio.AppBarLayout"
android:clickable="true" android:clickable="true"
@ -21,7 +20,7 @@
app:navigationIcon="@drawable/ic_back_24" app:navigationIcon="@drawable/ic_back_24"
app:title="@string/set_title" /> app:title="@string/set_title" />
</org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout> </org.oxycblt.auxio.ui.AuxioAppBarLayout>
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/settings_list_fragment" android:id="@+id/settings_list_fragment"
@ -30,4 +29,4 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>