Change chapter filters in reader

And some refactoring
This commit is contained in:
Jay 2020-05-21 15:01:25 -04:00
parent bd748f6a62
commit 45161220b8
10 changed files with 258 additions and 131 deletions

View File

@ -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)
}
}

View File

@ -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
}
}
}

View File

@ -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.

View File

@ -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()
}
}
}

View File

@ -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

View File

@ -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)
}
})

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="16dp"
android:paddingEnd="12dp"
android:text="@string/filter" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_all" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_read"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_read_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_unread"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_unread_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_downloaded_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_bookmark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_bookmarked_chapters" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_sheet_rounded_background">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.kanade.tachiyomi.ui.manga.chapter.ChapterFilterLayout
android:id="@+id/chapter_filter_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</FrameLayout>

View File

@ -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">
<androidx.core.widget.NestedScrollView
android:id="@+id/settings_scroll_view"
@ -23,8 +23,8 @@
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
@ -66,54 +66,10 @@
android:text="@string/oldest_first" />
</RadioGroup>
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
<eu.kanade.tachiyomi.ui.manga.chapter.ChapterFilterLayout
android:id="@+id/chapter_filter_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="16dp"
android:paddingEnd="12dp"
android:text="@string/filter" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_all" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_read"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_read_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_unread"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_unread_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_downloaded_chapters" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/show_bookmark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/show_bookmarked_chapters" />
android:layout_height="wrap_content" />
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
@ -160,12 +116,12 @@
android:id="@+id/pill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginTop="5dp"
android:alpha="0.25"
android:contentDescription="@string/drag_handle"
android:src="@drawable/draggable_pill"
android:tint="?android:attr/textColorPrimary"
android:layout_gravity="center|top"/>
android:tint="?android:attr/textColorPrimary" />
<ImageView
android:id="@+id/close_button"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.kanade.tachiyomi.ui.reader.ReaderChapterSheet xmlns:android="http://schemas.android.com/apk/res/android"
<eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chapters_bottom_sheet"
@ -14,7 +14,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/topbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="?attr/actionBarSize"
android:clickable="true"
android:focusable="true">
@ -31,17 +31,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/seekbar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/chapters_button"
android:layout_width="wrap_content"
@ -51,17 +40,34 @@
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?actionBarTintColor"
android:tooltipText="@string/view_chapters"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_format_list_numbered_24dp" />
<!--
Wonky way of setting height due to issues with horizontally centering the thumb in Android 5.
See https://stackoverflow.com/questions/15701767/android-thumb-is-not-centered-in-seekbar
-->
<ImageButton
android:id="@+id/filter_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/next"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
android:tint="?actionBarTintColor"
android:tooltipText="@string/filter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:alpha="0.0"
app:srcCompat="@drawable/ic_filter_list_24dp" />
<eu.kanade.tachiyomi.ui.reader.ReaderSeekBar
android:id="@+id/page_seekbar"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/page_text"
app:layout_constraintStart_toEndOf="@id/chapters_button"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/page_text"
@ -70,8 +76,10 @@
android:gravity="center"
android:textColor="?actionBarTintColor"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="100 / 105" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
@ -82,4 +90,4 @@
android:background="@android:color/transparent"
android:clipToPadding="false"
tools:listitem="@layout/reader_chapter_item" />
</eu.kanade.tachiyomi.ui.reader.ReaderChapterSheet>
</eu.kanade.tachiyomi.ui.reader.chapter.ReaderChapterSheet>