Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync feeds and extension repo settings #280

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/eu/kanade/domain/sync/SyncPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class SyncPreferences(
tracking = preferenceStore.getBoolean("tracking", true).get(),
history = preferenceStore.getBoolean("history", true).get(),
appSettings = preferenceStore.getBoolean("appSettings", true).get(),
extensionRepoSettings = preferenceStore.getBoolean("extensionRepoSettings", true).get(),
sourceSettings = preferenceStore.getBoolean("sourceSettings", true).get(),
privateSettings = preferenceStore.getBoolean("privateSettings", true).get(),

// SY -->
customInfo = preferenceStore.getBoolean("customInfo", true).get(),
readEntries = preferenceStore.getBoolean("readEntries", true).get(),
savedSearchesFeeds = preferenceStore.getBoolean("savedSearchesFeeds", true).get(),
// SY <--
)
}
Expand All @@ -70,12 +72,14 @@ class SyncPreferences(
preferenceStore.getBoolean("tracking", true).set(syncSettings.tracking)
preferenceStore.getBoolean("history", true).set(syncSettings.history)
preferenceStore.getBoolean("appSettings", true).set(syncSettings.appSettings)
preferenceStore.getBoolean("extensionRepoSettings", true).set(syncSettings.extensionRepoSettings)
preferenceStore.getBoolean("sourceSettings", true).set(syncSettings.sourceSettings)
preferenceStore.getBoolean("privateSettings", true).set(syncSettings.privateSettings)

// SY -->
preferenceStore.getBoolean("customInfo", true).set(syncSettings.customInfo)
preferenceStore.getBoolean("readEntries", true).set(syncSettings.readEntries)
preferenceStore.getBoolean("savedSearchesFeeds", true).set(syncSettings.savedSearchesFeeds)
// SY <--
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ data class SyncSettings(
val tracking: Boolean = true,
val history: Boolean = true,
val appSettings: Boolean = true,
val extensionRepoSettings: Boolean = true,
val sourceSettings: Boolean = true,
val privateSettings: Boolean = false,

// SY -->
val customInfo: Boolean = true,
val readEntries: Boolean = true,
val savedSearchesFeeds: Boolean = true,
// SY <--
)
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ private class SyncSettingsSelectorModel(
tracking = syncSettings.tracking,
history = syncSettings.history,
appSettings = syncSettings.appSettings,
extensionRepoSettings = syncSettings.extensionRepoSettings,
sourceSettings = syncSettings.sourceSettings,
privateSettings = syncSettings.privateSettings,

// SY -->
customInfo = syncSettings.customInfo,
readEntries = syncSettings.readEntries,
savedSearchesFeeds = syncSettings.savedSearchesFeeds,
// SY <--
)
}
Expand All @@ -140,12 +142,14 @@ private class SyncSettingsSelectorModel(
tracking = backupOptions.tracking,
history = backupOptions.history,
appSettings = backupOptions.appSettings,
extensionRepoSettings = backupOptions.extensionRepoSettings,
sourceSettings = backupOptions.sourceSettings,
privateSettings = backupOptions.privateSettings,

// SY -->
customInfo = backupOptions.customInfo,
readEntries = backupOptions.readEntries,
savedSearchesFeeds = backupOptions.savedSearchesFeeds,
// SY <--
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class BackupCreator(
backupSourcePreferences = backupSourcePreferences(options),

// SY -->
backupSavedSearches = backupSavedSearches(),
backupSavedSearches = backupSavedSearches(options),
// SY <--

// KMK -->
backupFeeds = backupFeeds(),
backupFeeds = backupFeeds(options),
// KMK <--
)

Expand Down Expand Up @@ -179,17 +179,21 @@ class BackupCreator(
}

// SY -->
suspend fun backupSavedSearches(): List<BackupSavedSearch> {
return savedSearchBackupCreator.backupSavedSearches()
suspend fun backupSavedSearches(options: BackupOptions): List<BackupSavedSearch> {
if (!options.savedSearchesFeeds) return emptyList()

return savedSearchBackupCreator()
}
// SY <--

// KMK -->
/**
* Backup global Popular/Latest feeds
*/
suspend fun backupFeeds(): List<BackupFeed> {
return feedBackupCreator.backupFeeds()
suspend fun backupFeeds(options: BackupOptions): List<BackupFeed> {
if (!options.savedSearchesFeeds) return emptyList()

return feedBackupCreator()
}
// KMK <--

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.backup.create
import dev.icerock.moko.resources.StringResource
import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.i18n.kmk.KMR
import tachiyomi.i18n.sy.SYMR

data class BackupOptions(
Expand All @@ -18,6 +19,7 @@ data class BackupOptions(
// SY -->
val customInfo: Boolean = true,
val readEntries: Boolean = true,
val savedSearchesFeeds: Boolean = true,
// SY <--
) {

Expand All @@ -34,10 +36,12 @@ data class BackupOptions(
// SY -->
customInfo,
readEntries,
savedSearchesFeeds,
// SY <--
)

fun canCreate() = libraryEntries || categories || appSettings || extensionRepoSettings || sourceSettings
fun canCreate() =
libraryEntries || categories || appSettings || extensionRepoSettings || sourceSettings || savedSearchesFeeds

companion object {
val libraryOptions = persistentListOf(
Expand Down Expand Up @@ -82,6 +86,13 @@ data class BackupOptions(
setter = { options, enabled -> options.copy(readEntries = enabled) },
enabled = { it.libraryEntries },
),
Entry(
// KMK-->
label = KMR.strings.saved_searches_feeds,
// KMK <--
getter = BackupOptions::savedSearchesFeeds,
setter = { options, enabled -> options.copy(savedSearchesFeeds = enabled) },
),
// SY <--
)

Expand Down Expand Up @@ -122,6 +133,7 @@ data class BackupOptions(
// SY -->
customInfo = array[9],
readEntries = array[10],
savedSearchesFeeds = array[11],
// SY <--
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ class FeedBackupCreator(
) {

/**
* Backup global Popular/Latest feeds
* Backup:
* - Global Popular/Latest feeds
* - Global feeds from saved searches
* - Source's feeds from saved searches
*/
suspend fun backupFeeds(): List<BackupFeed> {
suspend operator fun invoke(): List<BackupFeed> {
return handler.awaitList { feed_saved_searchQueries.selectAllFeedWithSavedSearch(backupFeedMapper) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SavedSearchBackupCreator(
private val handler: DatabaseHandler = Injekt.get(),
) {

suspend fun backupSavedSearches(): List<BackupSavedSearch> {
suspend operator fun invoke(): List<BackupSavedSearch> {
return handler.awaitList { saved_searchQueries.selectAll(backupSavedSearchMapper) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BackupRestorer(
restoreAmount += 1
}
// SY -->
if (options.savedSearches) {
if (options.savedSearchesFeeds) {
restoreAmount += 1
}
// SY <--
Expand All @@ -108,7 +108,7 @@ class BackupRestorer(
restoreCategories(backup.backupCategories)
}
// SY -->
if (options.savedSearches) {
if (options.savedSearchesFeeds) {
restoreSavedSearches(
backup.backupSavedSearches,
// KMK -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class RestoreOptions(
val extensionRepoSettings: Boolean = true,
val sourceSettings: Boolean = true,
// SY -->
val savedSearches: Boolean = true,
val savedSearchesFeeds: Boolean = true,
// SY <--
) {

Expand All @@ -23,7 +23,7 @@ data class RestoreOptions(
extensionRepoSettings,
sourceSettings,
// SY -->
savedSearches,
savedSearchesFeeds,
// SY <--
)

Expand All @@ -33,7 +33,7 @@ data class RestoreOptions(
appSettings ||
extensionRepoSettings ||
sourceSettings /* SY --> */ ||
savedSearches /* SY <-- */
savedSearchesFeeds /* SY <-- */

companion object {
val options = persistentListOf(
Expand Down Expand Up @@ -64,9 +64,11 @@ data class RestoreOptions(
),
// SY -->
Entry(
// KMK-->
label = KMR.strings.saved_searches_feeds,
getter = RestoreOptions::savedSearches,
setter = { options, enabled -> options.copy(savedSearches = enabled) },
// KMK <--
getter = RestoreOptions::savedSearchesFeeds,
setter = { options, enabled -> options.copy(savedSearchesFeeds = enabled) },
),
// SY <--
)
Expand All @@ -78,7 +80,7 @@ data class RestoreOptions(
extensionRepoSettings = array[3],
sourceSettings = array[4],
// SY -->
savedSearches = array[5],
savedSearchesFeeds = array[5],
// SY <--
)
}
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ class SyncManager(
chapters = syncOptions.chapters,
tracking = syncOptions.tracking,
history = syncOptions.history,
extensionRepoSettings = syncOptions.extensionRepoSettings,
appSettings = syncOptions.appSettings,
sourceSettings = syncOptions.sourceSettings,
privateSettings = syncOptions.privateSettings,

// SY -->
customInfo = syncOptions.customInfo,
readEntries = syncOptions.readEntries,
savedSearchesFeeds = syncOptions.savedSearchesFeeds,
// SY <--
)

Expand All @@ -105,11 +107,11 @@ class SyncManager(
backupSourcePreferences = backupCreator.backupSourcePreferences(backupOptions),

// SY -->
backupSavedSearches = backupCreator.backupSavedSearches(),
backupSavedSearches = backupCreator.backupSavedSearches(backupOptions),
// SY <--

// KMK -->
backupFeeds = backupCreator.backupFeeds(),
backupFeeds = backupCreator.backupFeeds(backupOptions),
// KMK <--
)
logcat(LogPriority.DEBUG) { "End create backup" }
Expand Down Expand Up @@ -180,10 +182,15 @@ class SyncManager(
backupSources = remoteBackup.backupSources,
backupPreferences = remoteBackup.backupPreferences,
backupSourcePreferences = remoteBackup.backupSourcePreferences,
backupExtensionRepo = remoteBackup.backupExtensionRepo,

// SY -->
backupSavedSearches = remoteBackup.backupSavedSearches,
// SY <--

// KMK -->
backupFeeds = remoteBackup.backupFeeds,
// KMK <--
)

// It's local sync no need to restore data. (just update remote data)
Expand All @@ -201,7 +208,12 @@ class SyncManager(
context,
backupUri,
sync = true,
options = RestoreOptions(),
options = RestoreOptions(
appSettings = true,
sourceSettings = true,
libraryEntries = true,
extensionRepoSettings = true,
),
)

// update the sync timestamp
Expand Down
Loading