From f84731c2dfdfbc15eade6bd2dfd88ed466743bd8 Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 16:50:26 +0100 Subject: [PATCH] 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 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/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