mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:59:18 +01:00
Simplify chapter's popup logic
This commit is contained in:
parent
04a61edb38
commit
0f5cf6a748
@ -48,7 +48,7 @@ public class ChaptersAdapter extends FlexibleAdapter<ChaptersHolder, Chapter> {
|
|||||||
void onListItemLongClick(int position);
|
void onListItemLongClick(int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChaptersFragment getMangaChaptersFragment() {
|
public ChaptersFragment getChaptersFragment() {
|
||||||
return (ChaptersFragment) fragment;
|
return (ChaptersFragment) fragment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import android.support.v4.content.ContextCompat;
|
|||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.view.ActionMode;
|
import android.support.v7.view.ActionMode;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.PopupMenu;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -24,11 +23,11 @@ import butterknife.ButterKnife;
|
|||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.database.models.Chapter;
|
import eu.kanade.mangafeed.data.database.models.Chapter;
|
||||||
import eu.kanade.mangafeed.data.download.DownloadService;
|
import eu.kanade.mangafeed.data.download.DownloadService;
|
||||||
|
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
||||||
|
import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment;
|
||||||
import eu.kanade.mangafeed.ui.decoration.DividerItemDecoration;
|
import eu.kanade.mangafeed.ui.decoration.DividerItemDecoration;
|
||||||
import eu.kanade.mangafeed.ui.manga.MangaActivity;
|
import eu.kanade.mangafeed.ui.manga.MangaActivity;
|
||||||
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||||
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
|
||||||
import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment;
|
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
@ -149,23 +148,15 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_select_all:
|
case R.id.action_select_all:
|
||||||
adapter.selectAll();
|
return onSelectAll();
|
||||||
return true;
|
|
||||||
case R.id.action_mark_as_read:
|
case R.id.action_mark_as_read:
|
||||||
getPresenter().markChaptersRead(getSelectedChapters(), true);
|
return onMarkAsRead(getSelectedChapters());
|
||||||
return true;
|
|
||||||
case R.id.action_mark_as_unread:
|
case R.id.action_mark_as_unread:
|
||||||
getPresenter().markChaptersRead(getSelectedChapters(), false);
|
return onMarkAsUnread(getSelectedChapters());
|
||||||
return true;
|
|
||||||
case R.id.action_download:
|
case R.id.action_download:
|
||||||
DownloadService.start(getActivity());
|
return onDownload(getSelectedChapters());
|
||||||
getPresenter().downloadChapters(getSelectedChapters());
|
|
||||||
closeActionMode();
|
|
||||||
return true;
|
|
||||||
case R.id.action_delete:
|
case R.id.action_delete:
|
||||||
getPresenter().deleteChapters(getSelectedChapters());
|
return onDelete(getSelectedChapters());
|
||||||
closeActionMode();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -187,6 +178,36 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean onSelectAll() {
|
||||||
|
adapter.selectAll();
|
||||||
|
setContextTitle(adapter.getSelectedItemCount());
|
||||||
|
actionMode.invalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onMarkAsRead(Observable<Chapter> chapters) {
|
||||||
|
getPresenter().markChaptersRead(chapters, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onMarkAsUnread(Observable<Chapter> chapters) {
|
||||||
|
getPresenter().markChaptersRead(chapters, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onDownload(Observable<Chapter> chapters) {
|
||||||
|
DownloadService.start(getActivity());
|
||||||
|
getPresenter().downloadChapters(chapters);
|
||||||
|
closeActionMode();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onDelete(Observable<Chapter> chapters) {
|
||||||
|
getPresenter().deleteChapters(chapters);
|
||||||
|
closeActionMode();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onListItemClick(int position) {
|
public boolean onListItemClick(int position) {
|
||||||
if (actionMode != null && adapter.getMode() == ChaptersAdapter.MODE_MULTI) {
|
if (actionMode != null && adapter.getMode() == ChaptersAdapter.MODE_MULTI) {
|
||||||
|
@ -2,11 +2,9 @@ package eu.kanade.mangafeed.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.support.v7.widget.PopupMenu;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.PopupMenu;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -17,7 +15,6 @@ import butterknife.Bind;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.database.models.Chapter;
|
import eu.kanade.mangafeed.data.database.models.Chapter;
|
||||||
import eu.kanade.mangafeed.data.download.DownloadService;
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
public class ChaptersHolder extends RecyclerView.ViewHolder implements
|
public class ChaptersHolder extends RecyclerView.ViewHolder implements
|
||||||
@ -58,14 +55,14 @@ public class ChaptersHolder extends RecyclerView.ViewHolder implements
|
|||||||
title.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
|
title.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapter.last_page_read > 0 && !chapter.read) {
|
if (!chapter.read && chapter.last_page_read > 0) {
|
||||||
pages.setText(context.getString(R.string.chapter_progress, chapter.last_page_read + 1));
|
pages.setText(context.getString(R.string.chapter_progress, chapter.last_page_read + 1));
|
||||||
} else {
|
} else {
|
||||||
pages.setText("");
|
pages.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapter.downloaded == Chapter.UNKNOWN) {
|
if (chapter.downloaded == Chapter.UNKNOWN) {
|
||||||
adapter.getMangaChaptersFragment().getPresenter().checkIsChapterDownloaded(chapter);
|
adapter.getChaptersFragment().getPresenter().checkIsChapterDownloaded(chapter);
|
||||||
}
|
}
|
||||||
if (chapter.downloaded == Chapter.DOWNLOADED) {
|
if (chapter.downloaded == Chapter.DOWNLOADED) {
|
||||||
downloadText.setVisibility(View.VISIBLE);
|
downloadText.setVisibility(View.VISIBLE);
|
||||||
@ -97,27 +94,24 @@ public class ChaptersHolder extends RecyclerView.ViewHolder implements
|
|||||||
|
|
||||||
private void showPopupMenu(View view) {
|
private void showPopupMenu(View view) {
|
||||||
// Create a PopupMenu, giving it the clicked view for an anchor
|
// Create a PopupMenu, giving it the clicked view for an anchor
|
||||||
PopupMenu popup = new PopupMenu(adapter.getMangaChaptersFragment().getActivity(), view);
|
PopupMenu popup = new PopupMenu(adapter.getChaptersFragment().getActivity(), view);
|
||||||
|
|
||||||
// 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());
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_mark_as_read:
|
case R.id.action_mark_as_read:
|
||||||
adapter.getMangaChaptersFragment().getPresenter().markChaptersRead(Observable.just(item), true);
|
return adapter.getChaptersFragment().onMarkAsRead(chapter);
|
||||||
return true;
|
|
||||||
case R.id.action_mark_as_unread:
|
case R.id.action_mark_as_unread:
|
||||||
adapter.getMangaChaptersFragment().getPresenter().markChaptersRead(Observable.just(item), false);
|
return adapter.getChaptersFragment().onMarkAsUnread(chapter);
|
||||||
return true;
|
|
||||||
case R.id.action_download:
|
case R.id.action_download:
|
||||||
DownloadService.start(adapter.getMangaChaptersFragment().getActivity());
|
return adapter.getChaptersFragment().onDownload(chapter);
|
||||||
adapter.getMangaChaptersFragment().getPresenter().downloadChapters(Observable.just(item));
|
|
||||||
return true;
|
|
||||||
case R.id.action_delete:
|
case R.id.action_delete:
|
||||||
adapter.getMangaChaptersFragment().getPresenter().deleteChapters(Observable.just(item));
|
return adapter.getChaptersFragment().onDelete(chapter);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user