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 deleted file mode 100644 index 82d5b3125..000000000 --- a/app/src/main/java/com/hippo/ehviewer/ui/dialog/SelectItemWithIconAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 final Context context; - private final LayoutInflater inflater; - - private final CharSequence[] texts; - private final 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.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt index 2beddcbf9..45b1f8c30 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt @@ -35,6 +35,14 @@ import android.view.ViewPropertyAnimator import android.widget.TextView import androidx.activity.OnBackPressedCallback import androidx.annotation.IntDef +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.Download +import androidx.compose.material.icons.filled.DriveFileMove +import androidx.compose.material.icons.filled.Favorite +import androidx.compose.material.icons.filled.HeartBroken +import androidx.compose.material.icons.filled.MenuBook +import androidx.compose.ui.platform.ComposeView import androidx.core.content.ContextCompat import androidx.core.view.GravityCompat import androidx.core.view.ViewCompat @@ -80,8 +88,10 @@ import com.hippo.ehviewer.databinding.SceneGalleryListBinding import com.hippo.ehviewer.download.DownloadManager import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener import com.hippo.ehviewer.ui.CommonOperations +import com.hippo.ehviewer.ui.MainActivity import com.hippo.ehviewer.ui.addToFavorites -import com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter +import com.hippo.ehviewer.ui.compose.DialogState +import com.hippo.ehviewer.ui.compose.setMD3Content import com.hippo.ehviewer.ui.legacy.AddDeleteDrawable import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder import com.hippo.ehviewer.ui.legacy.BringOutTransition @@ -338,12 +348,15 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H setSearchBarHint(title) } + private val dialogState = DialogState() + override fun onCreateViewWithToolbar( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View { _binding = SceneGalleryListBinding.inflate(inflater, container, false) + binding.root.addView(ComposeView(inflater.context).apply { setMD3Content { dialogState.Handler() } }) requireActivity().onBackPressedDispatcher.addCallback(mCallback) mHideActionFabSlop = ViewConfiguration.get(requireContext()).scaledTouchSlop mShowActionFab = true @@ -369,7 +382,6 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H binding.contentLayout.fastScroller.setOnDragHandlerListener(this) binding.contentLayout.setFitPaddingTop(paddingTopSB) mAdapter = GalleryListAdapter( - inflater, resources, binding.contentLayout.recyclerView, Settings.listMode, @@ -712,56 +724,34 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H } fun onItemLongClick(position: Int): Boolean { - val context = context - val activity = mainActivity - if (null == context || null == activity || null == mHelper) { - return false - } - val gi = mHelper!!.getDataAtEx(position) ?: return true - val downloaded = mDownloadManager.getDownloadState(gi.gid) != DownloadInfo.STATE_INVALID - val favourited = gi.favoriteSlot != -2 - val items = if (downloaded) { - arrayOf( - context.getString(R.string.read), - context.getString(R.string.delete_downloads), - context.getString(if (favourited) R.string.remove_from_favourites else R.string.add_to_favourites), - context.getString(R.string.download_move_dialog_title), - ) - } else { - arrayOf( - context.getString(R.string.read), - context.getString(R.string.download), - context.getString(if (favourited) R.string.remove_from_favourites else R.string.add_to_favourites), - ) - } - val icons = if (downloaded) { - intArrayOf( - R.drawable.v_book_open_x24, - R.drawable.v_delete_x24, - if (favourited) R.drawable.v_heart_broken_x24 else R.drawable.v_heart_x24, - R.drawable.v_folder_move_x24, - ) - } else { - intArrayOf( - R.drawable.v_book_open_x24, - R.drawable.v_download_x24, - if (favourited) R.drawable.v_heart_broken_x24 else R.drawable.v_heart_x24, - ) - } - BaseDialogBuilder(context) - .setTitle(EhUtils.getSuitableTitle(gi)) - .setAdapter( - SelectItemWithIconAdapter( - context, - items, - icons, - ), - ) { _: DialogInterface?, which: Int -> - when (which) { + val context = context ?: return true + val info = mHelper?.getDataAtEx(position) ?: return true + lifecycleScope.launchIO { + val downloaded = DownloadManager.getDownloadState(info.gid) != DownloadInfo.STATE_INVALID + val favourite = info.favoriteSlot != -2 + val selected: Int + if (!downloaded) { + selected = dialogState.showSelectItemWithIcon( + Icons.Default.MenuBook to R.string.read, + Icons.Default.Download to R.string.download, + if (!favourite) Icons.Default.Favorite to R.string.add_to_favourites else Icons.Default.HeartBroken to R.string.remove_from_favourites, + title = EhUtils.getSuitableTitle(info), + ) + } else { + selected = dialogState.showSelectItemWithIcon( + Icons.Default.MenuBook to R.string.read, + Icons.Default.Delete to R.string.delete_downloads, + if (!favourite) Icons.Default.Favorite to R.string.add_to_favourites else Icons.Default.HeartBroken to R.string.remove_from_favourites, + Icons.Default.DriveFileMove to R.string.download_move_dialog_title, + title = EhUtils.getSuitableTitle(info), + ) + } + withUIContext { + when (selected) { 0 -> { val intent = Intent(activity, ReaderActivity::class.java) intent.action = ReaderActivity.ACTION_EH - intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, gi) + intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, info) startActivity(intent) } @@ -771,23 +761,23 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H .setMessage( getString( R.string.download_remove_dialog_message, - gi.title, + info.title, ), ) .setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int -> mDownloadManager.deleteDownload( - gi.gid, + info.gid, ) } .show() } else { - CommonOperations.startDownload(activity, gi, false) + CommonOperations.startDownload(activity as MainActivity, info, false) } - 2 -> if (favourited) { + 2 -> if (favourite) { lifecycleScope.launchIO { runSuspendCatching { - removeFromFavorites(gi) + removeFromFavorites(info) showTip(R.string.remove_from_favorite_success, LENGTH_SHORT) }.onFailure { showTip(R.string.remove_from_favorite_failure, LENGTH_LONG) @@ -796,7 +786,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H } else { lifecycleScope.launchIO { runSuspendCatching { - requireContext().addToFavorites(gi) + context.addToFavorites(info) showTip(R.string.add_to_favorite_success, LENGTH_SHORT) }.onFailure { showTip(R.string.add_to_favorite_failure, LENGTH_LONG) @@ -815,14 +805,15 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H i++ } val labels = labelList.toTypedArray() - val helper = MoveDialogHelper(labels, gi) + val helper = MoveDialogHelper(labels, info) BaseDialogBuilder(context) .setTitle(R.string.download_move_dialog_title) .setItems(labels, helper) .show() } } - }.show() + } + } return true } @@ -1237,7 +1228,6 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H } private inner class GalleryListAdapter( - inflater: LayoutInflater, resources: Resources, recyclerView: RecyclerView, type: Int, diff --git a/app/src/main/res/drawable/v_heart_broken_x24.xml b/app/src/main/res/drawable/v_heart_broken_x24.xml deleted file mode 100644 index af280e3d0..000000000 --- a/app/src/main/res/drawable/v_heart_broken_x24.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - 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 deleted file mode 100644 index acd9ce577..000000000 --- a/app/src/main/res/layout/dialog_item_select_with_icon.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 871d88bbf..6f4350be1 100755 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -356,7 +356,6 @@ Über die App Entwickler Aktuelle Version - Host auf die IP, die nach die App festgelegt werden, umstellen\nKann von angepasstem hosts.txt überschrieben werden Lesefortschritte zurücksetzen Lesefortschritte aus allen heruntergeladenen Galerie zurücksetzen? Wenn jemand die folgenden Informationen hat, kann er sich als du anmelden. <br><b>ALSO GEHEIM HALTEN!</b><br><br>%s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index b5027a6a7..02fad83be 100755 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -466,7 +466,6 @@ Serveur proxy %1$s %2$s:%3$d %1$s - Mapper l\'hôte à l\'adresse IP selon les règles de l\'app\nIls pouvent être redéfinits par hosts.txt personnalisé Langue du système (défaut) Tout le monde peut utiliser les cookies de ce compte pour s\'y connecter.<br><b>GARDEZ-LES BIEN !</b><br><br>%s Vous ne vous êtes pas connecté. diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1ba8aa2c6..1d5dbd401 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -464,7 +464,6 @@ 既定hosts.txt システム言語(既定) ダウンロードサービス - ホストをアプリ既定のIPにマッピング\nカスタムhosts.txtに上書きされます。 下記の情報を持つ誰でもこのアカウントにログインできますので<br><b>絶対に他人に渡さないように!</b><br><br>%s まだログインしていません diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index a2f1be6da..1586240c8 100755 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -343,7 +343,6 @@ %1$s %2$s:%3$d %1$s 앱 내장 hosts.txt - 앱에 내장된 호스트-IP 지정 규칙을 사용합니다.\n대신 사용자 지정 hosts.txt 파일을 사용할 수도 있습니다. 데이터 내보내기 다운로드 목록, 빠른 검색 목록 등의 데이터를 외부 저장소에 저장 %s 경로에 데이터를 내보냈습니다. diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 81f6895f8..96f9f94d2 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -358,7 +358,6 @@ %1$s %2$s:%3$d %1$s ใช้ hosts.txt ของตัวแอป - ใช้ host-to-IP mapping แบบภายในที่จัดทำโดยตัวแอปเอง\nมันอาจจะเกิดการทับซ้อนกันจากการปรับแต่งไฟล์ hosts.txt เอง สำเนาข้อมูล บันทึกข้อมูลต่างๆเช่นรายการดาวน์โหลด และค้นหาอย่างด่วนลงพื้นที่จัดเก็บภายนอก ได้สำเนาข้อมูลแล้วจัดเก็บที่ %s diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a1ef5e85e..8762ef063 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -379,7 +379,6 @@ %1$s %2$s:%3$d %1$s 内置 hosts.txt - 应用提供的主机到IP的映射\n可被自定义 hosts.txt 覆盖 域名前置(重启应用后生效) 绕过 SNI 封锁\n启用时会禁用代理设置 绕过VPN diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 56dc3bd29..c436d92b8 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -397,7 +397,6 @@ %1$s App 界面語言 內置 hosts.txt - 應用提供的主機到IP的映射\n可被自定義 hosts.txt 覆蓋 導出數據 保存數據至外置存儲器,例如下載列表,快速搜索列表 已導出數據至 %s diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c7175f4f7..7eb239674 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -379,7 +379,6 @@ %1$s %2$s:%3$d %1$s 內建 hosts.txt - 應用程式提供的主機到 IP 的對映\n可覆蓋自訂 hosts.txt 域名前綴 繞過 SNI 封鎖 繞過 VPN diff --git a/app/src/main/res/values/pathdata.xml b/app/src/main/res/values/pathdata.xml index fc30ee11f..a2da4c491 100644 --- a/app/src/main/res/values/pathdata.xml +++ b/app/src/main/res/values/pathdata.xml @@ -27,7 +27,6 @@ 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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17469314c..532481c02 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -425,7 +425,6 @@ Built-in hosts.txt DNS Over HTTPS Server URL, blank: disable - Apply the built-in host-to-IP mapping provided by the app.\nIt can be overridden by custom hosts.txt. Domain fronting Bypass SNI blocking. Bypass VPN