Added option te delete chapter after reading.

Go to Setting > Downloads to toggle: default = false.
This commit is contained in:
NoodleMage 2016-02-20 11:50:38 +01:00
parent 8581e4667a
commit 9f30033a7a
5 changed files with 77 additions and 3 deletions

View file

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

View file

@ -80,7 +80,8 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
(view, pair) -> view.onAdjacentChapters(pair.first, pair.second));
startable(PRELOAD_NEXT_CHAPTER, this::getPreloadNextChapterObservable,
next -> {},
next -> {
},
error -> Timber.e("Error preloading chapter"));
@ -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();
}
@ -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();

View file

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

View file

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

View file

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