From 6c069ad87b82777fd3bedd99a9a5229daa7d6317 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:01:11 +0100 Subject: [PATCH 1/6] 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 1b7534d70b..e6989b23b5 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 1d56f62b39..5beb7871e4 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 3e995687ce..387a69d8b7 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 From 4be0b2502e264f7f95f32214c2790c90fe461406 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:25:36 +0100 Subject: [PATCH 2/6] Change stop to pause in download queue view --- .../tachiyomi/ui/download/DownloadFragment.java | 12 ++++++------ app/src/main/res/drawable-hdpi/ic_pause.png | Bin 0 -> 105 bytes app/src/main/res/drawable-ldpi/ic_pause.png | Bin 0 -> 95 bytes app/src/main/res/drawable-mdpi/ic_pause.png | Bin 0 -> 83 bytes app/src/main/res/drawable-xhdpi/ic_pause.png | Bin 0 -> 90 bytes app/src/main/res/drawable-xxhdpi/ic_pause.png | Bin 0 -> 92 bytes app/src/main/res/drawable-xxxhdpi/ic_pause.png | Bin 0 -> 94 bytes app/src/main/res/menu/download_queue.xml | 6 +++--- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_pause.png create mode 100644 app/src/main/res/drawable-ldpi/ic_pause.png create mode 100644 app/src/main/res/drawable-mdpi/ic_pause.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_pause.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_pause.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_pause.png diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java index 30e85441ae..57ee5fba46 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java @@ -29,7 +29,7 @@ public class DownloadFragment extends BaseRxFragment { private DownloadAdapter adapter; private MenuItem startButton; - private MenuItem stopButton; + private MenuItem pauseButton; private Subscription queueStatusSubscription; private boolean isRunning; @@ -64,11 +64,11 @@ public class DownloadFragment extends BaseRxFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.download_queue, menu); startButton = menu.findItem(R.id.start_queue); - stopButton = menu.findItem(R.id.stop_queue); + pauseButton = menu.findItem(R.id.pause_queue); // Menu seems to be inflated after onResume in fragments, so we initialize them here startButton.setVisible(!isRunning && !getPresenter().downloadManager.getQueue().isEmpty()); - stopButton.setVisible(isRunning); + pauseButton.setVisible(isRunning); } @Override @@ -77,7 +77,7 @@ public class DownloadFragment extends BaseRxFragment { case R.id.start_queue: DownloadService.start(getActivity()); break; - case R.id.stop_queue: + case R.id.pause_queue: DownloadService.stop(getActivity()); break; } @@ -101,8 +101,8 @@ public class DownloadFragment extends BaseRxFragment { isRunning = running; if (startButton != null) startButton.setVisible(!running && !getPresenter().downloadManager.getQueue().isEmpty()); - if (stopButton != null) - stopButton.setVisible(running); + if (pauseButton != null) + pauseButton.setVisible(running); } private void createAdapter() { diff --git a/app/src/main/res/drawable-hdpi/ic_pause.png b/app/src/main/res/drawable-hdpi/ic_pause.png new file mode 100644 index 0000000000000000000000000000000000000000..4d2ea05c462291e4a4f8bd30856a25ad33fd420f GIT binary patch literal 105 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K;fv1aOh{y5d1PRu~43dBH9UPL5 z6iT4)78&qol`;+06sJs-v9sr literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_pause.png b/app/src/main/res/drawable-mdpi/ic_pause.png new file mode 100644 index 0000000000000000000000000000000000000000..2272d478c38ddb2a4b3c592b2eadee8d4e296432 GIT binary patch literal 83 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1DNh&25R22v2@)?K*o!=P)So4B g)u6(pM}&c4fy8~qgzopr0A!jv*C{ m$r5W0{Noqkjk>0hJ%NeAb!~d=tj~okAZ?zmelF{r5}E*xz!xz9 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_pause.png b/app/src/main/res/drawable-xxxhdpi/ic_pause.png new file mode 100644 index 0000000000000000000000000000000000000000..660ac658589240d14b259e91e6864dc8a8f3665d GIT binary patch literal 94 zcmeAS@N?(olHy`uVBq!ia0vp^2_Vb}Bp6OT_L>T$m`Z~Df*BafCZDwc^29w|978G? plNp)=Km51n;8#DVkv_$ki-GCDeZ`wzAGd%sdb;|#taD0e0szsl7@+_F literal 0 HcmV?d00001 diff --git a/app/src/main/res/menu/download_queue.xml b/app/src/main/res/menu/download_queue.xml index e15e208e08..8de1cd1075 100644 --- a/app/src/main/res/menu/download_queue.xml +++ b/app/src/main/res/menu/download_queue.xml @@ -8,9 +8,9 @@ android:visible="false" app:showAsAction="ifRoom"/> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 387a69d8b7..8dbfb919f5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,12 +35,12 @@ Next unread Start Stop + Pause Previous chapter Next chapter Retry Change display mode - OK Cancel From 50d71d1395d9a7af6bd480341b3cb0cb5254a90b Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:34:41 +0100 Subject: [PATCH 3/6] clear the download queue --- .../ui/download/DownloadFragment.java | 22 +++++++++++-------- app/src/main/res/menu/download_queue.xml | 5 +++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java index 57ee5fba46..e2dd46c682 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java @@ -4,15 +4,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; 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 java.util.List; - +import android.view.*; import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.tachiyomi.R; @@ -22,6 +14,9 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment; import nucleus.factory.RequiresPresenter; import rx.Subscription; +import java.util.ArrayList; +import java.util.List; + @RequiresPresenter(DownloadPresenter.class) public class DownloadFragment extends BaseRxFragment { @@ -66,6 +61,10 @@ public class DownloadFragment extends BaseRxFragment { startButton = menu.findItem(R.id.start_queue); pauseButton = menu.findItem(R.id.pause_queue); + if(adapter.getItemCount() > 0) { + menu.findItem(R.id.clear_queue).setVisible(true); + } + // Menu seems to be inflated after onResume in fragments, so we initialize them here startButton.setVisible(!isRunning && !getPresenter().downloadManager.getQueue().isEmpty()); pauseButton.setVisible(isRunning); @@ -80,6 +79,11 @@ public class DownloadFragment extends BaseRxFragment { case R.id.pause_queue: DownloadService.stop(getActivity()); break; + case R.id.clear_queue: // Not sure if this is correct + DownloadService.stop(getActivity()); + getPresenter().downloadManager.getQueue().clear(); + onNextDownloads(new ArrayList<>()); + break; } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/res/menu/download_queue.xml b/app/src/main/res/menu/download_queue.xml index 8de1cd1075..118f1b45c2 100644 --- a/app/src/main/res/menu/download_queue.xml +++ b/app/src/main/res/menu/download_queue.xml @@ -14,4 +14,9 @@ android:visible="false" app:showAsAction="ifRoom"/> + + \ 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 8dbfb919f5..e23ce60fd4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -36,6 +36,7 @@ Start Stop Pause + Clear Previous chapter Next chapter Retry From f84731c2dfdfbc15eade6bd2dfd88ed466743bd8 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:50:26 +0100 Subject: [PATCH 4/6] cleanup chapter action menu --- .../ui/manga/chapter/ChaptersHolder.java | 37 ++++++++++++++----- app/src/main/res/menu/chapter_single.xml | 31 ++++++++-------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java index e8cc3a927a..60669fc51f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java @@ -2,16 +2,11 @@ package eu.kanade.tachiyomi.ui.manga.chapter; import android.content.Context; import android.support.v4.content.ContextCompat; +import android.view.Menu; import android.view.View; import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; - -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Date; - import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.tachiyomi.R; @@ -21,6 +16,11 @@ import eu.kanade.tachiyomi.data.download.model.Download; import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder; import rx.Observable; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Date; + public class ChaptersHolder extends FlexibleViewHolder { @Bind(R.id.chapter_title) TextView title; @@ -110,19 +110,36 @@ public class ChaptersHolder extends FlexibleViewHolder { // Inflate our menu resource into the PopupMenu's Menu popup.getMenuInflater().inflate(R.menu.chapter_single, popup.getMenu()); + // Hide download and show delete if the chapter is downloaded and + if(item.isDownloaded()) { + Menu menu = popup.getMenu(); + menu.findItem(R.id.action_download).setVisible(false); + menu.findItem(R.id.action_delete).setVisible(true); + } + + // Hide mark as unread when the chapter is unread + if(!item.read && item.last_page_read == 0) { + popup.getMenu().findItem(R.id.action_mark_as_unread).setVisible(false); + } + + // Hide mark as read when the chapter is read + if(item.read) { + popup.getMenu().findItem(R.id.action_mark_as_read).setVisible(false); + } + // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener(menuItem -> { Observable chapter = Observable.just(item); switch (menuItem.getItemId()) { - case R.id.action_mark_as_read: - return adapter.getFragment().onMarkAsRead(chapter); - case R.id.action_mark_as_unread: - return adapter.getFragment().onMarkAsUnread(chapter); case R.id.action_download: return adapter.getFragment().onDownload(chapter); case R.id.action_delete: return adapter.getFragment().onDelete(chapter); + case R.id.action_mark_as_read: + return adapter.getFragment().onMarkAsRead(chapter); + case R.id.action_mark_as_unread: + return adapter.getFragment().onMarkAsUnread(chapter); case R.id.action_mark_previous_as_read: return adapter.getFragment().onMarkPreviousAsRead(item); } diff --git a/app/src/main/res/menu/chapter_single.xml b/app/src/main/res/menu/chapter_single.xml index 36540bc66b..3d91f56b43 100644 --- a/app/src/main/res/menu/chapter_single.xml +++ b/app/src/main/res/menu/chapter_single.xml @@ -4,27 +4,28 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="@string/action_download" + android:icon="@drawable/ic_file_download" + android:visible="true" + app:showAsAction="ifRoom"/> + android:title="@string/action_delete" + android:icon="@drawable/ic_action_delete" + android:visible="false" + app:showAsAction="ifRoom"/> + android:title="@string/action_mark_as_read" + android:icon="@drawable/ic_action_done_all" + app:showAsAction="ifRoom"/> + android:title="@string/action_mark_as_unread" + android:icon="@drawable/ic_action_undone_all" + app:showAsAction="ifRoom"/> - + \ No newline at end of file From d8b46c19699e6ae19096bedb10452b1f49f622a7 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:57:11 +0100 Subject: [PATCH 5/6] set display mode title --- .../eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java | 1 + 1 file changed, 1 insertion(+) 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 e6989b23b5..d17d02f644 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 @@ -187,6 +187,7 @@ public class ChaptersFragment extends BaseRxFragment implemen int selectedIndex = manga.getDisplayMode() == Manga.DISPLAY_NAME ? 0 : 1; new MaterialDialog.Builder(getActivity()) + .title(R.string.action_display_mode) .items(modes) .itemsIds(ids) .itemsCallbackSingleChoice(selectedIndex, (dialog, itemView, which, text) -> { From 63d0161da554c70c8b46ae1de7583b94967859cf Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 17:42:39 +0100 Subject: [PATCH 6/6] move clear queue to presenter --- .../tachiyomi/ui/download/DownloadFragment.java | 11 ++++++----- .../tachiyomi/ui/download/DownloadPresenter.java | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java index e2dd46c682..68ac1d6ba6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment; import nucleus.factory.RequiresPresenter; import rx.Subscription; -import java.util.ArrayList; import java.util.List; @RequiresPresenter(DownloadPresenter.class) @@ -25,6 +24,7 @@ public class DownloadFragment extends BaseRxFragment { private MenuItem startButton; private MenuItem pauseButton; + private MenuItem clearButton; private Subscription queueStatusSubscription; private boolean isRunning; @@ -60,9 +60,10 @@ public class DownloadFragment extends BaseRxFragment { inflater.inflate(R.menu.download_queue, menu); startButton = menu.findItem(R.id.start_queue); pauseButton = menu.findItem(R.id.pause_queue); + clearButton = menu.findItem(R.id.clear_queue); if(adapter.getItemCount() > 0) { - menu.findItem(R.id.clear_queue).setVisible(true); + clearButton.setVisible(true); } // Menu seems to be inflated after onResume in fragments, so we initialize them here @@ -79,10 +80,10 @@ public class DownloadFragment extends BaseRxFragment { case R.id.pause_queue: DownloadService.stop(getActivity()); break; - case R.id.clear_queue: // Not sure if this is correct + case R.id.clear_queue: DownloadService.stop(getActivity()); - getPresenter().downloadManager.getQueue().clear(); - onNextDownloads(new ArrayList<>()); + getPresenter().clearQueue(); + clearButton.setVisible(false); break; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java index 36bb3d3080..df10854a61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java @@ -1,12 +1,6 @@ package eu.kanade.tachiyomi.ui.download; import android.os.Bundle; - -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; - import eu.kanade.tachiyomi.data.download.DownloadManager; import eu.kanade.tachiyomi.data.download.model.Download; import eu.kanade.tachiyomi.data.download.model.DownloadQueue; @@ -18,6 +12,10 @@ import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; import timber.log.Timber; +import javax.inject.Inject; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + public class DownloadPresenter extends BasePresenter { @Inject DownloadManager downloadManager; @@ -123,4 +121,8 @@ public class DownloadPresenter extends BasePresenter { remove(statusSubscription); } + public void clearQueue() { + downloadQueue.clear(); + start(GET_DOWNLOAD_QUEUE); + } }