Drop SelectItemWithIconAdapter

This commit is contained in:
tarsin committed 2023-05-31 00:46:52 +08:00
1 parent f542c8a12e
commit 886ce38543
14 files changed
+48 -208

No files matched your search

@@ -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;
}
}
@@ -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<CharSequence>(
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<CharSequence>(
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,
@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="@string/pd_heart_broken" />
</vector>
@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2014 The Android Open Source Project
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.
-->
<!--
This layout file is used by the AlertDialog when displaying a list of items.
This layout file is inflated and used as the TextView to display individual
items.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/keyline_margin"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?attr/listPreferredItemHeightSmall"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:textColor="?attr/textColorAlertDialogListItem" />
-1
View File
@@ -356,7 +356,6 @@
<string name="settings_about">Über die App</string>
<string name="settings_about_author">Entwickler</string>
<string name="settings_about_latest_release">Aktuelle Version</string>
<string name="settings_advanced_built_in_hosts_summary">Host auf die IP, die nach die App festgelegt werden, umstellen\nKann von angepasstem hosts.txt überschrieben werden</string>
<string name="download_reset_reading_progress">Lesefortschritte zurücksetzen</string>
<string name="reset_reading_progress_message">Lesefortschritte aus allen heruntergeladenen Galerie zurücksetzen?</string>
<string name="settings_eh_identity_cookies_signed">Wenn jemand die folgenden Informationen hat, kann er sich als du anmelden. &lt;br&gt;&lt;b&gt;ALSO GEHEIM HALTEN!&lt;/b&gt;&lt;br&gt;&lt;br&gt;%s</string>
-1
View File
@@ -466,7 +466,6 @@
<string name="settings_advanced_proxy">Serveur proxy</string>
<string name="settings_advanced_proxy_summary_1">%1$s %2$s:%3$d</string>
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_built_in_hosts_summary">Mapper l\'hôte à l\'adresse IP selon les règles de l\'app\nIls pouvent être redéfinits par hosts.txt personnalisé</string>
<string name="app_language_system">Langue du système (défaut)</string>
<string name="settings_eh_identity_cookies_signed">Tout le monde peut utiliser les cookies de ce compte pour s\'y connecter.&lt;br&gt;&lt;b&gt;GARDEZ-LES BIEN !&lt;/b&gt;&lt;br&gt;&lt;br&gt;%s</string>
<string name="settings_eh_identity_cookies_tourist">Vous ne vous êtes pas connecté.</string>
-1
View File
@@ -464,7 +464,6 @@
<string name="settings_advanced_built_in_hosts_title">既定hosts.txt</string>
<string name="app_language_system">システム言語(既定)</string>
<string name="download_service">ダウンロードサービス</string>
<string name="settings_advanced_built_in_hosts_summary">ホストをアプリ既定のIPにマッピング\nカスタムhosts.txtに上書きされます。</string>
<string name="settings_eh_identity_cookies_signed">下記の情報を持つ誰でもこのアカウントにログインできますので&lt;br&gt;&lt;b&gt;絶対に他人に渡さないように!&lt;/b&gt;&lt;br&gt;&lt;br&gt;%s</string>
<string name="settings_eh_identity_cookies_tourist">まだログインしていません</string>
-1
View File
@@ -343,7 +343,6 @@
<string name="settings_advanced_proxy_summary_1">%1$s %2$s:%3$d</string>
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_built_in_hosts_title">앱 내장 hosts.txt</string>
<string name="settings_advanced_built_in_hosts_summary">앱에 내장된 호스트-IP 지정 규칙을 사용합니다.\n대신 사용자 지정 hosts.txt 파일을 사용할 수도 있습니다.</string>
<string name="settings_advanced_export_data">데이터 내보내기</string>
<string name="settings_advanced_export_data_summary">다운로드 목록, 빠른 검색 목록 등의 데이터를 외부 저장소에 저장</string>
<string name="settings_advanced_export_data_to">%s 경로에 데이터를 내보냈습니다.</string>
-1
View File
@@ -358,7 +358,6 @@
<string name="settings_advanced_proxy_summary_1">%1$s %2$s:%3$d</string>
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_built_in_hosts_title">ใช้ hosts.txt ของตัวแอป</string>
<string name="settings_advanced_built_in_hosts_summary">ใช้ host-to-IP mapping แบบภายในที่จัดทำโดยตัวแอปเอง\nมันอาจจะเกิดการทับซ้อนกันจากการปรับแต่งไฟล์ hosts.txt เอง</string>
<string name="settings_advanced_export_data">สำเนาข้อมูล</string>
<string name="settings_advanced_export_data_summary">บันทึกข้อมูลต่างๆเช่นรายการดาวน์โหลด และค้นหาอย่างด่วนลงพื้นที่จัดเก็บภายนอก</string>
<string name="settings_advanced_export_data_to">ได้สำเนาข้อมูลแล้วจัดเก็บที่ %s</string>
@@ -379,7 +379,6 @@
<string name="settings_advanced_proxy_summary_1">%1$s %2$s:%3$d</string>
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_built_in_hosts_title">内置 hosts.txt</string>
<string name="settings_advanced_built_in_hosts_summary">应用提供的主机到IP的映射\n可被自定义 hosts.txt 覆盖</string>
<string name="settings_advanced_domain_fronting_title">域名前置(重启应用后生效)</string>
<string name="settings_advanced_domain_fronting_summary">绕过 SNI 封锁\n启用时会禁用代理设置</string>
<string name="settings_advanced_bypass_vpn_title">绕过VPN</string>
@@ -397,7 +397,6 @@
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_app_language_title">App 界面語言</string>
<string name="settings_advanced_built_in_hosts_title">內置 hosts.txt</string>
<string name="settings_advanced_built_in_hosts_summary">應用提供的主機到IP的映射\n可被自定義 hosts.txt 覆蓋</string>
<string name="settings_advanced_export_data">導出數據</string>
<string name="settings_advanced_export_data_summary">保存數據至外置存儲器,例如下載列表,快速搜索列表</string>
<string name="settings_advanced_export_data_to">已導出數據至 %s</string>
@@ -379,7 +379,6 @@
<string name="settings_advanced_proxy_summary_1">%1$s %2$s:%3$d</string>
<string name="settings_advanced_proxy_summary_2">%1$s</string>
<string name="settings_advanced_built_in_hosts_title">內建 hosts.txt</string>
<string name="settings_advanced_built_in_hosts_summary">應用程式提供的主機到 IP 的對映\n可覆蓋自訂 hosts.txt</string>
<string name="settings_advanced_domain_fronting_title">域名前綴</string>
<string name="settings_advanced_domain_fronting_summary">繞過 SNI 封鎖</string>
<string name="settings_advanced_bypass_vpn_title">繞過 VPN</string>
-1
View File
@@ -27,7 +27,6 @@
<string name="pd_homepage" translatable="false">M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z</string>
<string name="pd_fire" translatable="false">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</string>
<string name="pd_heart" translatable="false">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</string>
<string name="pd_heart_broken" translatable="false">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</string>
<string name="pd_history" translatable="false">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</string>
<string name="pd_book_open" translatable="false">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</string>
<string name="pd_delete" translatable="false">M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z</string>
-1
View File
@@ -425,7 +425,6 @@
<string name="settings_advanced_built_in_hosts_title">Built-in hosts.txt</string>
<string name="settings_advanced_dns_over_http_title">DNS Over HTTPS</string>
<string name="settings_advanced_dns_over_http_hint">Server URL, blank: disable</string>
<string name="settings_advanced_built_in_hosts_summary">Apply the built-in host-to-IP mapping provided by the app.\nIt can be overridden by custom hosts.txt.</string>
<string name="settings_advanced_domain_fronting_title">Domain fronting</string>
<string name="settings_advanced_domain_fronting_summary">Bypass SNI blocking.</string>
<string name="settings_advanced_bypass_vpn_title">Bypass VPN</string>