More List scrolling work

less bugs + end of categories animation
Always showing start reading button, it's just disabled when there's nothing to read
This commit is contained in:
Jay 2020-03-10 21:02:19 -07:00
parent 8379caa149
commit 1f91ad0a07
8 changed files with 48 additions and 20 deletions

View File

@ -53,6 +53,7 @@ import java.util.Locale
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sign
@ -152,10 +153,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
bottom_sheet.getGlobalVisibleRect(sheetRect)
view?.getGlobalVisibleRect(recyclerRect)
if (sheetRect.contains(event.x.toInt(), event.y.toInt()) ||
!recyclerRect.contains(event.x.toInt(), event.y.toInt())) {
return
}
if (startPosX == null) {
startPosX = event.rawX
startPosY = event.rawY
@ -185,8 +183,14 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
prevCategory = newOffsetP
}
}
return
}
else if (event.actionMasked != MotionEvent.ACTION_UP && startPosX != null) {
if (startPosX != null && startPosY != null &&
(sheetRect.contains(startPosX!!.toInt(), startPosY!!.toInt()) ||
!recyclerRect.contains(startPosX!!.toInt(), startPosY!!.toInt()))) {
return
}
if (event.actionMasked != MotionEvent.ACTION_UP && startPosX != null) {
val distance = abs(event.rawX - startPosX!!)
val sign = sign(event.rawX - startPosX!!)
@ -196,26 +200,21 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
!lockedRecycler) {
lockedRecycler = true
switchingCategories = true
if ((prevCategory == null && sign > 0) || (nextCategory == null && sign < 0)) {
recycler_layout.x = 0f
recycler_layout.alpha = 1f
return
}
else
recycler.suppressLayout(true)
recycler.suppressLayout(true)
}
else if (!lockedRecycler && abs(event.rawY - startPosY!!) > 30) {
lockedY = true
resetRecyclerY()
return
}
if ((prevCategory == null && sign > 0) || (nextCategory == null && sign < 0)) {
resetRecyclerY()
return
}
if (abs(event.rawY - startPosY!!) <= 30 || recycler.isLayoutSuppressed
|| lockedRecycler) {
if (distance <= swipeDistance * 1.1f) {
if ((prevCategory == null && sign > 0) || (nextCategory == null && sign < 0)) {
recycler_layout.x = sign * distance.pow(0.6f)
recycler_layout.alpha = 1f
}
else if (distance <= swipeDistance * 1.1f) {
recycler_layout.x = (max(0f, distance - 50f) * sign) / 3
recycler_layout.alpha =
(1f - (distance - (swipeDistance * 0.1f)) / swipeDistance)
@ -454,6 +453,14 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
headerPosition, (if (headerPosition == 0) 0 else (-28).dpToPx)
+ appbarOffset
)
val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
this
val headerItem = adapter.getItem(headerPosition) as? LibraryHeaderItem
if (headerItem != null) {
customTitleSpinner.category_title.text = headerItem.category.name
if (isCurrentController) setTitle()
}
recycler.suppressLayout(false)
}
launchUI {
@ -790,6 +797,8 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
if (lockedRecycler && abs(x) > 1000f) {
val sign = sign(x).roundToInt()
if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null)
return
val distance = recycler_layout.alpha
val speed = max(3000f / abs(x), 0.75f)
Timber.d("Flinged $distance, velo ${abs(x)}, speed $speed")

View File

@ -47,6 +47,8 @@ class SearchActivity: MainActivity() {
toolbar.navigationIcon = drawerArrow
drawerArrow?.progress = 1f
if (to !is SpinnerTitleInterface) toolbar.removeSpinner()
if (to is NoToolbarElevationController) {
appbar.disableElevation()
} else {

View File

@ -98,6 +98,7 @@ class MangaDetailsPresenter(private val controller: MangaDetailsController,
fun fetchChapters() {
launch {
getChapters()
refreshTracking()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}
}

View File

@ -156,7 +156,8 @@ class MangaHeaderHolder(
with(start_reading_button) {
val nextChapter = presenter.getNextUnreadChapter()
visibleIf(nextChapter != null && !item.isLocked)
visibleIf(presenter.chapters.isNotEmpty() && !item.isLocked)
isEnabled = (nextChapter != null)
if (nextChapter != null) {
val number = adapter.decimalFormat.format(nextChapter.chapter_number.toDouble())
text = if (nextChapter.chapter_number > 0) resources.getString(
@ -171,6 +172,9 @@ class MangaHeaderHolder(
)
}
}
else {
text = resources.getString(R.string.all_caught_up)
}
}
val count = presenter.chapters.size

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:alpha="0.12" android:color="?attr/colorOnSurface" />
<item android:color="?colorAccent" />
</selector>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_enabled="true"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>

View File

@ -514,6 +514,7 @@
<string name="no_description">No description</string>
<string name="mark_all_as_read_message">Mark all chapters as read?</string>
<string name="remove_from_library">Remove from library</string>
<string name="all_caught_up">All caught up</string>
<!-- Manga chapters fragment -->
<string name="start_reading">Start reading</string>

View File

@ -247,8 +247,8 @@
<style name="Theme.Widget.Button.Primary" parent="Widget.MaterialComponents.Button">
<item name="android:textAllCaps">false</item>
<item name="backgroundTint">?colorAccent</item>
<item name="android:textColor">@android:color/white</item>
<item name="backgroundTint">@color/mtrl_btn_bg_selector</item>
<item name="android:textColor">@color/primary_button_text_color_selector</item>
<item name="android:letterSpacing">0.0</item>
</style>