mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-01 06:47:56 +01:00
MainActivity fixes (#6591)
* Reduce notifyDataSetChanged calls when category count is disabled * Fix category tabs briefly showing when it's supposed to be disabled Also fix tabs showing when activity recreated * Lift appbar when tab is hidden Check against tab visibility instead of viewpager * Restore selected nav item after recreate * Simplify SHORTCUT_MANGA intent handling Don't need to change controller if the topmost controller is the target
This commit is contained in:
@@ -5,23 +5,15 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.coordinatorlayout.R
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.doOnLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.customview.view.AbsSavedState
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.bluelinelabs.conductor.ChangeHandlerFrameLayout
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import eu.kanade.tachiyomi.util.system.isTablet
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
import eu.kanade.tachiyomi.util.view.findDescendant
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.HierarchyChangeEvent
|
||||
import reactivecircus.flowbinding.android.view.hierarchyChangeEvents
|
||||
|
||||
/**
|
||||
* [CoordinatorLayout] with its own app bar lift state handler.
|
||||
@@ -33,8 +25,6 @@ import reactivecircus.flowbinding.android.view.hierarchyChangeEvents
|
||||
* With those conditions, this view expects the following direct child:
|
||||
*
|
||||
* 1. An [AppBarLayout].
|
||||
*
|
||||
* 2. A [ChangeHandlerFrameLayout] that contains an optional [ViewPager].
|
||||
*/
|
||||
class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
@@ -48,7 +38,7 @@ class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||
private val isTablet = context.isTablet()
|
||||
|
||||
private var appBarLayout: AppBarLayout? = null
|
||||
private var viewPager: ViewPager? = null
|
||||
private var tabLayout: TabLayout? = null
|
||||
|
||||
/**
|
||||
* If true, [AppBarLayout] child will be lifted on nested scroll.
|
||||
@@ -72,32 +62,21 @@ class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||
) {
|
||||
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
||||
// Disable elevation overlay when tabs are visible
|
||||
if (canLiftAppBarOnScroll && viewPager == null) {
|
||||
appBarLayout?.isLifted = dyConsumed != 0 || dyUnconsumed >= 0
|
||||
if (canLiftAppBarOnScroll) {
|
||||
appBarLayout?.isLifted = (dyConsumed != 0 || dyUnconsumed >= 0) && tabLayout?.isVisible == false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
appBarLayout = findChild()
|
||||
viewPager = findChild<ChangeHandlerFrameLayout>()?.findDescendant()
|
||||
|
||||
// Updates ViewPager reference when controller is changed
|
||||
findViewTreeLifecycleOwner()?.lifecycle?.coroutineScope?.let { scope ->
|
||||
findChild<ChangeHandlerFrameLayout>()?.hierarchyChangeEvents()
|
||||
?.onEach {
|
||||
if (it is HierarchyChangeEvent.ChildRemoved) {
|
||||
viewPager = (it.parent as? ViewGroup)?.findDescendant()
|
||||
}
|
||||
}
|
||||
?.launchIn(scope)
|
||||
}
|
||||
tabLayout = appBarLayout?.findChild()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
appBarLayout = null
|
||||
viewPager = null
|
||||
tabLayout = null
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(): Parcelable? {
|
||||
|
||||
Reference in New Issue
Block a user