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 30e85441a..68ac1d6ba 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,8 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment; import nucleus.factory.RequiresPresenter; import rx.Subscription; +import java.util.List; + @RequiresPresenter(DownloadPresenter.class) public class DownloadFragment extends BaseRxFragment { @@ -29,7 +23,8 @@ public class DownloadFragment extends BaseRxFragment { private DownloadAdapter adapter; private MenuItem startButton; - private MenuItem stopButton; + private MenuItem pauseButton; + private MenuItem clearButton; private Subscription queueStatusSubscription; private boolean isRunning; @@ -64,11 +59,16 @@ 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); + clearButton = menu.findItem(R.id.clear_queue); + + if(adapter.getItemCount() > 0) { + clearButton.setVisible(true); + } // 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,9 +77,14 @@ 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; + case R.id.clear_queue: + DownloadService.stop(getActivity()); + getPresenter().clearQueue(); + clearButton.setVisible(false); + break; } return super.onOptionsItemSelected(item); } @@ -101,8 +106,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/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java index 36bb3d308..df10854a6 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); + } } 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..d17d02f64 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; } @@ -190,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) -> { @@ -202,6 +200,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/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java index e8cc3a927..60669fc51 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/drawable-hdpi/ic_pause.png b/app/src/main/res/drawable-hdpi/ic_pause.png new file mode 100644 index 000000000..4d2ea05c4 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_pause.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_pause.png b/app/src/main/res/drawable-ldpi/ic_pause.png new file mode 100644 index 000000000..d3edf7439 Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_pause.png differ 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 000000000..2272d478c Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_pause.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_pause.png b/app/src/main/res/drawable-xhdpi/ic_pause.png new file mode 100644 index 000000000..f49aed757 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_pause.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_pause.png b/app/src/main/res/drawable-xxhdpi/ic_pause.png new file mode 100644 index 000000000..7192ad487 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_pause.png differ 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 000000000..660ac6585 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_pause.png differ diff --git a/app/src/main/res/menu/chapter_single.xml b/app/src/main/res/menu/chapter_single.xml index 36540bc66..3d91f56b4 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 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/menu/download_queue.xml b/app/src/main/res/menu/download_queue.xml index e15e208e0..118f1b45c 100644 --- a/app/src/main/res/menu/download_queue.xml +++ b/app/src/main/res/menu/download_queue.xml @@ -8,10 +8,15 @@ 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 3e995687c..e23ce60fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,12 +35,13 @@ Next unread Start Stop + Pause + Clear Previous chapter Next chapter Retry Change display mode - OK Cancel @@ -179,6 +180,9 @@ Error while fetching chapters Show title Show chapter number + Download + Download all + Download unread Reading