use of com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter in project EhViewer by seven332.
the class GalleryListScene method onItemLongClick.
@Override
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
final Context context = getContext2();
final MainActivity activity = getActivity2();
if (null == context || null == activity || null == mHelper) {
return false;
}
final GalleryInfo gi = mHelper.getDataAtEx(position);
if (gi == null) {
return true;
}
boolean downloaded = mDownloadManager.getDownloadState(gi.gid) != DownloadInfo.STATE_INVALID;
boolean favourited = gi.favoriteSlot != -2;
CharSequence[] items = new CharSequence[] { context.getString(R.string.read), context.getString(downloaded ? R.string.delete_downloads : R.string.download), context.getString(favourited ? R.string.remove_from_favourites : R.string.add_to_favourites) };
int[] icons = new int[] { R.drawable.v_book_open_x24, downloaded ? R.drawable.v_delete_x24 : R.drawable.v_download_x24, favourited ? R.drawable.v_heart_broken_x24 : R.drawable.v_heart_x24 };
new AlertDialog.Builder(context).setTitle(EhUtils.getSuitableTitle(gi)).setAdapter(new SelectItemWithIconAdapter(context, items, icons), (dialog, which) -> {
switch(which) {
case // Read
0:
Intent intent = new Intent(activity, GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, gi);
startActivity(intent);
break;
case // Download
1:
if (downloaded) {
new AlertDialog.Builder(context).setTitle(R.string.download_remove_dialog_title).setMessage(getString(R.string.download_remove_dialog_message, gi.title)).setPositiveButton(android.R.string.ok, (dialog1, which1) -> mDownloadManager.deleteDownload(gi.gid)).show();
} else {
CommonOperations.startDownload(activity, gi, false);
}
break;
case // Favorites
2:
if (favourited) {
CommonOperations.removeFromFavorites(activity, gi, new RemoveFromFavoriteListener(context, activity.getStageId(), getTag()));
} else {
CommonOperations.addToFavorites(activity, gi, new AddToFavoriteListener(context, activity.getStageId(), getTag()));
}
break;
}
}).show();
return true;
}
Aggregations