From 59a9448d706b304b41519c93c3d3bcde93768b6f Mon Sep 17 00:00:00 2001
From: FooIbar <118464521+FooIbar@users.noreply.github.com>
Date: Fri, 4 Aug 2023 14:50:46 +0800
Subject: [PATCH] Restore default favorite slot
---
.../main/java/com/hippo/ehviewer/Settings.kt | 1 +
.../com/hippo/ehviewer/ui/CommonOperations.kt | 39 +++++++++++--------
.../hippo/ehviewer/ui/settings/EhScreen.kt | 24 ++++++++++++
app/src/main/res/values-de/strings.xml | 1 +
app/src/main/res/values-es/strings.xml | 1 +
app/src/main/res/values-fr/strings.xml | 1 +
app/src/main/res/values-ja/strings.xml | 1 +
app/src/main/res/values-ko/strings.xml | 1 +
app/src/main/res/values-th/strings.xml | 1 +
app/src/main/res/values-zh-rCN/strings.xml | 2 +
app/src/main/res/values-zh-rHK/strings.xml | 1 +
app/src/main/res/values-zh-rTW/strings.xml | 1 +
app/src/main/res/values/strings.xml | 2 +
13 files changed, 59 insertions(+), 17 deletions(-)
diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt
index 89349ab7d..eb0b57de4 100755
--- a/app/src/main/java/com/hippo/ehviewer/Settings.kt
+++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt
@@ -66,6 +66,7 @@ object Settings : DataStorePreferences(null) {
var bypassCloudflare by boolPref("bypass_cloudflare", false)
var thumbSizeDp by intPref("thumb_size_", 120)
var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_LOCAL)
+ var defaultFavSlot by intPref("default_favorite_slot", -2)
var securityDelay by intPref("require_unlock_delay", 0)
var clipboardTextHashCode by intPref("clipboard_text_hash_code", 0)
var listThumbSize by intPref("list_tile_size", 40)
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt
index 1ceb1dbc1..c33006506 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt
+++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt
@@ -202,34 +202,39 @@ fun getFavoriteIcon(favorited: Boolean) =
suspend fun DialogState.modifyFavorites(galleryInfo: BaseGalleryInfo): Boolean {
val localFavorited = EhDB.containLocalFavorites(galleryInfo.gid)
if (EhCookieStore.hasSignedIn()) {
- val localFav = getFavoriteIcon(localFavorited) to appCtx.getString(R.string.local_favorites)
- val cloudFav = Settings.favCat.mapIndexed { index, name ->
- getFavoriteIcon(galleryInfo.favoriteSlot == index) to name
- }.toTypedArray()
val isFavorited = galleryInfo.favoriteSlot != NOT_FAVORITED
- val items = if (isFavorited) {
- val remove = Icons.Default.HeartBroken to appCtx.getString(R.string.remove_from_favourites)
- arrayOf(remove, localFav, *cloudFav)
+ val defaultFavSlot = Settings.defaultFavSlot
+ if (defaultFavSlot == -2) {
+ val localFav = getFavoriteIcon(localFavorited) to appCtx.getString(R.string.local_favorites)
+ val cloudFav = Settings.favCat.mapIndexed { index, name ->
+ getFavoriteIcon(galleryInfo.favoriteSlot == index) to name
+ }.toTypedArray()
+ val items = if (isFavorited) {
+ val remove = Icons.Default.HeartBroken to appCtx.getString(R.string.remove_from_favourites)
+ arrayOf(remove, localFav, *cloudFav)
+ } else {
+ arrayOf(localFav, *cloudFav)
+ }
+ val (slot, note) = showSelectItemWithIconAndTextField(
+ *items,
+ title = R.string.add_favorites_dialog_title,
+ hint = R.string.favorite_note,
+ maxChar = MAX_FAVNOTE_CHAR,
+ )
+ return doModifyFavorites(galleryInfo, if (isFavorited) slot - 2 else slot - 1, localFavorited, note)
} else {
- arrayOf(localFav, *cloudFav)
+ return doModifyFavorites(galleryInfo, if (isFavorited) NOT_FAVORITED else defaultFavSlot, localFavorited)
}
- val (slot, note) = showSelectItemWithIconAndTextField(
- *items,
- title = R.string.add_favorites_dialog_title,
- hint = R.string.favorite_note,
- maxChar = MAX_FAVNOTE_CHAR,
- )
- return doModifyFavorites(galleryInfo, if (isFavorited) slot - 2 else slot - 1, note, localFavorited)
} else {
- return doModifyFavorites(galleryInfo, LOCAL_FAVORITED, localFavorited = localFavorited)
+ return doModifyFavorites(galleryInfo, LOCAL_FAVORITED, localFavorited)
}
}
private suspend fun doModifyFavorites(
galleryInfo: BaseGalleryInfo,
slot: Int = NOT_FAVORITED,
- note: String = "",
localFavorited: Boolean = true,
+ note: String = "",
): Boolean {
val add = when (slot) {
NOT_FAVORITED -> { // Remove from cloud favorites first
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/settings/EhScreen.kt b/app/src/main/java/com/hippo/ehviewer/ui/settings/EhScreen.kt
index 580711fd3..d73a8cf5b 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/settings/EhScreen.kt
+++ b/app/src/main/java/com/hippo/ehviewer/ui/settings/EhScreen.kt
@@ -53,6 +53,7 @@ import com.hippo.ehviewer.ui.UCONFIG_SCREEN
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
import com.hippo.ehviewer.ui.tools.TimePickerDialog
import com.hippo.ehviewer.ui.tools.observed
+import com.hippo.ehviewer.ui.tools.rememberDialogState
import com.hippo.ehviewer.ui.tools.rememberedAccessor
import com.hippo.ehviewer.util.whisperClipboard
import eu.kanade.tachiyomi.util.lang.withUIContext
@@ -71,6 +72,8 @@ fun EhScreen() {
val context = LocalContext.current
fun launchSnackBar(content: String) = coroutineScope.launch { snackbarHostState.showSnackbar(content) }
val signin = EhCookieStore.hasSignedIn()
+ val dialogState = rememberDialogState()
+ dialogState.Intercept()
Scaffold(
topBar = {
TopAppBar(
@@ -241,6 +244,27 @@ fun EhScreen() {
entryValueRes = R.array.thumb_resolution_entry_values,
value = thumbResolution,
)
+ var defaultFavSlot by Settings::defaultFavSlot.observed
+ val disabled = stringResource(id = R.string.disabled_nav)
+ val localFav = stringResource(id = R.string.local_favorites)
+ val summary = when (defaultFavSlot) {
+ -1 -> localFav
+ in 0..9 -> Settings.favCat[defaultFavSlot]
+ else -> stringResource(id = R.string.default_favorites_warning)
+ }
+ val items = if (signin) {
+ arrayOf(disabled, localFav, *Settings.favCat)
+ } else {
+ arrayOf(disabled, localFav)
+ }
+ Preference(
+ title = stringResource(id = R.string.default_favorites_collection),
+ summary = summary,
+ ) {
+ coroutineScope.launch {
+ defaultFavSlot = dialogState.showSelectItem(*items, title = R.string.default_favorites_collection) - 2
+ }
+ }
SwitchPreference(
title = stringResource(id = R.string.settings_eh_force_eh_thumb),
summary = stringResource(id = R.string.settings_eh_force_eh_thumb_summary),
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 7adc68e4e..9fd5067a9 100755
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -297,6 +297,7 @@
Aus Favoriten löschen
%d Elemente aus Favoriten löschen?
Favoriten verschieben
+ Standard-Favoriten
Manuell auswählen
Kollektionen
Du musst dich zuerst anmelden
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 68b02eba0..1e77ef9b0 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -357,6 +357,7 @@
Eliminar de favoritos
¿Eliminar %d galerías de favoritos?
Mover favoritos
+ Colección de favoritos por defecto
Déjame elegir
Colección
Se necesita iniciar sesión
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index c44381a68..0cb10c2af 100755
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -396,6 +396,7 @@
Effacer de favoris
Effacer %d objets de favoris ?
Déplacer favoris
+ Collection favoris par défaut
Sélectionner manuellement
Collections
Vous devez vous connecter
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 224e95c83..fab8a68f4 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -393,6 +393,7 @@
お気に入りから削除
%d件の項目をお気に入りリストから削除します?
お気に入りを移動
+ 既定のお気に入りリスト
手動で選択
お気に入りコレクション
ログインが必要
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 2da01798d..c7b2c40f6 100755
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -367,6 +367,7 @@
즐겨찾기에서 삭제
%d개 항목을 즐겨찾기에서 삭제하시겠습니까?
즐겨찾기 이동
+ 기본 즐겨찾기 컬렉션
직접 선택
컬렉션
로그인 필요
diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml
index 81452448a..69d6d4855 100644
--- a/app/src/main/res/values-th/strings.xml
+++ b/app/src/main/res/values-th/strings.xml
@@ -382,6 +382,7 @@
ลบออกจากรายการโปรด
ต้องการลบ %d รายการออกจากรายการโปรดหรือไม่?
ย้ายรายการโปรด
+ ค่าเริ่มต้นของที่เก็บรายการโปรด
ขอให้ฉันเลือกนะ
คอลเลคชั่น
จำเป็นต้องลงชื่อเข้าใช้ก่อน
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index fa9804384..4b1e98026 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -412,6 +412,8 @@
删除收藏
删除 %d 项收藏?
移动收藏
+ 默认收藏夹
+ 启用此项将无法添加收藏备注
让我选择
备注
收藏夹
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 81316271e..a730abebb 100755
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -422,6 +422,7 @@
刪除收藏
刪除 %d 項收藏?
移動收藏
+ 默認收藏夾
讓我選擇
收藏夾
需要登錄
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 74cd95b3c..d0817b85d 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -403,6 +403,7 @@
移除收藏
將 %d 項收藏移除?
移動收藏
+ 預設收藏夾
讓我每次都選擇
收藏夾
需要登入
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 45522359c..1240f8d86 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -470,6 +470,8 @@
Delete from favorites
Delete %d items from favorites?
Move favorites
+ Default favorites collection
+ You won\'t be able to add favorite notes if you enable this
Let me select
Note
Collections