From 2c7f0743db063c9db9f7f4f88591edb26a174332 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 3 Nov 2019 13:45:30 -0800 Subject: [PATCH] Going to manga chapters now jumps to your last unread chapter Fixes to dark theme dialogs for custom download amount --- .../ui/manga/chapter/ChaptersController.kt | 29 +++++++++++-------- .../ui/manga/chapter/ChaptersPresenter.kt | 5 ++++ app/src/main/res/drawable/dialog_selector.xml | 19 ++++++++++++ .../res/layout/download_custom_amount.xml | 8 ++--- app/src/main/res/values-night/colors.xml | 2 ++ app/src/main/res/values/colors.xml | 4 ++- 6 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 app/src/main/res/drawable/dialog_selector.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 916343baae..2fb9f1d0c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -33,6 +33,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import android.content.Context import android.util.AttributeSet import androidx.core.view.ViewCompat +import androidx.recyclerview.widget.RecyclerView import kotlin.math.* class ChaptersController : NucleusController(), @@ -51,6 +52,8 @@ class ChaptersController : NucleusController(), */ private var adapter: ChaptersAdapter? = null + private var scrollToUnread = true + /** * Action mode for multiple selection. */ @@ -84,19 +87,14 @@ class ChaptersController : NucleusController(), adapter = ChaptersAdapter(this, view.context) recycler.adapter = adapter - recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context) - recycler.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(view.context, androidx.recyclerview.widget.DividerItemDecoration.VERTICAL)) + recycler.layoutManager = LinearLayoutManager(view.context) + recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL)) recycler.setHasFixedSize(true) adapter?.fastScroller = fast_scroller val fabBaseMarginBottom = fab?.marginBottom ?: 0 recycler.doOnApplyWindowInsets { v, insets, padding -> v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) - //if (snack == null) { - //fab?.translationY = -insets.systemWindowInsetBottom.toFloat() - /*} - else - fab?.translationY = 0f*/ fab?.updateLayoutParams { bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom } @@ -213,8 +211,9 @@ class ChaptersController : NucleusController(), fun onNextChapters(chapters: List) { // If the list is empty, fetch chapters from source if the conditions are met // We use presenter chapters instead because they are always unfiltered - if (presenter.chapters.isEmpty()) + if (presenter.chapters.isEmpty()) { initialFetchChapters() + } val adapter = adapter ?: return adapter.updateDataSet(chapters) @@ -230,7 +229,17 @@ class ChaptersController : NucleusController(), } actionMode?.invalidate() } + scrollToUnread() + } + private fun scrollToUnread() { + if (scrollToUnread) { + val index = presenter.getFirstUnreadIndex() + val centerOfScreen = recycler.height / 2 - 96 + (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(index, + centerOfScreen) + } + scrollToUnread = false } private fun initialFetchChapters() { @@ -520,7 +529,3 @@ class ChaptersController : NucleusController(), } } } - -class ShrinkBehavior(context: Context, attrs: AttributeSet) : - CoordinatorLayout.Behavior(context, attrs) { -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index ec18e5e56d..65419a5a74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -415,4 +415,9 @@ class ChaptersPresenter( return manga.sortDescending() } + fun getFirstUnreadIndex(): Int { + val index = chapters.sortedByDescending { it.source_order }.indexOfFirst { !it.read } + return if (sortDescending()) (chapters.size - 1) - index + else index + } } diff --git a/app/src/main/res/drawable/dialog_selector.xml b/app/src/main/res/drawable/dialog_selector.xml new file mode 100644 index 0000000000..831d0f5d38 --- /dev/null +++ b/app/src/main/res/drawable/dialog_selector.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/download_custom_amount.xml b/app/src/main/res/layout/download_custom_amount.xml index 32c6033acf..ddad2b2e19 100644 --- a/app/src/main/res/layout/download_custom_amount.xml +++ b/app/src/main/res/layout/download_custom_amount.xml @@ -10,7 +10,7 @@ android:id="@+id/btn_decrease_10" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="?selectable_list_drawable" + android:background="@drawable/dialog_selector" android:padding="8dp" android:tint="?colorAccent" app:srcCompat="@drawable/ic_chevron_left_double_black_24dp" /> @@ -19,7 +19,7 @@ android:id="@+id/btn_decrease" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="?selectable_list_drawable" + android:background="@drawable/dialog_selector" android:tint="?colorAccent" android:padding="8dp" app:srcCompat="@drawable/ic_chevron_left_black_24dp" /> @@ -38,7 +38,7 @@ android:id="@+id/btn_increase" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="?selectable_list_drawable" + android:background="@drawable/dialog_selector" android:tint="?colorAccent" android:padding="8dp" app:srcCompat="@drawable/ic_chevron_right_black_24dp" /> @@ -47,7 +47,7 @@ android:id="@+id/btn_increase_10" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="?selectable_list_drawable" + android:background="@drawable/dialog_selector" android:tint="?colorAccent" android:padding="8dp" app:srcCompat="@drawable/ic_chevron_right_double_black_24dp" /> diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 493da64e2e..57cf1782ce 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -5,4 +5,6 @@ #B3000000 #FFFFFF @color/colorDarkPrimary + @color/md_white_1000_20 + @color/md_grey_800 \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 36f7d3e52e..7d40bb55a3 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,6 +7,8 @@ @color/colorPrimary #FFFFFF #323232 + @color/md_white_1000 + @color/md_black_1000_12 #212121 #212121 @@ -37,7 +39,7 @@ @color/md_white_1000_70 @color/md_white_1000_50 @android:color/transparent - @color/md_white_1000_20- + @color/md_white_1000_20 @color/md_black_1000 @color/md_grey_900