diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt
new file mode 100644
index 0000000000..9c647e1462
--- /dev/null
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt
@@ -0,0 +1,50 @@
+package eu.kanade.tachiyomi.ui.manga.chapter
+
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.CompoundButton
+import android.widget.FrameLayout
+import android.widget.RelativeLayout
+import eu.kanade.tachiyomi.R
+import eu.kanade.tachiyomi.data.database.models.Manga
+import kotlinx.android.synthetic.main.chapter_filter_layout.view.*
+
+class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
+ FrameLayout(context, attrs) {
+
+ init {
+ RelativeLayout.inflate(context, R.layout.chapter_filter_layout, this)
+ show_all.setOnCheckedChangeListener(::checkedFilter)
+ show_read.setOnCheckedChangeListener(::checkedFilter)
+ show_unread.setOnCheckedChangeListener(::checkedFilter)
+ show_download.setOnCheckedChangeListener(::checkedFilter)
+ show_bookmark.setOnCheckedChangeListener(::checkedFilter)
+ }
+
+ private fun checkedFilter(checkBox: CompoundButton, isChecked: Boolean) {
+ if (isChecked) {
+ if (show_all == checkBox) {
+ show_read.isChecked = false
+ show_unread.isChecked = false
+ show_download.isChecked = false
+ show_bookmark.isChecked = false
+ } else {
+ show_all.isChecked = false
+ if (show_read == checkBox) show_unread.isChecked = false
+ else if (show_unread == checkBox) show_read.isChecked = false
+ }
+ } else if (!show_read.isChecked && !show_unread.isChecked && !show_download.isChecked && !show_bookmark.isChecked) {
+ show_all.isChecked = true
+ }
+ }
+
+ fun setCheckboxes(manga: Manga) {
+ show_read.isChecked = manga.readFilter == Manga.SHOW_READ
+ show_unread.isChecked = manga.readFilter == Manga.SHOW_UNREAD
+ show_download.isChecked = manga.downloadedFilter == Manga.SHOW_DOWNLOADED
+ show_bookmark.isChecked = manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED
+
+ show_all.isChecked = !(show_read.isChecked || show_unread.isChecked ||
+ show_download.isChecked || show_bookmark.isChecked)
+ }
+}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
index 05c1fb7c4c..772aed0363 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
@@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.manga.chapter
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
-import android.widget.CompoundButton
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
@@ -15,6 +14,7 @@ import eu.kanade.tachiyomi.util.view.setBottomEdge
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.util.view.visInvisIf
import eu.kanade.tachiyomi.util.view.visibleIf
+import kotlinx.android.synthetic.main.chapter_filter_layout.*
import kotlinx.android.synthetic.main.chapter_sort_bottom_sheet.*
import kotlin.math.max
@@ -86,13 +86,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
}
private fun initGeneralPreferences() {
- show_read.isChecked = presenter.onlyRead()
- show_unread.isChecked = presenter.onlyUnread()
- show_download.isChecked = presenter.onlyDownloaded()
- show_bookmark.isChecked = presenter.onlyBookmarked()
-
- show_all.isChecked = !(show_read.isChecked || show_unread.isChecked ||
- show_download.isChecked || show_bookmark.isChecked)
+ chapter_filter_layout.setCheckboxes(presenter.manga)
var defPref = presenter.globalSort()
sort_group.check(if (presenter.manga.sortDescending(defPref)) R.id.sort_newest else
@@ -124,29 +118,5 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
hide_titles.setOnCheckedChangeListener { _, isChecked ->
presenter.hideTitle(isChecked)
}
-
- show_all.setOnCheckedChangeListener(::checkedFilter)
- show_read.setOnCheckedChangeListener(::checkedFilter)
- show_unread.setOnCheckedChangeListener(::checkedFilter)
- show_download.setOnCheckedChangeListener(::checkedFilter)
- show_bookmark.setOnCheckedChangeListener(::checkedFilter)
- }
-
- private fun checkedFilter(checkBox: CompoundButton, isChecked: Boolean) {
- if (isChecked) {
- if (show_all == checkBox) {
- show_read.isChecked = false
- show_unread.isChecked = false
- show_download.isChecked = false
- show_bookmark.isChecked = false
- } else {
- show_all.isChecked = false
- if (show_read == checkBox) show_unread.isChecked = false
- else if (show_unread == checkBox) show_read.isChecked = false
- }
- } else if (!show_read.isChecked && !show_unread.isChecked &&
- !show_download.isChecked && !show_bookmark.isChecked) {
- show_all.isChecked = true
- }
}
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
index 28192cae69..da223c825a 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
@@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
+import eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterItem
import eu.kanade.tachiyomi.ui.reader.loader.ChapterLoader
import eu.kanade.tachiyomi.ui.reader.loader.DownloadPageLoader
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
@@ -229,8 +230,9 @@ class ReaderPresenter(
else -> it.source_order.toFloat()
}
}.map {
- ReaderChapterItem(it, manga, it.id ==
- getCurrentChapter()?.chapter?.id ?: chapterId)
+ ReaderChapterItem(
+ it, manga, it.id == getCurrentChapter()?.chapter?.id ?: chapterId
+ )
}
if (!manga.sortDescending(preferences.chaptersDescAsDefault().getOrDefault()))
list.reversed()
@@ -239,6 +241,21 @@ class ReaderPresenter(
return chapterItems
}
+ /**
+ * Removes all filters and requests an UI update.
+ */
+ fun setFilters(read: Boolean, unread: Boolean, downloaded: Boolean, bookmarked: Boolean) {
+ val manga = manga ?: return
+ manga.readFilter = when {
+ read -> Manga.SHOW_READ
+ unread -> Manga.SHOW_UNREAD
+ else -> Manga.SHOW_ALL
+ }
+ manga.downloadedFilter = if (downloaded) Manga.SHOW_DOWNLOADED else Manga.SHOW_ALL
+ manga.bookmarkedFilter = if (bookmarked) Manga.SHOW_BOOKMARKED else Manga.SHOW_ALL
+ db.updateFlags(manga).executeAsBlocking()
+ }
+
/**
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
* set the chapter loader, view subscriptions and trigger an initial load.
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ChapterFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ChapterFilterSheet.kt
new file mode 100644
index 0000000000..75c6eda628
--- /dev/null
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ChapterFilterSheet.kt
@@ -0,0 +1,37 @@
+package eu.kanade.tachiyomi.ui.reader.chapter
+
+import android.view.ViewGroup
+import com.google.android.material.bottomsheet.BottomSheetBehavior
+import com.google.android.material.bottomsheet.BottomSheetDialog
+import eu.kanade.tachiyomi.R
+import eu.kanade.tachiyomi.data.database.models.Manga
+import eu.kanade.tachiyomi.ui.reader.ReaderActivity
+import eu.kanade.tachiyomi.util.view.expand
+import eu.kanade.tachiyomi.util.view.setBottomEdge
+import eu.kanade.tachiyomi.util.view.setEdgeToEdge
+import kotlinx.android.synthetic.main.chapter_filter_layout.*
+import kotlinx.android.synthetic.main.chapter_filter_sheet.*
+import kotlinx.android.synthetic.main.reader_chapters_sheet.*
+
+class ChapterFilterSheet(activity: ReaderActivity, manga: Manga) :
+ BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
+
+ init {
+ val view = activity.layoutInflater.inflate(R.layout.chapter_filter_sheet, null)
+ setContentView(view)
+ BottomSheetBehavior.from(view.parent as ViewGroup).expand()
+ setEdgeToEdge(activity, view)
+ setBottomEdge(show_bookmark, activity)
+
+ chapter_filter_layout.setCheckboxes(manga)
+ setOnDismissListener {
+ activity.presenter.setFilters(
+ show_read.isChecked,
+ show_unread.isChecked,
+ show_download.isChecked,
+ show_bookmark.isChecked
+ )
+ activity.chapters_bottom_sheet.refreshList()
+ }
+ }
+}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt
similarity index 98%
rename from app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt
rename to app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt
index 5b7421b971..b8550b50ff 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt
@@ -1,4 +1,4 @@
-package eu.kanade.tachiyomi.ui.reader
+package eu.kanade.tachiyomi.ui.reader.chapter
import android.graphics.Typeface
import android.view.View
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt
similarity index 86%
rename from app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt
rename to app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt
index 316af1fd67..ec309b5356 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt
@@ -1,4 +1,4 @@
-package eu.kanade.tachiyomi.ui.reader
+package eu.kanade.tachiyomi.ui.reader.chapter
import android.content.Context
import android.content.res.ColorStateList
@@ -14,12 +14,16 @@ import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.listeners.ClickEventHook
import eu.kanade.tachiyomi.R
+import eu.kanade.tachiyomi.ui.reader.ReaderActivity
+import eu.kanade.tachiyomi.ui.reader.ReaderPresenter
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.isExpanded
+import eu.kanade.tachiyomi.util.view.visInvisIf
+import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.reader_chapters_sheet.view.*
import kotlin.math.max
import kotlin.math.min
@@ -49,6 +53,10 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
}
}
+ filter_button.setOnClickListener {
+ ChapterFilterSheet(activity, presenter.manga!!).show()
+ }
+
post {
chapter_recycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f
}
@@ -57,6 +65,10 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
override fun onSlide(bottomSheet: View, progress: Float) {
pill.alpha = (1 - max(0f, progress)) * 0.25f
val trueProgress = max(progress, 0f)
+ chapters_button.alpha = 1 - trueProgress
+ filter_button.alpha = trueProgress
+ filter_button.visibleIf(filter_button.alpha > 0)
+ chapters_button.visInvisIf(chapters_button.alpha > 0)
backgroundTintList =
ColorStateList.valueOf(lerpColor(primary, fullPrimary, trueProgress))
chapter_recycler.alpha = trueProgress
@@ -74,11 +86,17 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0,
chapter_recycler.height / 2 - 30.dpToPx
)
+ chapters_button.alpha = 1f
+ filter_button.alpha = 0f
}
if (state == BottomSheetBehavior.STATE_EXPANDED) {
chapter_recycler.alpha = 1f
+ chapters_button.alpha = 0f
+ filter_button.alpha = 1f
if (activity.sheetManageNavColor) activity.window.navigationBarColor = primary
}
+ filter_button.visibleIf(state != BottomSheetBehavior.STATE_COLLAPSED)
+ chapters_button.visInvisIf(state != BottomSheetBehavior.STATE_EXPANDED)
}
})
diff --git a/app/src/main/res/layout/chapter_filter_layout.xml b/app/src/main/res/layout/chapter_filter_layout.xml
new file mode 100644
index 0000000000..e20c8b69c8
--- /dev/null
+++ b/app/src/main/res/layout/chapter_filter_layout.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/chapter_filter_sheet.xml b/app/src/main/res/layout/chapter_filter_sheet.xml
new file mode 100644
index 0000000000..89e5bb0eaa
--- /dev/null
+++ b/app/src/main/res/layout/chapter_filter_sheet.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/chapter_sort_bottom_sheet.xml b/app/src/main/res/layout/chapter_sort_bottom_sheet.xml
index aa945667d0..fb2c1ee337 100644
--- a/app/src/main/res/layout/chapter_sort_bottom_sheet.xml
+++ b/app/src/main/res/layout/chapter_sort_bottom_sheet.xml
@@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/display_bottom_sheet"
android:layout_width="match_parent"
- android:background="@drawable/bottom_sheet_rounded_background"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:background="@drawable/bottom_sheet_rounded_background">
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_height="wrap_content" />
+ android:tint="?android:attr/textColorPrimary" />
-
@@ -31,47 +31,55 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+ app:layout_constraintTop_toTopOf="parent"
+ tools:text="100 / 105" />
-
\ No newline at end of file
+
\ No newline at end of file