From 7a47b2504d905cdb88d592bd8aa247ab3a359ab6 Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 20 Jun 2019 18:21:52 +0800 Subject: [PATCH] Show icon in selection dialogs --- .../ui/dialog/SelectItemWithIconAdapter.java | 78 +++++++++++++++++++ .../ehviewer/ui/scene/GalleryListScene.java | 19 +++-- app/src/main/res/drawable/v_download_x24.xml | 29 +++++++ .../main/res/drawable/v_heart_broken_x24.xml | 29 +++++++ app/src/main/res/drawable/v_heart_x24.xml | 29 +++++++ .../layout/dialog_item_select_with_icon.xml | 34 ++++++++ app/src/main/res/values/pathdata.xml | 1 + 7 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/ui/dialog/SelectItemWithIconAdapter.java create mode 100644 app/src/main/res/drawable/v_download_x24.xml create mode 100644 app/src/main/res/drawable/v_heart_broken_x24.xml create mode 100644 app/src/main/res/drawable/v_heart_x24.xml create mode 100644 app/src/main/res/layout/dialog_item_select_with_icon.xml diff --git a/app/src/main/java/com/hippo/ehviewer/ui/dialog/SelectItemWithIconAdapter.java b/app/src/main/java/com/hippo/ehviewer/ui/dialog/SelectItemWithIconAdapter.java new file mode 100644 index 000000000..124380cb2 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/ui/dialog/SelectItemWithIconAdapter.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.ui.dialog; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; +import androidx.appcompat.content.res.AppCompatResources; +import com.hippo.ehviewer.R; + +public class SelectItemWithIconAdapter extends BaseAdapter { + + private Context context; + private LayoutInflater inflater; + + private CharSequence[] texts; + private int[] icons; + + public SelectItemWithIconAdapter(Context context, CharSequence[] texts, int[] icons) { + int count = texts.length; + if (count != icons.length) { + throw new IllegalArgumentException("Length conflict"); + } + this.context = context; + this.inflater = LayoutInflater.from(context); + this.texts = texts; + this.icons = icons; + } + + @Override + public int getCount() { + return texts.length; + } + + @Override + public Object getItem(int position) { + return texts[position]; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = inflater.inflate(R.layout.dialog_item_select_with_icon, parent, false); + } + TextView view = (TextView) convertView; + + view.setText(texts[position]); + + Drawable icon = AppCompatResources.getDrawable(context, icons[position]); + icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); + view.setCompoundDrawables(icon, null, null, null); + + return view; + } +} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 5458fed21..7b1ebd23b 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -82,6 +82,7 @@ import com.hippo.ehviewer.download.DownloadManager; import com.hippo.ehviewer.ui.CommonOperations; import com.hippo.ehviewer.ui.GalleryActivity; import com.hippo.ehviewer.ui.MainActivity; +import com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter; import com.hippo.ehviewer.widget.GalleryInfoContentHelper; import com.hippo.ehviewer.widget.SearchBar; import com.hippo.ehviewer.widget.SearchLayout; @@ -1062,17 +1063,23 @@ public final class GalleryListScene extends BaseScene } boolean downloaded = mDownloadManager.getDownloadState(gi.gid) != DownloadInfo.STATE_INVALID; - boolean favourite = gi.favoriteSlot == -2; + 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(favourite ? R.string.add_to_favourites : R.string.remove_from_favourites), + 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)) - .setItems(items, (dialog, which) -> { + .setAdapter(new SelectItemWithIconAdapter(context, items, icons), (dialog, which) -> { switch (which) { case 0: // Read Intent intent = new Intent(activity, GalleryActivity.class); @@ -1088,10 +1095,10 @@ public final class GalleryListScene extends BaseScene } break; case 2: // Favorites - if (favourite) { - CommonOperations.addToFavorites(activity, gi, new AddToFavoriteListener(context, activity.getStageId(), getTag())); - } else { + if (favourited) { CommonOperations.removeFromFavorites(activity, gi, new RemoveFromFavoriteListener(context, activity.getStageId(), getTag())); + } else { + CommonOperations.addToFavorites(activity, gi, new AddToFavoriteListener(context, activity.getStageId(), getTag())); } break; } diff --git a/app/src/main/res/drawable/v_download_x24.xml b/app/src/main/res/drawable/v_download_x24.xml new file mode 100644 index 000000000..94353a77e --- /dev/null +++ b/app/src/main/res/drawable/v_download_x24.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/v_heart_broken_x24.xml b/app/src/main/res/drawable/v_heart_broken_x24.xml new file mode 100644 index 000000000..d11f24f42 --- /dev/null +++ b/app/src/main/res/drawable/v_heart_broken_x24.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/v_heart_x24.xml b/app/src/main/res/drawable/v_heart_x24.xml new file mode 100644 index 000000000..bc4c9cddc --- /dev/null +++ b/app/src/main/res/drawable/v_heart_x24.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/layout/dialog_item_select_with_icon.xml b/app/src/main/res/layout/dialog_item_select_with_icon.xml new file mode 100644 index 000000000..46f23f217 --- /dev/null +++ b/app/src/main/res/layout/dialog_item_select_with_icon.xml @@ -0,0 +1,34 @@ + + + + + diff --git a/app/src/main/res/values/pathdata.xml b/app/src/main/res/values/pathdata.xml index 7462fc164..5da0352b9 100644 --- a/app/src/main/res/values/pathdata.xml +++ b/app/src/main/res/values/pathdata.xml @@ -29,6 +29,7 @@ M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z M11.71,19C9.93,19 8.5,17.59 8.5,15.86C8.5,14.24 9.53,13.1 11.3,12.74C13.07,12.38 14.9,11.53 15.92,10.16C16.31,11.45 16.5,12.81 16.5,14.2C16.5,16.84 14.36,19 11.71,19M13.5,0.67C13.5,0.67 14.24,3.32 14.24,5.47C14.24,7.53 12.89,9.2 10.83,9.2C8.76,9.2 7.2,7.53 7.2,5.47L7.23,5.1C5.21,7.5 4,10.61 4,14A8,8 0 0,0 12,22A8,8 0 0,0 20,14C20,8.6 17.41,3.8 13.5,0.67Z M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z + M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C8.17,3 8.82,3.12 9.44,3.33L13,9.35L9,14.35L12,21.35V21.35M16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35L11,14.35L15.5,9.35L12.85,4.27C13.87,3.47 15.17,3 16.5,3Z M11,7V12.11L15.71,14.9L16.5,13.62L12.5,11.25V7M12.5,2C8.97,2 5.91,3.92 4.27,6.77L2,4.5V11H8.5L5.75,8.25C6.96,5.73 9.5,4 12.5,4A7.5,7.5 0 0,1 20,11.5A7.5,7.5 0 0,1 12.5,19C9.23,19 6.47,16.91 5.44,14H3.34C4.44,18.03 8.11,21 12.5,21C17.74,21 22,16.75 22,11.5A9.5,9.5 0 0,0 12.5,2Z M21,4C19.9,3.7,18.7,3.5,17.5,3.5C15.6,3.5,13.4,3.9,12,5C10.6,3.9,8.4,3.5,6.5,3.5S2.5,3.9,1,5V19.6C1,19.9,1.3,20.1,1.5,20.1C1.6,20.1,1.6,20.1,1.8,20.1C3.1,19.5,5.1,19,6.5,19C8.4,19,10.6,19.4,12,20.5C13.4,19.6,15.8,19,17.5,19C19.1,19,20.9,19.3,22.3,20C22.4,20.1,22.4,20.1,22.6,20.1C22.9,20.1,23.1,19.8,23.1,19.6V5C22.4,4.6,21.8,4.3,21,4M21,17.5C19.9,17.1,18.7,17,17.5,17C15.8,17,13.4,17.6,12,18.5V7C13.4,6.2,15.8,5.5,17.5,5.5C18.7,5.5,19.9,5.7,21,6V17.5Z M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z