Reset last added categories on app relaunch

This commit is contained in:
Jays2Kings 2023-09-20 14:46:45 -07:00
parent 137b8a08df
commit 4e2b7ab7d3
4 changed files with 8 additions and 9 deletions

View file

@ -52,6 +52,8 @@ interface Category : Serializable {
} }
companion object { companion object {
var lastCategoriesAddedTo = emptySet<Int>()
fun create(name: String): Category = CategoryImpl().apply { fun create(name: String): Category = CategoryImpl().apply {
this.name = name this.name = name
} }

View file

@ -209,8 +209,6 @@ class PreferencesHelper(val context: Context) {
fun lastUsedCategory() = flowPrefs.getInt(Keys.lastUsedCategory, 0) 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 lastUsedSources() = flowPrefs.getStringSet("last_used_sources", emptySet())
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0) fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)

View file

@ -276,10 +276,9 @@ class SetCategoriesSheet(
categories.map { MangaCategory.create(manga, it) } categories.map { MangaCategory.create(manga, it) }
}.flatten() }.flatten()
if (addCategories.isNotEmpty() || listManga.size == 1) { if (addCategories.isNotEmpty() || listManga.size == 1) {
preferences.lastCategoriesAddedTo().set( Category.lastCategoriesAddedTo =
addCategories.mapNotNull { it.id?.toString() }.toSet().takeIf { it.isNotEmpty() } addCategories.mapNotNull { it.id }.toSet().takeIf { it.isNotEmpty() }
?: setOf("0"), ?: setOf(0)
)
} }
db.setMangaCategories(mangaCategories, listManga) db.setMangaCategories(mangaCategories, listManga)
onMangaAdded() onMangaAdded()

View file

@ -174,8 +174,8 @@ fun Manga.addOrRemoveToFavorites(
val categories = db.getCategories().executeAsBlocking() val categories = db.getCategories().executeAsBlocking()
val defaultCategoryId = preferences.defaultCategory() val defaultCategoryId = preferences.defaultCategory()
val defaultCategory = categories.find { it.id == defaultCategoryId } val defaultCategory = categories.find { it.id == defaultCategoryId }
val lastUsedCategories = preferences.lastCategoriesAddedTo().get().mapNotNull { catId -> val lastUsedCategories = Category.lastCategoriesAddedTo.mapNotNull { catId ->
categories.find { it.id == catId.toIntOrNull() } categories.find { it.id == catId }
} }
when { when {
defaultCategory != null -> { defaultCategory != null -> {
@ -195,7 +195,7 @@ fun Manga.addOrRemoveToFavorites(
} }
defaultCategoryId == -2 && ( defaultCategoryId == -2 && (
lastUsedCategories.isNotEmpty() || lastUsedCategories.isNotEmpty() ||
preferences.lastCategoriesAddedTo().get().firstOrNull() == "0" Category.lastCategoriesAddedTo.firstOrNull() == 0
) -> { // last used category(s) ) -> { // last used category(s)
favorite = true favorite = true
date_added = Date().time date_added = Date().time