Restore default favorite slot

This commit is contained in:
FooIbar authored and tarsin committed 2023-08-04 17:37:26 +08:00
1 parent 22b87de29d
commit 59a9448d70
13 files changed
+59 -17

No files matched your search

@@ -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)
@@ -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
@@ -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),
+1
View File
@@ -297,6 +297,7 @@
<string name="delete_favorites_dialog_title">Aus Favoriten löschen</string>
<string name="delete_favorites_dialog_message">%d Elemente aus Favoriten löschen?</string>
<string name="move_favorites_dialog_title">Favoriten verschieben</string>
<string name="default_favorites_collection">Standard-Favoriten</string>
<string name="let_me_select">Manuell auswählen</string>
<string name="collections">Kollektionen</string>
<string name="need_sign_in">Du musst dich zuerst anmelden</string>
+1
View File
@@ -357,6 +357,7 @@
<string name="delete_favorites_dialog_title">Eliminar de favoritos</string>
<string name="delete_favorites_dialog_message">¿Eliminar %d galerías de favoritos?</string>
<string name="move_favorites_dialog_title">Mover favoritos</string>
<string name="default_favorites_collection">Colección de favoritos por defecto</string>
<string name="let_me_select">Déjame elegir</string>
<string name="collections">Colección</string>
<string name="need_sign_in">Se necesita iniciar sesión</string>
+1
View File
@@ -396,6 +396,7 @@
<string name="delete_favorites_dialog_title">Effacer de favoris</string>
<string name="delete_favorites_dialog_message">Effacer %d objets de favoris ?</string>
<string name="move_favorites_dialog_title">Déplacer favoris</string>
<string name="default_favorites_collection">Collection favoris par défaut</string>
<string name="let_me_select">Sélectionner manuellement</string>
<string name="collections">Collections</string>
<string name="need_sign_in">Vous devez vous connecter</string>
+1
View File
@@ -393,6 +393,7 @@
<string name="delete_favorites_dialog_title">お気に入りから削除</string>
<string name="delete_favorites_dialog_message">%d件の項目をお気に入りリストから削除します?</string>
<string name="move_favorites_dialog_title">お気に入りを移動</string>
<string name="default_favorites_collection">既定のお気に入りリスト</string>
<string name="let_me_select">手動で選択</string>
<string name="collections">お気に入りコレクション</string>
<string name="need_sign_in">ログインが必要</string>
+1
View File
@@ -367,6 +367,7 @@
<string name="delete_favorites_dialog_title">즐겨찾기에서 삭제</string>
<string name="delete_favorites_dialog_message">%d개 항목을 즐겨찾기에서 삭제하시겠습니까?</string>
<string name="move_favorites_dialog_title">즐겨찾기 이동</string>
<string name="default_favorites_collection">기본 즐겨찾기 컬렉션</string>
<string name="let_me_select">직접 선택</string>
<string name="collections">컬렉션</string>
<string name="need_sign_in">로그인 필요</string>
+1
View File
@@ -382,6 +382,7 @@
<string name="delete_favorites_dialog_title">ลบออกจากรายการโปรด</string>
<string name="delete_favorites_dialog_message">ต้องการลบ %d รายการออกจากรายการโปรดหรือไม่?</string>
<string name="move_favorites_dialog_title">ย้ายรายการโปรด</string>
<string name="default_favorites_collection">ค่าเริ่มต้นของที่เก็บรายการโปรด</string>
<string name="let_me_select">ขอให้ฉันเลือกนะ</string>
<string name="collections">คอลเลคชั่น</string>
<string name="need_sign_in">จำเป็นต้องลงชื่อเข้าใช้ก่อน</string>
@@ -412,6 +412,8 @@
<string name="delete_favorites_dialog_title">删除收藏</string>
<string name="delete_favorites_dialog_message">删除 %d 项收藏?</string>
<string name="move_favorites_dialog_title">移动收藏</string>
<string name="default_favorites_collection">默认收藏夹</string>
<string name="default_favorites_warning">启用此项将无法添加收藏备注</string>
<string name="let_me_select">让我选择</string>
<string name="favorite_note">备注</string>
<string name="collections">收藏夹</string>
@@ -422,6 +422,7 @@
<string name="delete_favorites_dialog_title">刪除收藏</string>
<string name="delete_favorites_dialog_message">刪除 %d 項收藏?</string>
<string name="move_favorites_dialog_title">移動收藏</string>
<string name="default_favorites_collection">默認收藏夾</string>
<string name="let_me_select">讓我選擇</string>
<string name="collections">收藏夾</string>
<string name="need_sign_in">需要登錄</string>
@@ -403,6 +403,7 @@
<string name="delete_favorites_dialog_title">移除收藏</string>
<string name="delete_favorites_dialog_message">將 %d 項收藏移除?</string>
<string name="move_favorites_dialog_title">移動收藏</string>
<string name="default_favorites_collection">預設收藏夾</string>
<string name="let_me_select">讓我每次都選擇</string>
<string name="collections">收藏夾</string>
<string name="need_sign_in">需要登入</string>
+2
View File
@@ -470,6 +470,8 @@
<string name="delete_favorites_dialog_title">Delete from favorites</string>
<string name="delete_favorites_dialog_message">Delete %d items from favorites?</string>
<string name="move_favorites_dialog_title">Move favorites</string>
<string name="default_favorites_collection">Default favorites collection</string>
<string name="default_favorites_warning">You won\'t be able to add favorite notes if you enable this</string>
<string name="let_me_select">Let me select</string>
<string name="favorite_note">Note</string>
<string name="collections">Collections</string>