Saved searches tweaks
This commit is contained in:
parent
d5638c6204
commit
1dcf49200a
@ -147,8 +147,8 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
|||||||
* @return list of [BackupSavedSearch] to be backed up
|
* @return list of [BackupSavedSearch] to be backed up
|
||||||
*/
|
*/
|
||||||
private fun backupSavedSearches(): List<BackupSavedSearch> {
|
private fun backupSavedSearches(): List<BackupSavedSearch> {
|
||||||
return preferences.savedSearches().get().map {
|
return preferences.savedSearches().get().mapNotNull {
|
||||||
val sourceId = it.substringBefore(':').toLong()
|
val sourceId = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
BackupSavedSearch(
|
BackupSavedSearch(
|
||||||
content.name,
|
content.name,
|
||||||
@ -414,8 +414,8 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
|||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
internal fun restoreSavedSearches(backupSavedSearches: List<BackupSavedSearch>) {
|
internal fun restoreSavedSearches(backupSavedSearches: List<BackupSavedSearch>) {
|
||||||
val currentSavedSearches = preferences.savedSearches().get().map {
|
val currentSavedSearches = preferences.savedSearches().get().mapNotNull {
|
||||||
val sourceId = it.substringBefore(':').toLong()
|
val sourceId = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
BackupSavedSearch(
|
BackupSavedSearch(
|
||||||
content.name,
|
content.name,
|
||||||
@ -425,22 +425,19 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences.savedSearches()
|
val newSavedSearches = backupSavedSearches.filter { backupSavedSearch ->
|
||||||
.set(
|
currentSavedSearches.none { it.name == backupSavedSearch.name && it.source == backupSavedSearch.source }
|
||||||
(
|
}.map {
|
||||||
backupSavedSearches.filter { backupSavedSearch -> currentSavedSearches.none { it.name == backupSavedSearch.name && it.source == backupSavedSearch.source } }
|
"${it.source}:" + Json.encodeToString(
|
||||||
.map {
|
JsonSavedSearch(
|
||||||
"${it.source}:" + Json.encodeToString(
|
it.name,
|
||||||
JsonSavedSearch(
|
it.query,
|
||||||
it.name,
|
Json.decodeFromString(it.filterList)
|
||||||
it.query,
|
)
|
||||||
Json.decodeFromString(it.filterList)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} + preferences.savedSearches().get()
|
|
||||||
)
|
|
||||||
.toSet()
|
|
||||||
)
|
)
|
||||||
|
}.toSet()
|
||||||
|
|
||||||
|
preferences.savedSearches().set(newSavedSearches + preferences.savedSearches().get())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,32 +289,32 @@ class LegacyBackupManager(context: Context, version: Int = CURRENT_VERSION) : Ab
|
|||||||
|
|
||||||
val newSavedSearches = backupSavedSearches.mapNotNull {
|
val newSavedSearches = backupSavedSearches.mapNotNull {
|
||||||
runCatching {
|
runCatching {
|
||||||
val id = it.substringBefore(':').toLong()
|
val id = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val content = parser.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = parser.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
id to content
|
id to content
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}.toMutableList()
|
}.toMutableSet()
|
||||||
|
|
||||||
val currentSources = newSavedSearches.map { it.first }.toSet()
|
val currentSources = newSavedSearches.map(Pair<Long, *>::first).toSet()
|
||||||
|
|
||||||
newSavedSearches += preferences.savedSearches().get().mapNotNull {
|
newSavedSearches += preferences.savedSearches().get().mapNotNull {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
val id = it.substringBefore(':').toLong()
|
val id = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val content = parser.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = parser.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
id to content
|
id to content
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}.toMutableList()
|
}
|
||||||
|
|
||||||
val otherSerialized = preferences.savedSearches().get().mapNotNull {
|
val otherSerialized = preferences.savedSearches().get().mapNotNull {
|
||||||
val sourceId = it.split(":")[0].toLongOrNull() ?: return@mapNotNull null
|
val sourceId = it.substringBefore(":").toLongOrNull() ?: return@mapNotNull null
|
||||||
if (sourceId in currentSources) return@mapNotNull null
|
if (sourceId in currentSources) return@mapNotNull null
|
||||||
it
|
it
|
||||||
}
|
}.toSet()
|
||||||
|
|
||||||
val newSerialized = newSavedSearches.map {
|
val newSerialized = newSavedSearches.map { (source, savedSearch) ->
|
||||||
"${it.first}:" + Json.encodeToString(it.second)
|
"$source:" + Json.encodeToString(savedSearch)
|
||||||
}
|
}.toSet()
|
||||||
preferences.savedSearches().set((otherSerialized + newSerialized).toSet())
|
preferences.savedSearches().set(otherSerialized + newSerialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,7 @@ import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
|
|||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
|
import exh.log.xLogE
|
||||||
import exh.savedsearches.EXHSavedSearch
|
import exh.savedsearches.EXHSavedSearch
|
||||||
import exh.savedsearches.JsonSavedSearch
|
import exh.savedsearches.JsonSavedSearch
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -443,9 +444,9 @@ open class BrowseSourcePresenter(
|
|||||||
|
|
||||||
// EXH -->
|
// EXH -->
|
||||||
fun saveSearches(searches: List<EXHSavedSearch>) {
|
fun saveSearches(searches: List<EXHSavedSearch>) {
|
||||||
val otherSerialized = prefs.savedSearches().get().filter {
|
val otherSerialized = prefs.savedSearches().get().filterNot {
|
||||||
!it.startsWith("${source.id}:")
|
it.startsWith("${source.id}:")
|
||||||
}
|
}.toSet()
|
||||||
val newSerialized = searches.map {
|
val newSerialized = searches.map {
|
||||||
"${source.id}:" + Json.encodeToString(
|
"${source.id}:" + Json.encodeToString(
|
||||||
JsonSavedSearch(
|
JsonSavedSearch(
|
||||||
@ -457,14 +458,13 @@ open class BrowseSourcePresenter(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
prefs.savedSearches().set((otherSerialized + newSerialized).toSet())
|
prefs.savedSearches().set(otherSerialized + newSerialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadSearches(): List<EXHSavedSearch> {
|
fun loadSearches(): List<EXHSavedSearch> {
|
||||||
val loaded = prefs.savedSearches().get()
|
return prefs.savedSearches().get().mapNotNull {
|
||||||
return loaded.map {
|
val id = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val id = it.substringBefore(':').toLong()
|
if (id != source.id) return@mapNotNull null
|
||||||
if (id != source.id) return@map null
|
|
||||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
try {
|
try {
|
||||||
val originalFilters = source.getFilterList()
|
val originalFilters = source.getFilterList()
|
||||||
@ -476,15 +476,14 @@ open class BrowseSourcePresenter(
|
|||||||
)
|
)
|
||||||
} catch (t: RuntimeException) {
|
} catch (t: RuntimeException) {
|
||||||
// Load failed
|
// Load failed
|
||||||
Timber.e(t, "Failed to load saved search!")
|
xLogE("Failed to load saved search!", t)
|
||||||
t.printStackTrace()
|
|
||||||
EXHSavedSearch(
|
EXHSavedSearch(
|
||||||
content.name,
|
content.name,
|
||||||
content.query,
|
content.query,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.filterNotNull()
|
}
|
||||||
}
|
}
|
||||||
// EXH <--
|
// EXH <--
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Compani
|
|||||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
|
import exh.log.xLogE
|
||||||
import exh.savedsearches.EXHSavedSearch
|
import exh.savedsearches.EXHSavedSearch
|
||||||
import exh.savedsearches.JsonSavedSearch
|
import exh.savedsearches.JsonSavedSearch
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -213,9 +214,8 @@ open class IndexPresenter(
|
|||||||
private val filterSerializer = FilterSerializer()
|
private val filterSerializer = FilterSerializer()
|
||||||
|
|
||||||
fun loadSearches(): List<EXHSavedSearch> {
|
fun loadSearches(): List<EXHSavedSearch> {
|
||||||
val loaded = preferences.savedSearches().get()
|
return preferences.savedSearches().get().mapNotNull {
|
||||||
return loaded.mapNotNull {
|
val id = it.substringBefore(':').toLongOrNull() ?: return@mapNotNull null
|
||||||
val id = it.substringBefore(':').toLong()
|
|
||||||
if (id != source.id) return@mapNotNull null
|
if (id != source.id) return@mapNotNull null
|
||||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||||
try {
|
try {
|
||||||
@ -228,8 +228,7 @@ open class IndexPresenter(
|
|||||||
)
|
)
|
||||||
} catch (t: RuntimeException) {
|
} catch (t: RuntimeException) {
|
||||||
// Load failed
|
// Load failed
|
||||||
Timber.e(t, "Failed to load saved search!")
|
xLogE("Failed to load saved search!", t)
|
||||||
t.printStackTrace()
|
|
||||||
EXHSavedSearch(
|
EXHSavedSearch(
|
||||||
content.name,
|
content.name,
|
||||||
content.query,
|
content.query,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user