mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 11:29:15 +01:00
Added option te delete chapter after reading.
Go to Setting > Downloads to toggle: default = false.
This commit is contained in:
parent
8581e4667a
commit
9f30033a7a
@ -185,6 +185,14 @@ public class PreferencesHelper {
|
||||
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns preference of deletion after reading chapter
|
||||
* @return preference of deletion
|
||||
*/
|
||||
public boolean deleteChapterAfterReading() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_delete_after_reading_key), false);
|
||||
}
|
||||
|
||||
public static int getLibraryUpdateInterval(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
|
||||
context.getString(R.string.pref_library_update_interval_key), 0);
|
||||
|
@ -80,8 +80,9 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
(view, pair) -> view.onAdjacentChapters(pair.first, pair.second));
|
||||
|
||||
startable(PRELOAD_NEXT_CHAPTER, this::getPreloadNextChapterObservable,
|
||||
next -> {},
|
||||
error -> Timber.e("Error preloading chapter"));
|
||||
next -> {
|
||||
},
|
||||
error -> Timber.e("Error preloading chapter"));
|
||||
|
||||
|
||||
restartable(GET_MANGA_SYNC, () -> getMangaSyncObservable().subscribe());
|
||||
@ -316,6 +317,16 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
// Save current progress of the chapter. Mark as read if the chapter is finished
|
||||
if (activePage.isLastPage()) {
|
||||
activeChapter.read = true;
|
||||
|
||||
// Check if user want to delete manga after reading it.
|
||||
if (prefs.deleteChapterAfterReading()) {
|
||||
// Check if the chapter is downloaded.
|
||||
if (activeChapter.isDownloaded()) {
|
||||
// Delete chapter.
|
||||
Observable<Chapter> chapterObservable = Observable.just(activeChapter);
|
||||
onDelete(chapterObservable, manga);
|
||||
}
|
||||
}
|
||||
}
|
||||
db.insertChapter(activeChapter).asRxObservable().subscribe();
|
||||
}
|
||||
@ -328,7 +339,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
// If the current chapter has been read, we check with this one
|
||||
if (activeChapter.read)
|
||||
lastChapterReadLocal = (int) Math.floor(activeChapter.chapter_number);
|
||||
// If not, we check if the previous chapter has been read
|
||||
// If not, we check if the previous chapter has been read
|
||||
else if (previousChapter != null && previousChapter.read)
|
||||
lastChapterReadLocal = (int) Math.floor(previousChapter.chapter_number);
|
||||
|
||||
@ -399,6 +410,55 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start deleting chapter
|
||||
*
|
||||
* @param chapters selected chapters
|
||||
* @param manga manga that belongs to chapter
|
||||
* @return success of deletion.
|
||||
*/
|
||||
protected boolean onDelete(Observable<Chapter> chapters, Manga manga) {
|
||||
Observable<Chapter> observable = chapters
|
||||
.concatMap(chapter -> {
|
||||
deleteChapter(chapter, manga);
|
||||
return Observable.just(chapter);
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(chapter -> {
|
||||
chapter.status = Download.NOT_DOWNLOADED;
|
||||
});
|
||||
|
||||
deleteChapters(observable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete selected chapter
|
||||
*
|
||||
* @param chapter chapter that is selected
|
||||
* @param manga manga that belongs to chapter
|
||||
*/
|
||||
public void deleteChapter(Chapter chapter, Manga manga) {
|
||||
Source source = sourceManager.get(manga.source);
|
||||
downloadManager.deleteChapter(source, manga, chapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete selected chapter observable
|
||||
*
|
||||
* @param selectedChapters chapter that are selected
|
||||
*/
|
||||
public void deleteChapters(Observable<Chapter> selectedChapters) {
|
||||
add(selectedChapters
|
||||
.subscribe(chapter -> {
|
||||
downloadManager.getQueue().remove(chapter);
|
||||
}, error -> {
|
||||
Timber.e(error.getMessage());
|
||||
}));
|
||||
}
|
||||
|
||||
public void updateMangaViewer(int viewer) {
|
||||
manga.viewer = viewer;
|
||||
db.insertManga(manga).executeAsBlocking();
|
||||
|
@ -32,6 +32,7 @@
|
||||
<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_only_over_wifi_key">pref_download_only_over_wifi_key</string>
|
||||
<string name="pref_delete_after_reading_key">pref_delete_after_reading_key</string>
|
||||
|
||||
<string name="pref_clear_chapter_cache_key">pref_clear_chapter_cache_key</string>
|
||||
<string name="pref_clear_database_key">pref_clear_database_key</string>
|
||||
|
@ -123,6 +123,7 @@
|
||||
<string name="pref_download_directory">Downloads directory</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_delete_after_reading">Delete chapter after reading</string>
|
||||
|
||||
<!-- Advanced section -->
|
||||
<string name="pref_clear_chapter_cache">Clear chapter cache</string>
|
||||
|
@ -10,6 +10,10 @@
|
||||
android:key="@string/pref_download_only_over_wifi_key"
|
||||
android:defaultValue="true"/>
|
||||
|
||||
<SwitchPreference android:title="@string/pref_delete_after_reading"
|
||||
android:key="@string/pref_delete_after_reading_key"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<eu.kanade.tachiyomi.widget.preference.IntListPreference
|
||||
android:title="@string/pref_download_slots"
|
||||
android:key="@string/pref_download_slots_key"
|
||||
|
Loading…
Reference in New Issue
Block a user