From 6c069ad87b82777fd3bedd99a9a5229daa7d6317 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:01:11 +0100 Subject: [PATCH] multiple chapter download from manga view --- .../ui/manga/chapter/ChaptersFragment.java | 45 ++++++++++++++----- app/src/main/res/menu/chapters.xml | 5 +++ app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java index 1b7534d70..e6989b23b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java @@ -8,21 +8,12 @@ import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.view.ActionMode; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; +import android.view.*; import android.widget.CheckBox; import android.widget.ImageView; - -import com.afollestad.materialdialogs.MaterialDialog; - -import java.util.List; - import butterknife.Bind; import butterknife.ButterKnife; +import com.afollestad.materialdialogs.MaterialDialog; import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Manga; @@ -40,6 +31,9 @@ import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; +import java.util.ArrayList; +import java.util.List; + @RequiresPresenter(ChaptersPresenter.class) public class ChaptersFragment extends BaseRxFragment implements ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener { @@ -110,6 +104,9 @@ public class ChaptersFragment extends BaseRxFragment implemen case R.id.action_display_mode: showDisplayModeDialog(); return true; + case R.id.manga_download: + showDownloadDialog(); + return true; } return false; } @@ -202,6 +199,32 @@ public class ChaptersFragment extends BaseRxFragment implemen .show(); } + private void showDownloadDialog() { + + // Get available modes + String[] modes = {getString(R.string.download_all), getString(R.string.download_unread)}; + + new MaterialDialog.Builder(getActivity()) + .title(R.string.manga_download) + .items(modes) + .itemsCallback((dialog, view, i, charSequence) -> { + List chapters = new ArrayList<>(); + + for(Chapter chapter : getPresenter().getChapters()) { + if(!chapter.isDownloaded()) { + if(i == 0 || (i == 1 && !chapter.read)) { + chapters.add(chapter); + } + } + } + if(chapters.size() > 0) { + onDownload(Observable.from(chapters)); + } + }) + .negativeText(R.string.button_cancel) + .show(); + } + private void observeChapterDownloadProgress() { downloadProgressSubscription = getPresenter().getDownloadProgressObs() .subscribe(this::onDownloadProgressChange, diff --git a/app/src/main/res/menu/chapters.xml b/app/src/main/res/menu/chapters.xml index 1d56f62b3..5beb7871e 100644 --- a/app/src/main/res/menu/chapters.xml +++ b/app/src/main/res/menu/chapters.xml @@ -6,4 +6,9 @@ android:title="@string/action_display_mode" android:id="@+id/action_display_mode" app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e995687c..387a69d8b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -179,6 +179,9 @@ Error while fetching chapters Show title Show chapter number + Download + Download all + Download unread Reading