Restore default favorite slot
This commit is contained in:
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),
|
||||
|
||||
Reference in new issue
Block a user