mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Reset last added categories on app relaunch
This commit is contained in:
parent
137b8a08df
commit
4e2b7ab7d3
4 changed files with 8 additions and 9 deletions
|
@ -52,6 +52,8 @@ interface Category : Serializable {
|
|||
}
|
||||
|
||||
companion object {
|
||||
var lastCategoriesAddedTo = emptySet<Int>()
|
||||
|
||||
fun create(name: String): Category = CategoryImpl().apply {
|
||||
this.name = name
|
||||
}
|
||||
|
|
|
@ -209,8 +209,6 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun lastUsedCategory() = flowPrefs.getInt(Keys.lastUsedCategory, 0)
|
||||
|
||||
fun lastCategoriesAddedTo() = flowPrefs.getStringSet("last_category_added_to", emptySet())
|
||||
|
||||
fun lastUsedSources() = flowPrefs.getStringSet("last_used_sources", emptySet())
|
||||
|
||||
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
||||
|
|
|
@ -276,10 +276,9 @@ class SetCategoriesSheet(
|
|||
categories.map { MangaCategory.create(manga, it) }
|
||||
}.flatten()
|
||||
if (addCategories.isNotEmpty() || listManga.size == 1) {
|
||||
preferences.lastCategoriesAddedTo().set(
|
||||
addCategories.mapNotNull { it.id?.toString() }.toSet().takeIf { it.isNotEmpty() }
|
||||
?: setOf("0"),
|
||||
)
|
||||
Category.lastCategoriesAddedTo =
|
||||
addCategories.mapNotNull { it.id }.toSet().takeIf { it.isNotEmpty() }
|
||||
?: setOf(0)
|
||||
}
|
||||
db.setMangaCategories(mangaCategories, listManga)
|
||||
onMangaAdded()
|
||||
|
|
|
@ -174,8 +174,8 @@ fun Manga.addOrRemoveToFavorites(
|
|||
val categories = db.getCategories().executeAsBlocking()
|
||||
val defaultCategoryId = preferences.defaultCategory()
|
||||
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||
val lastUsedCategories = preferences.lastCategoriesAddedTo().get().mapNotNull { catId ->
|
||||
categories.find { it.id == catId.toIntOrNull() }
|
||||
val lastUsedCategories = Category.lastCategoriesAddedTo.mapNotNull { catId ->
|
||||
categories.find { it.id == catId }
|
||||
}
|
||||
when {
|
||||
defaultCategory != null -> {
|
||||
|
@ -195,7 +195,7 @@ fun Manga.addOrRemoveToFavorites(
|
|||
}
|
||||
defaultCategoryId == -2 && (
|
||||
lastUsedCategories.isNotEmpty() ||
|
||||
preferences.lastCategoriesAddedTo().get().firstOrNull() == "0"
|
||||
Category.lastCategoriesAddedTo.firstOrNull() == 0
|
||||
) -> { // last used category(s)
|
||||
favorite = true
|
||||
date_added = Date().time
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue