Added read filter to chapter select. (#431)

* Added read filter to chapter select.
* Can now select how far back the chapter should be deleted after read.
This commit is contained in:
Bram van de Kerkhof 2016-09-05 11:08:16 +02:00 committed by GitHub
parent 8ffff44454
commit d8d93ee344
11 changed files with 118 additions and 61 deletions

View File

@ -66,9 +66,7 @@ class PreferenceKeys(context: Context) {
val downloadOnlyOverWifi = context.getString(R.string.pref_download_only_over_wifi_key)
val removeAfterRead = context.getString(R.string.pref_remove_after_read_key)
val removeAfterReadPrevious = context.getString(R.string.pref_remove_after_read_previous_key)
val removeAfterReadSlots = context.getString(R.string.pref_remove_after_read_slots_key)
val removeAfterMarkedAsRead = context.getString(R.string.pref_remove_after_marked_as_read_key)

View File

@ -116,9 +116,7 @@ class PreferencesHelper(context: Context) {
fun downloadOnlyOverWifi() = prefs.getBoolean(keys.downloadOnlyOverWifi, true)
fun removeAfterRead() = prefs.getBoolean(keys.removeAfterRead, false)
fun removeAfterReadPrevious() = prefs.getBoolean(keys.removeAfterReadPrevious, false)
fun removeAfterReadSlots() = prefs.getInt(keys.removeAfterReadSlots, -1)
fun removeAfterMarkedAsRead() = prefs.getBoolean(keys.removeAfterMarkedAsRead, false)

View File

@ -116,8 +116,25 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.chapters, menu)
menu.findItem(R.id.action_filter_unread).isChecked = presenter.onlyUnread()
menu.findItem(R.id.action_filter_downloaded).isChecked = presenter.onlyDownloaded()
}
override fun onPrepareOptionsMenu(menu: Menu) {
// Initialize menu items.
val menuFilterRead = menu.findItem(R.id.action_filter_read)
val menuFilterUnread = menu.findItem(R.id.action_filter_unread)
val menuFilterDownloaded = menu.findItem(R.id.action_filter_downloaded)
// Set correct checkbox values.
menuFilterRead.isChecked = presenter.onlyRead()
menuFilterUnread.isChecked = presenter.onlyUnread()
menuFilterDownloaded.isChecked = presenter.onlyDownloaded()
if (presenter.onlyRead())
//Disable unread filter option if read filter is enabled.
menuFilterUnread.isEnabled = false
if (presenter.onlyUnread())
//Disable read filter option if unread filter is enabled.
menuFilterRead.isEnabled = false
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -126,8 +143,14 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
R.id.manga_download -> showDownloadDialog()
R.id.action_sorting_mode -> showSortingDialog()
R.id.action_filter_unread -> {
item.isChecked = !item.isChecked
presenter.setUnreadFilter(item.isChecked)
activity.supportInvalidateOptionsMenu()
}
R.id.action_filter_read -> {
item.isChecked = !item.isChecked
presenter.setReadFilter(item.isChecked)
activity.supportInvalidateOptionsMenu()
}
R.id.action_filter_downloaded -> {
item.isChecked = !item.isChecked
@ -145,8 +168,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
fun onNextManga(manga: Manga) {
// Set initial values
setReadFilter()
setDownloadedFilter()
activity.supportInvalidateOptionsMenu()
}
fun onNextChapters(chapters: List<ChapterModel>) {
@ -394,12 +416,4 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
private fun setContextTitle(count: Int) {
actionMode?.title = getString(R.string.label_selected, count)
}
fun setReadFilter() {
activity.supportInvalidateOptionsMenu()
}
fun setDownloadedFilter() {
activity.supportInvalidateOptionsMenu()
}
}

View File

@ -209,6 +209,9 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
if (onlyUnread()) {
observable = observable.filter { !it.read }
}
if (onlyRead()) {
observable = observable.filter { it.read }
}
if (onlyDownloaded()) {
observable = observable.filter { it.isDownloaded }
}
@ -349,12 +352,23 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
*
* @param onlyUnread whether to display only unread chapters or all chapters.
*/
fun setReadFilter(onlyUnread: Boolean) {
fun setUnreadFilter(onlyUnread: Boolean) {
manga.readFilter = if (onlyUnread) Manga.SHOW_UNREAD else Manga.SHOW_ALL
db.updateFlags(manga).executeAsBlocking()
refreshChapters()
}
/**
* Sets the read filter and requests an UI update.
*
* @param onlyRead whether to display only read chapters or all chapters.
*/
fun setReadFilter(onlyRead: Boolean) {
manga.readFilter = if (onlyRead) Manga.SHOW_READ else Manga.SHOW_ALL
db.updateFlags(manga).executeAsBlocking()
refreshChapters()
}
/**
* Sets the download filter and requests an UI update.
*
@ -411,6 +425,13 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
return manga.readFilter == Manga.SHOW_UNREAD
}
/**
* Whether the display only read filter is enabled.
*/
fun onlyRead(): Boolean {
return manga.readFilter == Manga.SHOW_READ
}
/**
* Whether the sorting method is descending or ascending.
*/

View File

@ -228,12 +228,14 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
* strategy set for the manga.
*
* @param chapter the current active chapter.
* @param previousChapterAmount the desired number of chapters preceding the current active chapter (Default: 1).
* @param nextChapterAmount the desired number of chapters succeeding the current active chapter (Default: 1).
*/
private fun getAdjacentChaptersStrategy(chapter: ReaderChapter) = when (manga.sorting) {
private fun getAdjacentChaptersStrategy(chapter: ReaderChapter, previousChapterAmount: Int = 1, nextChapterAmount: Int = 1) = when (manga.sorting) {
Manga.SORTING_SOURCE -> {
val currChapterIndex = chapterList.indexOfFirst { chapter.id == it.id }
val nextChapter = chapterList.getOrNull(currChapterIndex + 1)
val prevChapter = chapterList.getOrNull(currChapterIndex - 1)
val nextChapter = chapterList.getOrNull(currChapterIndex + nextChapterAmount)
val prevChapter = chapterList.getOrNull(currChapterIndex - previousChapterAmount)
Pair(prevChapter, nextChapter)
}
Manga.SORTING_NUMBER -> {
@ -241,18 +243,18 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
val chapterNumber = chapter.chapter_number
var prevChapter: ReaderChapter? = null
for (i in (currChapterIndex - 1) downTo 0) {
for (i in (currChapterIndex - previousChapterAmount) downTo 0) {
val c = chapterList[i]
if (c.chapter_number < chapterNumber && c.chapter_number >= chapterNumber - 1) {
if (c.chapter_number < chapterNumber && c.chapter_number >= chapterNumber - previousChapterAmount) {
prevChapter = c
break
}
}
var nextChapter: ReaderChapter? = null
for (i in (currChapterIndex + 1) until chapterList.size) {
for (i in (currChapterIndex + nextChapterAmount) until chapterList.size) {
val c = chapterList[i]
if (c.chapter_number > chapterNumber && c.chapter_number <= chapterNumber + 1) {
if (c.chapter_number > chapterNumber && c.chapter_number <= chapterNumber + nextChapterAmount) {
nextChapter = c
break
}
@ -344,7 +346,6 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
fun onChapterLeft() {
// Reference these locally because they are needed later from another thread.
val chapter = chapter
val prevChapter = prevChapter
val pages = chapter.pages ?: return
@ -355,21 +356,21 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
chapter.read = true
}
// Cache current page list progress for online chapters to allow a faster reopen
if (!chapter.isDownloaded) {
source.let { if (it is OnlineSource) it.savePageList(chapter, pages) }
}
// Cache current page list progress for online chapters to allow a faster reopen
if (chapter.read) {
// Check if remove after read is selected by user
if (prefs.removeAfterRead()) {
if (prefs.removeAfterReadPrevious() ) {
if (prevChapter != null) {
deleteChapter(prevChapter, manga)
}
} else {
deleteChapter(chapter, manga)
}
val removeAfterReadSlots = prefs.removeAfterReadSlots()
when (removeAfterReadSlots) {
// Setting disabled
-1 -> { /**Empty function**/ }
// Remove current read chapter
0 -> deleteChapter(chapter, manga)
// Remove previous chapter specified by user in settings.
else -> getAdjacentChaptersStrategy(chapter, removeAfterReadSlots)
.first?.let { deleteChapter(it, manga) }
}
}

View File

@ -9,13 +9,17 @@
app:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/action_filter_downloaded"
android:id="@+id/action_filter_read"
android:checkable="true"
android:title="@string/action_filter_downloaded"/>
android:title="@string/action_filter_read"/>
<item
android:id="@+id/action_filter_unread"
android:checkable="true"
android:title="@string/action_filter_unread"/>
<item
android:id="@+id/action_filter_downloaded"
android:checkable="true"
android:title="@string/action_filter_downloaded"/>
<item
android:id="@+id/action_filter_empty"
android:title="@string/action_filter_empty"/>

View File

@ -1,13 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog bulletedList="false">
<changelogversion versionName="r736" changeDate="">
<changelogversion changeDate="" versionName="r857">
<changelogtext>[b]Important![/b] Delete after read has been updated.
This means the value has been reset set to disabled.
This can be changed in Settings > Downloads
</changelogtext>
</changelogversion>
<changelogversion changeDate="" versionName="r736">
<changelogtext>[b]Important![/b] Now chapters follow the order of the sources. [b]It's required that you update your entire library
before reading in order for them to be synced.[/b] Old behavior can be restored for a manga in the overflow menu of the chapters tab.
</changelogtext>
</changelogversion>
<changelogversion versionName="r724" changeDate="">
<changelogversion changeDate="" versionName="r724">
<changelogtext>Kissmanga covers may not load anymore. The only workaround is to update the details of the manga
from the info tab, or clearing the database (the latter won't fix covers from library manga).
</changelogtext>

View File

@ -48,6 +48,24 @@
<item>3</item>
</string-array>
<string-array name="remove_after_read_slots">
<item>@string/disabled</item>
<item>@string/last_read_chapter</item>
<item>@string/second_to_last</item>
<item>@string/third_to_last</item>
<item>@string/fourth_to_last</item>
<item>@string/fifth_to_last</item>
</string-array>
<string-array name="remove_after_read_slots_values">
<item>-1</item>
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="image_decoders">
<item>@string/rapid_decoder</item>
<item>@string/skia_decoder</item>

View File

@ -41,13 +41,11 @@
<string name="pref_download_directory_key">pref_download_directory_key</string>
<string name="pref_download_slots_key">pref_download_slots_key</string>
<string name="pref_remove_after_read_slots_key">remove_after_read_slots</string>
<string name="pref_download_only_over_wifi_key">pref_download_only_over_wifi_key</string>
<string name="pref_remove_after_marked_as_read_key">pref_remove_after_marked_as_read_key</string>
<string name="pref_category_remove_after_read_key">pref_category_remove_after_read_key</string>
<string name="pref_remove_after_read_key">pref_remove_after_read_key</string>
<string name="pref_remove_after_read_previous_key">pref_remove_after_read_previous_key</string>
<string name="pref_last_used_category_key">last_used_category</string>
<string name="pref_source_languages">pref_source_languages</string>

View File

@ -19,6 +19,7 @@
<string name="action_filter">Filter</string>
<string name="action_filter_downloaded">Downloaded</string>
<string name="action_filter_unread">Unread</string>
<string name="action_filter_read">Read</string>
<string name="action_filter_empty">Remove filter</string>
<string name="action_search">Search</string>
<string name="action_select_all">Select all</string>
@ -142,11 +143,13 @@
<string name="pref_download_only_over_wifi">Only download over Wi-Fi</string>
<string name="pref_remove_after_marked_as_read">Remove when marked as read</string>
<string name="pref_remove_after_read">Remove after read</string>
<string name="cat_remove_after_read">Remove after read</string>
<string name="current_chapter">Current chapter</string>
<string name="previous_chapter">Previous chapter</string>
<string name="custom_dir">Custom directory</string>
<string name="disabled">Disabled</string>
<string name="last_read_chapter">Last read chapter</string>
<string name="second_to_last">Second to last chapter</string>
<string name="third_to_last">Third to last chapter</string>
<string name="fourth_to_last">Fourth to last chapter</string>
<string name="fifth_to_last">Fifth to last chapter</string>
<!-- Sources section -->
<string name="languages">Languages</string>

View File

@ -25,25 +25,20 @@
<PreferenceCategory
android:persistent="false"
android:title="@string/cat_remove_after_read"/>
android:title="@string/pref_remove_after_read" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_remove_after_marked_as_read_key"
android:title="@string/pref_remove_after_marked_as_read"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_remove_after_read_key"
android:summary="@string/current_chapter"
android:title="@string/pref_remove_after_read"/>
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/pref_remove_after_read_key"
android:key="@string/pref_remove_after_read_previous_key"
android:summary="@string/previous_chapter"
android:title="@string/pref_remove_after_read"/>
<eu.kanade.tachiyomi.widget.preference.IntListPreference
android:defaultValue="-1"
android:entries="@array/remove_after_read_slots"
android:entryValues="@array/remove_after_read_slots_values"
android:key="@string/pref_remove_after_read_slots_key"
android:summary="%s"
android:title="@string/pref_remove_after_read" />
</PreferenceScreen>