Fixed #326
This commit is contained in:
parent
4bc44b22f6
commit
113107e05c
@ -1,12 +1,15 @@
|
|||||||
package eu.kanade.tachiyomi.util.view
|
package eu.kanade.tachiyomi.util.view
|
||||||
|
|
||||||
import android.R
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.math.MathUtils
|
import androidx.core.math.MathUtils
|
||||||
@ -17,9 +20,11 @@ import com.bluelinelabs.conductor.ControllerChangeHandler
|
|||||||
import com.bluelinelabs.conductor.ControllerChangeType
|
import com.bluelinelabs.conductor.ControllerChangeType
|
||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.main.BottomSheetController
|
import eu.kanade.tachiyomi.ui.main.BottomSheetController
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import kotlinx.android.synthetic.main.main_activity.*
|
import kotlinx.android.synthetic.main.main_activity.*
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
@ -52,6 +57,7 @@ fun Controller.setOnQueryTextChangeListener(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
fun Controller.scrollViewWith(
|
fun Controller.scrollViewWith(
|
||||||
recycler: RecyclerView,
|
recycler: RecyclerView,
|
||||||
padBottom: Boolean = false,
|
padBottom: Boolean = false,
|
||||||
@ -77,7 +83,7 @@ fun Controller.scrollViewWith(
|
|||||||
val randomTag = Random.nextLong()
|
val randomTag = Random.nextLong()
|
||||||
var headerHeight = 0
|
var headerHeight = 0
|
||||||
var lastY = 0f
|
var lastY = 0f
|
||||||
|
var fakeToolbarView: View? = null
|
||||||
recycler.doOnApplyWindowInsets { view, insets, _ ->
|
recycler.doOnApplyWindowInsets { view, insets, _ ->
|
||||||
headerHeight = insets.systemWindowInsetTop + appBarHeight
|
headerHeight = insets.systemWindowInsetTop + appBarHeight
|
||||||
if (!customPadding) view.updatePaddingRelative(
|
if (!customPadding) view.updatePaddingRelative(
|
||||||
@ -116,15 +122,10 @@ fun Controller.scrollViewWith(
|
|||||||
super.onChangeStart(controller, changeHandler, changeType)
|
super.onChangeStart(controller, changeHandler, changeType)
|
||||||
if (changeType.isEnter) {
|
if (changeType.isEnter) {
|
||||||
elevateFunc(elevate)
|
elevateFunc(elevate)
|
||||||
if (!customPadding && changeType == ControllerChangeType.POP_ENTER &&
|
if (fakeToolbarView?.parent != null) {
|
||||||
recycler.marginTop > 0) {
|
val parent = recycler.parent as ViewGroup
|
||||||
recycler.updatePaddingRelative(
|
parent.removeView(fakeToolbarView)
|
||||||
top = headerHeight
|
fakeToolbarView = null
|
||||||
)
|
|
||||||
recycler.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
||||||
topMargin = 0
|
|
||||||
}
|
|
||||||
recycler.scrollBy(0, -headerHeight)
|
|
||||||
}
|
}
|
||||||
lastY = 0f
|
lastY = 0f
|
||||||
activity!!.toolbar.tag = randomTag
|
activity!!.toolbar.tag = randomTag
|
||||||
@ -136,20 +137,21 @@ fun Controller.scrollViewWith(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!customPadding && lastY == 0f &&
|
if (!customPadding && lastY == 0f && router.backstack.lastOrNull()
|
||||||
router.backstack.lastOrNull()?.controller() is MangaDetailsController
|
?.controller() is MangaDetailsController
|
||||||
) {
|
) {
|
||||||
recycler.updatePaddingRelative(
|
val v = View(activity)
|
||||||
top = 0
|
fakeToolbarView = v
|
||||||
)
|
val parent = recycler.parent as ViewGroup
|
||||||
recycler.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
parent.addView(v, parent.indexOfChild(recycler) + 1)
|
||||||
topMargin = headerHeight
|
val params = fakeToolbarView?.layoutParams
|
||||||
}
|
params?.height = recycler.paddingTop
|
||||||
recycler.scrollBy(0, headerHeight)
|
params?.width = MATCH_PARENT
|
||||||
|
v.setBackgroundColor(v.context.getResourceColor(R.attr.colorSecondary))
|
||||||
|
v.layoutParams = params
|
||||||
}
|
}
|
||||||
elevationAnim?.cancel()
|
elevationAnim?.cancel()
|
||||||
if (activity!!.toolbar.tag == randomTag)
|
if (activity!!.toolbar.tag == randomTag) activity!!.toolbar.setOnClickListener(null)
|
||||||
activity!!.toolbar.setOnClickListener(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -164,7 +166,7 @@ fun Controller.scrollViewWith(
|
|||||||
) {
|
) {
|
||||||
if (!recycler.canScrollVertically(-1)) {
|
if (!recycler.canScrollVertically(-1)) {
|
||||||
val shortAnimationDuration = resources?.getInteger(
|
val shortAnimationDuration = resources?.getInteger(
|
||||||
R.integer.config_shortAnimTime
|
android.R.integer.config_shortAnimTime
|
||||||
) ?: 0
|
) ?: 0
|
||||||
activity!!.appbar.animate().y(0f).setDuration(shortAnimationDuration.toLong())
|
activity!!.appbar.animate().y(0f).setDuration(shortAnimationDuration.toLong())
|
||||||
.start()
|
.start()
|
||||||
@ -193,7 +195,7 @@ fun Controller.scrollViewWith(
|
|||||||
) {
|
) {
|
||||||
val halfWay = abs((-activity!!.appbar.height.toFloat()) / 2)
|
val halfWay = abs((-activity!!.appbar.height.toFloat()) / 2)
|
||||||
val shortAnimationDuration = resources?.getInteger(
|
val shortAnimationDuration = resources?.getInteger(
|
||||||
R.integer.config_shortAnimTime
|
android.R.integer.config_shortAnimTime
|
||||||
) ?: 0
|
) ?: 0
|
||||||
val closerToTop = abs(activity!!.appbar.y) - halfWay > 0
|
val closerToTop = abs(activity!!.appbar.y) - halfWay > 0
|
||||||
val atTop = !recycler.canScrollVertically(-1)
|
val atTop = !recycler.canScrollVertically(-1)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
android:id="@+id/source_layout"
|
android:id="@+id/source_layout"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -22,7 +22,7 @@
|
|||||||
android:layout_gravity="center_vertical|center_horizontal"
|
android:layout_gravity="center_vertical|center_horizontal"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user