mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-11 12:13:15 +02:00
commit
03ecb2fe13
@ -190,6 +190,18 @@ class PreferencesHelper(private val context: Context) {
|
|||||||
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true)
|
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeAfterRead(): Boolean {
|
||||||
|
return prefs.getBoolean(getKey(R.string.pref_remove_after_read_key), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeAfterReadPrevious(): Boolean {
|
||||||
|
return prefs.getBoolean(getKey(R.string.pref_remove_after_read_previous_key), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeAfterMarkedAsRead(): Boolean {
|
||||||
|
return prefs.getBoolean(getKey(R.string.pref_remove_after_marked_as_read_key), false)
|
||||||
|
}
|
||||||
|
|
||||||
fun libraryUpdateInterval(): Preference<Int> {
|
fun libraryUpdateInterval(): Preference<Int> {
|
||||||
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0)
|
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import nucleus.factory.RequiresPresenter
|
|||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
@RequiresPresenter(ChaptersPresenter::class)
|
@RequiresPresenter(ChaptersPresenter::class)
|
||||||
class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
|
class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
|
||||||
@ -217,23 +216,41 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
|
|||||||
|
|
||||||
private fun showDownloadDialog() {
|
private fun showDownloadDialog() {
|
||||||
// Get available modes
|
// Get available modes
|
||||||
val modes = listOf(getString(R.string.download_all), getString(R.string.download_unread))
|
val modes = listOf(getString(R.string.download_1), getString(R.string.download_5), getString(R.string.download_10),
|
||||||
|
getString(R.string.download_unread), getString(R.string.download_all))
|
||||||
|
|
||||||
MaterialDialog.Builder(activity)
|
MaterialDialog.Builder(activity)
|
||||||
.title(R.string.manga_download)
|
.title(R.string.manga_download)
|
||||||
.negativeText(android.R.string.cancel)
|
.negativeText(android.R.string.cancel)
|
||||||
.items(modes)
|
.items(modes)
|
||||||
.itemsCallback { dialog, view, i, charSequence ->
|
.itemsCallback { dialog, view, i, charSequence ->
|
||||||
val chapters = ArrayList<Chapter>()
|
var chapters: MutableList<Chapter> = arrayListOf()
|
||||||
|
|
||||||
|
// i = 0: Download 1
|
||||||
|
// i = 1: Download 5
|
||||||
|
// i = 2: Download 10
|
||||||
|
// i = 3: Download unread
|
||||||
|
// i = 4: Download all
|
||||||
for (chapter in presenter.chapters) {
|
for (chapter in presenter.chapters) {
|
||||||
if (!chapter.isDownloaded) {
|
if (!chapter.isDownloaded) {
|
||||||
if (i == 0 || (i == 1 && !chapter.read)) {
|
if (i == 4 || (i != 4 && !chapter.read)) {
|
||||||
chapters.add(chapter)
|
chapters.add(chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chapters.size > 0) {
|
if (chapters.size > 0) {
|
||||||
|
when (i) {
|
||||||
|
// Set correct chapters size if desired
|
||||||
|
0 -> chapters = chapters.subList(0, 1)
|
||||||
|
1 -> {
|
||||||
|
if (chapters.size >= 5)
|
||||||
|
chapters = chapters.subList(0, 5)
|
||||||
|
}
|
||||||
|
2 -> {
|
||||||
|
if (chapters.size >= 10)
|
||||||
|
chapters = chapters.subList(0, 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
onDownload(Observable.from(chapters))
|
onDownload(Observable.from(chapters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,6 +191,11 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
|
|||||||
.doOnNext { chapter ->
|
.doOnNext { chapter ->
|
||||||
chapter.read = read
|
chapter.read = read
|
||||||
if (!read) chapter.last_page_read = 0
|
if (!read) chapter.last_page_read = 0
|
||||||
|
|
||||||
|
// Delete chapter when marked as read if desired by user.
|
||||||
|
if (preferences.removeAfterMarkedAsRead() && read) {
|
||||||
|
deleteChapter(chapter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
.flatMap { chapters -> db.insertChapters(chapters).asRxObservable() }
|
.flatMap { chapters -> db.insertChapters(chapters).asRxObservable() }
|
||||||
|
@ -252,6 +252,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
nextChapterBtn?.isVisible = presenter.hasNextChapter()
|
nextChapterBtn?.isVisible = presenter.hasNextChapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getOrCreateViewer(manga: Manga): BaseReader {
|
private fun getOrCreateViewer(manga: Manga): BaseReader {
|
||||||
val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer else manga.viewer
|
val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer else manga.viewer
|
||||||
|
|
||||||
|
@ -335,10 +335,32 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
// Save current progress of the chapter. Mark as read if the chapter is finished
|
// Save current progress of the chapter. Mark as read if the chapter is finished
|
||||||
if (activePage.isLastPage) {
|
if (activePage.isLastPage) {
|
||||||
chapter.read = true
|
chapter.read = true
|
||||||
|
|
||||||
|
// Check if remove after read is selected by user
|
||||||
|
if (prefs.removeAfterRead()) {
|
||||||
|
if (prefs.removeAfterReadPrevious() ) {
|
||||||
|
if (previousChapter != null) {
|
||||||
|
deleteChapter(previousChapter!!, manga)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deleteChapter(chapter, manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
db.insertChapter(chapter).asRxObservable().subscribe()
|
db.insertChapter(chapter).asRxObservable().subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete selected chapter
|
||||||
|
* @param chapter chapter that is selected
|
||||||
|
* *
|
||||||
|
* @param manga manga that belongs to chapter
|
||||||
|
*/
|
||||||
|
fun deleteChapter(chapter: Chapter, manga: Manga) {
|
||||||
|
val source = sourceManager.get(manga.source)!!
|
||||||
|
downloadManager.deleteChapter(source, manga, chapter)
|
||||||
|
}
|
||||||
|
|
||||||
// If the current chapter has been read, we check with this one
|
// If the current chapter has been read, we check with this one
|
||||||
// If not, we check if the previous chapter has been read
|
// If not, we check if the previous chapter has been read
|
||||||
// We know the chapter we have to check, but we don't know yet if an update is required.
|
// We know the chapter we have to check, but we don't know yet if an update is required.
|
||||||
@ -417,5 +439,4 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
manga.viewer = viewer
|
manga.viewer = viewer
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -202,9 +202,9 @@ class RecentChaptersFragment : BaseRxFragment<RecentChaptersPresenter>(), Flexib
|
|||||||
* @param chapters selected chapter
|
* @param chapters selected chapter
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
fun onMarkAsRead(chapters: Observable<Chapter>): Boolean {
|
fun onMarkAsRead(chapters: Observable<Chapter>, manga : Manga): Boolean {
|
||||||
// Set marked as read
|
// Set marked as read
|
||||||
presenter.markChaptersRead(chapters, true)
|
presenter.markChaptersRead(chapters, manga, true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,9 +214,9 @@ class RecentChaptersFragment : BaseRxFragment<RecentChaptersPresenter>(), Flexib
|
|||||||
* @param chapters selected chapter
|
* @param chapters selected chapter
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
fun onMarkAsUnread(chapters: Observable<Chapter>): Boolean {
|
fun onMarkAsUnread(chapters: Observable<Chapter> , manga : Manga): Boolean {
|
||||||
// Set marked as unread
|
// Set marked as unread
|
||||||
presenter.markChaptersRead(chapters, false)
|
presenter.markChaptersRead(chapters, manga, false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +125,8 @@ class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapte
|
|||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.action_download -> adapter.fragment.onDownload(chapterObservable, it.manga)
|
R.id.action_download -> adapter.fragment.onDownload(chapterObservable, it.manga)
|
||||||
R.id.action_delete -> adapter.fragment.onDelete(chapterObservable, it.manga)
|
R.id.action_delete -> adapter.fragment.onDelete(chapterObservable, it.manga)
|
||||||
R.id.action_mark_as_read -> adapter.fragment.onMarkAsRead(chapterObservable);
|
R.id.action_mark_as_read -> adapter.fragment.onMarkAsRead(chapterObservable, it.manga);
|
||||||
R.id.action_mark_as_unread -> adapter.fragment.onMarkAsUnread(chapterObservable);
|
R.id.action_mark_as_unread -> adapter.fragment.onMarkAsUnread(chapterObservable, it.manga);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
|||||||
import eu.kanade.tachiyomi.data.database.models.MangaChapter
|
import eu.kanade.tachiyomi.data.database.models.MangaChapter
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.event.DownloadChaptersEvent
|
import eu.kanade.tachiyomi.event.DownloadChaptersEvent
|
||||||
import eu.kanade.tachiyomi.event.ReaderEvent
|
import eu.kanade.tachiyomi.event.ReaderEvent
|
||||||
@ -25,6 +26,11 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
|||||||
*/
|
*/
|
||||||
@Inject lateinit var db: DatabaseHelper
|
@Inject lateinit var db: DatabaseHelper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to get settings
|
||||||
|
*/
|
||||||
|
@Inject lateinit var preferences: PreferencesHelper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get information from download manager
|
* Used to get information from download manager
|
||||||
*/
|
*/
|
||||||
@ -291,15 +297,16 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
|||||||
* *
|
* *
|
||||||
* @param read read status
|
* @param read read status
|
||||||
*/
|
*/
|
||||||
fun markChaptersRead(selectedChapters: Observable<Chapter>, read: Boolean) {
|
fun markChaptersRead(selectedChapters: Observable<Chapter>, manga: Manga, read: Boolean) {
|
||||||
add(selectedChapters
|
add(selectedChapters.subscribeOn(Schedulers.io())
|
||||||
.subscribeOn(Schedulers.io())
|
.doOnNext { chapter ->
|
||||||
.map { chapter ->
|
|
||||||
chapter.read = read
|
chapter.read = read
|
||||||
if (!read) {
|
if (!read) chapter.last_page_read = 0
|
||||||
chapter.last_page_read = 0
|
|
||||||
|
// Delete chapter when marked as read if desired by user.
|
||||||
|
if (preferences.removeAfterMarkedAsRead() && read) {
|
||||||
|
deleteChapter(chapter,manga)
|
||||||
}
|
}
|
||||||
chapter
|
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
.flatMap { chapters -> db.insertChapters(chapters).asRxObservable() }
|
.flatMap { chapters -> db.insertChapters(chapters).asRxObservable() }
|
||||||
|
@ -20,7 +20,6 @@ import java.io.File
|
|||||||
class SettingsDownloadsFragment : SettingsNestedFragment() {
|
class SettingsDownloadsFragment : SettingsNestedFragment() {
|
||||||
|
|
||||||
val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) }
|
val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val DOWNLOAD_DIR_CODE = 103
|
val DOWNLOAD_DIR_CODE = 103
|
||||||
|
@ -36,6 +36,12 @@
|
|||||||
<string name="pref_download_directory_key">pref_download_directory_key</string>
|
<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_download_slots_key">pref_download_slots_key</string>
|
||||||
<string name="pref_download_only_over_wifi_key">pref_download_only_over_wifi_key</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_source_languages">pref_source_languages</string>
|
<string name="pref_source_languages">pref_source_languages</string>
|
||||||
|
|
||||||
|
@ -134,8 +134,14 @@
|
|||||||
<string name="pref_download_directory">Downloads directory</string>
|
<string name="pref_download_directory">Downloads directory</string>
|
||||||
<string name="pref_download_slots">Simultaneous downloads</string>
|
<string name="pref_download_slots">Simultaneous downloads</string>
|
||||||
<string name="pref_download_only_over_wifi">Only download over Wi-Fi</string>
|
<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="custom_dir">Custom directory</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Sources section -->
|
<!-- Sources section -->
|
||||||
<string name="languages">Languages</string>
|
<string name="languages">Languages</string>
|
||||||
<string name="languages_summary">Select the languages to show sources from</string>
|
<string name="languages_summary">Select the languages to show sources from</string>
|
||||||
@ -208,6 +214,9 @@
|
|||||||
<string name="show_title">Show title</string>
|
<string name="show_title">Show title</string>
|
||||||
<string name="show_chapter_number">Show chapter number</string>
|
<string name="show_chapter_number">Show chapter number</string>
|
||||||
<string name="manga_download">Download</string>
|
<string name="manga_download">Download</string>
|
||||||
|
<string name="download_1">Download next chapter</string>
|
||||||
|
<string name="download_5">Download next 5 chapters</string>
|
||||||
|
<string name="download_10">Download next 10 chapters</string>
|
||||||
<string name="download_all">Download all</string>
|
<string name="download_all">Download all</string>
|
||||||
<string name="download_unread">Download unread</string>
|
<string name="download_unread">Download unread</string>
|
||||||
|
|
||||||
|
@ -3,20 +3,41 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/pref_download_directory"
|
android:key="@string/pref_download_directory_key"
|
||||||
android:key="@string/pref_download_directory_key"/>
|
android:title="@string/pref_download_directory"/>
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:title="@string/pref_download_only_over_wifi"
|
android:defaultValue="true"
|
||||||
android:key="@string/pref_download_only_over_wifi_key"
|
android:key="@string/pref_download_only_over_wifi_key"
|
||||||
android:defaultValue="true"/>
|
android:title="@string/pref_download_only_over_wifi"/>
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.widget.preference.IntListPreference
|
<eu.kanade.tachiyomi.widget.preference.IntListPreference
|
||||||
android:title="@string/pref_download_slots"
|
android:defaultValue="1"
|
||||||
android:key="@string/pref_download_slots_key"
|
|
||||||
android:entries="@array/download_slots"
|
android:entries="@array/download_slots"
|
||||||
android:entryValues="@array/download_slots"
|
android:entryValues="@array/download_slots"
|
||||||
android:defaultValue="1"
|
android:key="@string/pref_download_slots_key"
|
||||||
android:summary="%s"/>
|
android:summary="%s"
|
||||||
|
android:title="@string/pref_download_slots"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/cat_remove_after_read"/>
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/pref_remove_after_marked_as_read_key"
|
||||||
|
android:title="@string/pref_remove_after_marked_as_read"/>
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/pref_remove_after_read_key"
|
||||||
|
android:summary="@string/current_chapter"
|
||||||
|
android:title="@string/pref_remove_after_read"/>
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
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"/>
|
||||||
|
|
||||||
</android.support.v7.preference.PreferenceScreen>
|
</android.support.v7.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user