cleanup chapter action menu

This commit is contained in:
Kevin Richter 2016-02-09 16:50:26 +01:00
parent 50d71d1395
commit f84731c2df
2 changed files with 43 additions and 25 deletions

View File

@ -2,16 +2,11 @@ package eu.kanade.tachiyomi.ui.manga.chapter;
import android.content.Context; import android.content.Context;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.Menu;
import android.view.View; import android.view.View;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; 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.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.kanade.tachiyomi.R; 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 eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
import rx.Observable; import rx.Observable;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Date;
public class ChaptersHolder extends FlexibleViewHolder { public class ChaptersHolder extends FlexibleViewHolder {
@Bind(R.id.chapter_title) TextView title; @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 // Inflate our menu resource into the PopupMenu's Menu
popup.getMenuInflater().inflate(R.menu.chapter_single, popup.getMenu()); 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 // Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener(menuItem -> { popup.setOnMenuItemClickListener(menuItem -> {
Observable<Chapter> chapter = Observable.just(item); Observable<Chapter> chapter = Observable.just(item);
switch (menuItem.getItemId()) { 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: case R.id.action_download:
return adapter.getFragment().onDownload(chapter); return adapter.getFragment().onDownload(chapter);
case R.id.action_delete: case R.id.action_delete:
return adapter.getFragment().onDelete(chapter); 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: case R.id.action_mark_previous_as_read:
return adapter.getFragment().onMarkPreviousAsRead(item); return adapter.getFragment().onMarkPreviousAsRead(item);
} }

View File

@ -6,11 +6,13 @@
<item android:id="@+id/action_download" <item android:id="@+id/action_download"
android:title="@string/action_download" android:title="@string/action_download"
android:icon="@drawable/ic_file_download" android:icon="@drawable/ic_file_download"
android:visible="true"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item android:id="@+id/action_delete" <item android:id="@+id/action_delete"
android:title="@string/action_delete" android:title="@string/action_delete"
android:icon="@drawable/ic_action_delete" android:icon="@drawable/ic_action_delete"
android:visible="false"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item android:id="@+id/action_mark_as_read" <item android:id="@+id/action_mark_as_read"
@ -23,8 +25,7 @@
android:icon="@drawable/ic_action_undone_all" android:icon="@drawable/ic_action_undone_all"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item <item android:id="@+id/action_mark_previous_as_read"
android:id="@+id/action_mark_previous_as_read"
android:title="@string/action_mark_previous_as_read"/> android:title="@string/action_mark_previous_as_read"/>
</menu> </menu>