Search in sources :

Example 1 with SelectItemWithIconAdapter

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;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) EhException(com.hippo.ehviewer.client.exception.EhException) ContentLayout(com.hippo.widget.ContentLayout) Bundle(android.os.Bundle) AnimationUtils(com.hippo.yorozuya.AnimationUtils) NonNull(androidx.annotation.NonNull) SearchBar(com.hippo.ehviewer.widget.SearchBar) Spannable(android.text.Spannable) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) SelectItemWithIconAdapter(com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter) ColorDrawable(android.graphics.drawable.ColorDrawable) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) ViewConfiguration(android.view.ViewConfiguration) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder) AddDeleteDrawable(com.hippo.drawable.AddDeleteDrawable) DrawerLayout(com.hippo.drawerlayout.DrawerLayout) Display(android.view.Display) View(android.view.View) RefreshLayout(com.hippo.refreshlayout.RefreshLayout) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) AssertUtils(com.hippo.yorozuya.AssertUtils) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) QuickSearch(com.hippo.ehviewer.dao.QuickSearch) GalleryDetailUrlParser(com.hippo.ehviewer.client.parser.GalleryDetailUrlParser) FastScroller(com.hippo.easyrecyclerview.FastScroller) InputType(android.text.InputType) ViewGroup(android.view.ViewGroup) Ripple(com.hippo.ripple.Ripple) MathUtils(com.hippo.yorozuya.MathUtils) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) GalleryPageUrlParser(com.hippo.ehviewer.client.parser.GalleryPageUrlParser) EhClient(com.hippo.ehviewer.client.EhClient) Toolbar(androidx.appcompat.widget.Toolbar) ListView(android.widget.ListView) EhApplication(com.hippo.ehviewer.EhApplication) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) EhRequest(com.hippo.ehviewer.client.EhRequest) DrawableManager(com.hippo.util.DrawableManager) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) ImageSpan(android.text.style.ImageSpan) Intent(android.content.Intent) IntDef(androidx.annotation.IntDef) SimpleShowcaseEventListener(com.github.amlcurran.showcaseview.SimpleShowcaseEventListener) MenuItem(android.view.MenuItem) MainActivity(com.hippo.ehviewer.ui.MainActivity) FabLayout(com.hippo.widget.FabLayout) Retention(java.lang.annotation.Retention) FavouriteStatusRouter(com.hippo.ehviewer.FavouriteStatusRouter) SceneFragment(com.hippo.scene.SceneFragment) ViewTransition(com.hippo.view.ViewTransition) SpannableStringBuilder(android.text.SpannableStringBuilder) SearchBarMover(com.hippo.widget.SearchBarMover) ViewUtils(com.hippo.yorozuya.ViewUtils) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener) DrawerArrowDrawable(com.hippo.drawable.DrawerArrowDrawable) DialogInterface(android.content.DialogInterface) GalleryInfoContentHelper(com.hippo.ehviewer.widget.GalleryInfoContentHelper) SearchLayout(com.hippo.ehviewer.widget.SearchLayout) LayoutInflater(android.view.LayoutInflater) DownloadManager(com.hippo.ehviewer.download.DownloadManager) StringUtils(com.hippo.yorozuya.StringUtils) PointTarget(com.github.amlcurran.showcaseview.targets.PointTarget) EhDB(com.hippo.ehviewer.EhDB) Point(android.graphics.Point) TextUtils(android.text.TextUtils) EhUtils(com.hippo.ehviewer.client.EhUtils) CommonOperations(com.hippo.ehviewer.ui.CommonOperations) AppHelper(com.hippo.util.AppHelper) File(java.io.File) R(com.hippo.ehviewer.R) Color(android.graphics.Color) Gravity(android.view.Gravity) ArrayAdapter(android.widget.ArrayAdapter) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) GalleryListParser(com.hippo.ehviewer.client.parser.GalleryListParser) Settings(com.hippo.ehviewer.Settings) AttrResources(com.hippo.android.resource.AttrResources) EhUrl(com.hippo.ehviewer.client.EhUrl) Announcer(com.hippo.scene.Announcer) Activity(android.app.Activity) Collections(java.util.Collections) Resources(android.content.res.Resources) RetentionPolicy(java.lang.annotation.RetentionPolicy) SelectItemWithIconAdapter(com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) Intent(android.content.Intent) MainActivity(com.hippo.ehviewer.ui.MainActivity) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity)

Aggregations

Animator (android.animation.Animator)1 Activity (android.app.Activity)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Color (android.graphics.Color)1 Point (android.graphics.Point)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 InputType (android.text.InputType)1 Spannable (android.text.Spannable)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextUtils (android.text.TextUtils)1 ImageSpan (android.text.style.ImageSpan)1 Display (android.view.Display)1 Gravity (android.view.Gravity)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1