Skip to content

Commit

Permalink
Move sync strings to SY files
Browse files Browse the repository at this point in the history
  • Loading branch information
jobobby04 committed Apr 13, 2024
1 parent e866e60 commit 739f7bc
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private fun LibraryRegularToolbar(
onClick = onClickOpenRandomManga,
),
AppBar.OverflowAction(
title = stringResource(MR.strings.sync_library),
title = stringResource(SYMR.strings.sync_library),
onClick = onClickSyncNow,
),
).builder().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ object SettingsDataScreen : SearchableSettings {
private fun getSyncPreferences(syncPreferences: SyncPreferences, syncService: Int): List<Preference> {
return listOf(
Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_sync_service_category),
title = stringResource(SYMR.strings.pref_sync_service_category),
preferenceItems = persistentListOf(
Preference.PreferenceItem.ListPreference(
pref = syncPreferences.syncService(),
title = stringResource(MR.strings.pref_sync_service),
title = stringResource(SYMR.strings.pref_sync_service),
entries = persistentMapOf(
SyncManager.SyncService.NONE.value to stringResource(MR.strings.off),
SyncManager.SyncService.SYNCYOMI.value to stringResource(MR.strings.syncyomi),
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(MR.strings.google_drive),
SyncManager.SyncService.SYNCYOMI.value to stringResource(SYMR.strings.syncyomi),
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(SYMR.strings.google_drive),
),
onValueChanged = { true },
),
Expand Down Expand Up @@ -402,7 +402,7 @@ object SettingsDataScreen : SearchableSettings {
val googleDriveSync = Injekt.get<GoogleDriveService>()
return listOf(
Preference.PreferenceItem.TextPreference(
title = stringResource(MR.strings.pref_google_drive_sign_in),
title = stringResource(SYMR.strings.pref_google_drive_sign_in),
onClick = {
val intent = googleDriveSync.getSignInIntent()
context.startActivity(intent)
Expand All @@ -427,19 +427,19 @@ object SettingsDataScreen : SearchableSettings {
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
when (result) {
GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(
MR.strings.google_drive_not_signed_in,
SYMR.strings.google_drive_not_signed_in,
duration = 5000,
)
GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast(
MR.strings.google_drive_sync_data_not_found,
SYMR.strings.google_drive_sync_data_not_found,
duration = 5000,
)
GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast(
MR.strings.google_drive_sync_data_purged,
SYMR.strings.google_drive_sync_data_purged,
duration = 5000,
)
GoogleDriveSyncService.DeleteSyncDataStatus.ERROR -> context.toast(
MR.strings.google_drive_sync_data_purge_error,
SYMR.strings.google_drive_sync_data_purge_error,
duration = 10000,
)
}
Expand All @@ -450,7 +450,7 @@ object SettingsDataScreen : SearchableSettings {
}

return Preference.PreferenceItem.TextPreference(
title = stringResource(MR.strings.pref_google_drive_purge_sync_data),
title = stringResource(SYMR.strings.pref_google_drive_purge_sync_data),
onClick = { showPurgeDialog = true },
)
}
Expand All @@ -462,8 +462,8 @@ object SettingsDataScreen : SearchableSettings {
) {
AlertDialog(
onDismissRequest = onDismissRequest,
title = { Text(text = stringResource(MR.strings.pref_purge_confirmation_title)) },
text = { Text(text = stringResource(MR.strings.pref_purge_confirmation_message)) },
title = { Text(text = stringResource(SYMR.strings.pref_purge_confirmation_title)) },
text = { Text(text = stringResource(SYMR.strings.pref_purge_confirmation_message)) },
dismissButton = {
TextButton(onClick = onDismissRequest) {
Text(text = stringResource(MR.strings.action_cancel))
Expand All @@ -482,8 +482,8 @@ object SettingsDataScreen : SearchableSettings {
val scope = rememberCoroutineScope()
return listOf(
Preference.PreferenceItem.EditTextPreference(
title = stringResource(MR.strings.pref_sync_host),
subtitle = stringResource(MR.strings.pref_sync_host_summ),
title = stringResource(SYMR.strings.pref_sync_host),
subtitle = stringResource(SYMR.strings.pref_sync_host_summ),
pref = syncPreferences.clientHost(),
onValueChanged = { newValue ->
scope.launch {
Expand All @@ -496,8 +496,8 @@ object SettingsDataScreen : SearchableSettings {
},
),
Preference.PreferenceItem.EditTextPreference(
title = stringResource(MR.strings.pref_sync_api_key),
subtitle = stringResource(MR.strings.pref_sync_api_key_summ),
title = stringResource(SYMR.strings.pref_sync_api_key),
subtitle = stringResource(SYMR.strings.pref_sync_api_key_summ),
pref = syncPreferences.clientAPIKey(),
),
)
Expand All @@ -507,12 +507,12 @@ object SettingsDataScreen : SearchableSettings {
private fun getSyncNowPref(): Preference.PreferenceGroup {
val navigator = LocalNavigator.currentOrThrow
return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_sync_now_group_title),
title = stringResource(SYMR.strings.pref_sync_now_group_title),
preferenceItems = persistentListOf(
getSyncOptionsPref(),
Preference.PreferenceItem.TextPreference(
title = stringResource(MR.strings.pref_sync_now),
subtitle = stringResource(MR.strings.pref_sync_now_subtitle),
title = stringResource(SYMR.strings.pref_sync_now),
subtitle = stringResource(SYMR.strings.pref_sync_now_subtitle),
onClick = {
navigator.push(SyncSettingsSelector())
},
Expand All @@ -525,8 +525,8 @@ object SettingsDataScreen : SearchableSettings {
private fun getSyncOptionsPref(): Preference.PreferenceItem.TextPreference {
val navigator = LocalNavigator.currentOrThrow
return Preference.PreferenceItem.TextPreference(
title = stringResource(MR.strings.pref_sync_options),
subtitle = stringResource(MR.strings.pref_sync_options_summ),
title = stringResource(SYMR.strings.pref_sync_options),
subtitle = stringResource(SYMR.strings.pref_sync_options_summ),
onClick = { navigator.push(SyncTriggerOptionsScreen()) },
)
}
Expand All @@ -538,16 +538,16 @@ object SettingsDataScreen : SearchableSettings {
val lastSync by syncPreferences.lastSyncTimestamp().collectAsState()

return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_sync_automatic_category),
title = stringResource(SYMR.strings.pref_sync_automatic_category),
preferenceItems = persistentListOf(
Preference.PreferenceItem.ListPreference(
pref = syncIntervalPref,
title = stringResource(MR.strings.pref_sync_interval),
title = stringResource(SYMR.strings.pref_sync_interval),
entries = persistentMapOf(
0 to stringResource(MR.strings.off),
30 to stringResource(MR.strings.update_30min),
60 to stringResource(MR.strings.update_1hour),
180 to stringResource(MR.strings.update_3hour),
30 to stringResource(SYMR.strings.update_30min),
60 to stringResource(SYMR.strings.update_1hour),
180 to stringResource(SYMR.strings.update_3hour),
360 to stringResource(MR.strings.update_6hour),
720 to stringResource(MR.strings.update_12hour),
1440 to stringResource(MR.strings.update_24hour),
Expand All @@ -560,7 +560,7 @@ object SettingsDataScreen : SearchableSettings {
},
),
Preference.PreferenceItem.InfoPreference(
stringResource(MR.strings.last_synchronization, relativeTimeSpanString(lastSync)),
stringResource(SYMR.strings.last_synchronization, relativeTimeSpanString(lastSync)),
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.util.system.toast
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.update
import tachiyomi.i18n.MR
import tachiyomi.i18n.sy.SYMR
import tachiyomi.presentation.core.components.LabeledCheckbox
import tachiyomi.presentation.core.components.LazyColumnWithAction
import tachiyomi.presentation.core.components.SectionCard
Expand All @@ -39,22 +40,22 @@ class SyncSettingsSelector : Screen() {
Scaffold(
topBar = {
AppBar(
title = stringResource(MR.strings.pref_choose_what_to_sync),
title = stringResource(SYMR.strings.pref_choose_what_to_sync),
navigateUp = navigator::pop,
scrollBehavior = it,
)
},
) { contentPadding ->
LazyColumnWithAction(
contentPadding = contentPadding,
actionLabel = stringResource(MR.strings.label_sync),
actionLabel = stringResource(SYMR.strings.label_sync),
actionEnabled = state.options.anyEnabled(),
onClickAction = {
if (!SyncDataJob.isRunning(context)) {
model.syncNow(context)
navigator.pop()
} else {
context.toast(MR.strings.sync_in_progress)
context.toast(SYMR.strings.sync_in_progress)
}
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.data.sync.models.SyncTriggerOptions
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.update
import tachiyomi.i18n.MR
import tachiyomi.i18n.sy.SYMR
import tachiyomi.presentation.core.components.LabeledCheckbox
import tachiyomi.presentation.core.components.LazyColumnWithAction
import tachiyomi.presentation.core.components.SectionCard
Expand All @@ -34,7 +35,7 @@ class SyncTriggerOptionsScreen : Screen() {
Scaffold(
topBar = {
AppBar(
title = stringResource(MR.strings.pref_sync_options),
title = stringResource(SYMR.strings.pref_sync_options),
navigateUp = navigator::pop,
scrollBehavior = it,
)
Expand All @@ -49,7 +50,7 @@ class SyncTriggerOptionsScreen : Screen() {
},
) {
item {
SectionCard(MR.strings.label_triggers) {
SectionCard(SYMR.strings.label_triggers) {
Options(SyncTriggerOptions.mainOptions, state, model)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.data.sync.models

import dev.icerock.moko.resources.StringResource
import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.i18n.sy.SYMR

data class SyncTriggerOptions(
val syncOnChapterRead: Boolean = false,
Expand All @@ -25,22 +25,22 @@ data class SyncTriggerOptions(
companion object {
val mainOptions = persistentListOf(
Entry(
label = MR.strings.sync_on_chapter_read,
label = SYMR.strings.sync_on_chapter_read,
getter = SyncTriggerOptions::syncOnChapterRead,
setter = { options, enabled -> options.copy(syncOnChapterRead = enabled) },
),
Entry(
label = MR.strings.sync_on_chapter_open,
label = SYMR.strings.sync_on_chapter_open,
getter = SyncTriggerOptions::syncOnChapterOpen,
setter = { options, enabled -> options.copy(syncOnChapterOpen = enabled) },
),
Entry(
label = MR.strings.sync_on_app_start,
label = SYMR.strings.sync_on_app_start,
getter = SyncTriggerOptions::syncOnAppStart,
setter = { options, enabled -> options.copy(syncOnAppStart = enabled) },
),
Entry(
label = MR.strings.sync_on_app_resume,
label = SYMR.strings.sync_on_app_resume,
getter = SyncTriggerOptions::syncOnAppResume,
setter = { options, enabled -> options.copy(syncOnAppResume = enabled) },
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.core.common.util.system.logcat
import tachiyomi.i18n.MR
import tachiyomi.i18n.sy.SYMR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -68,7 +69,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
try {
googleDriveService.refreshToken()
val drive = googleDriveService.driveService
?: throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
?: throw Exception(context.stringResource(SYMR.strings.google_drive_not_signed_in))

var backoff = 1000L
var retries = 0 // Retry counter
Expand Down Expand Up @@ -112,11 +113,11 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync

if (retries >= maxRetries) {
logcat(LogPriority.ERROR) { "Max retries reached, exiting sync process" }
throw Exception(context.stringResource(MR.strings.error_before_sync_gdrive) + ": Max retries reached.")
throw Exception(context.stringResource(SYMR.strings.error_before_sync_gdrive) + ": Max retries reached.")
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, throwable = e) { "Error in GoogleDrive beforeSync" }
throw Exception(context.stringResource(MR.strings.error_before_sync_gdrive) + ": ${e.message}", e)
throw Exception(context.stringResource(SYMR.strings.error_before_sync_gdrive) + ": ${e.message}", e)
}
}

Expand All @@ -125,7 +126,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync

if (drive == null) {
logcat(LogPriority.DEBUG) { "Google Drive service not initialized" }
throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
throw Exception(context.stringResource(SYMR.strings.google_drive_not_signed_in))
}

val fileList = getAppDataFileList(drive)
Expand Down Expand Up @@ -166,7 +167,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
override suspend fun pushSyncData(syncData: SyncData) {
val jsonData = json.encodeToString(syncData)
val drive = googleDriveService.driveService
?: throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
?: throw Exception(context.stringResource(SYMR.strings.google_drive_not_signed_in))

val fileList = getAppDataFileList(drive)
val byteArrayOutputStream = ByteArrayOutputStream()
Expand Down Expand Up @@ -205,7 +206,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
deleteLockFile(drive)
} catch (e: Exception) {
logcat(LogPriority.ERROR, throwable = e) { "Failed to push or update sync data" }
throw Exception(context.stringResource(MR.strings.error_uploading_sync_data) + ": ${e.message}", e)
throw Exception(context.stringResource(SYMR.strings.error_uploading_sync_data) + ": ${e.message}", e)
}
}

Expand Down Expand Up @@ -282,7 +283,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, throwable = e) { "Error deleting lock file" }
throw Exception(context.stringResource(MR.strings.error_deleting_google_drive_lock_file), e)
throw Exception(context.stringResource(SYMR.strings.error_deleting_google_drive_lock_file), e)
}
}

Expand Down Expand Up @@ -407,7 +408,7 @@ class GoogleDriveService(private val context: Context) {
.build()

if (refreshToken == "") {
throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
throw Exception(context.stringResource(SYMR.strings.google_drive_not_signed_in))
}

credential.refreshToken = refreshToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ object LibraryTab : Tab {
if (!SyncDataJob.isRunning(context)) {
SyncDataJob.startNow(context)
} else {
context.toast(MR.strings.sync_in_progress)
context.toast(SYMR.strings.sync_in_progress)
}
},
// SY -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.sync.service.GoogleDriveService
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.i18n.MR
import tachiyomi.i18n.sy.SYMR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

Expand All @@ -23,7 +23,7 @@ class GoogleDriveLoginActivity : BaseOAuthLoginActivity() {
onSuccess = {
Toast.makeText(
this@GoogleDriveLoginActivity,
stringResource(MR.strings.google_drive_login_success),
stringResource(SYMR.strings.google_drive_login_success),
Toast.LENGTH_LONG,
).show()

Expand All @@ -32,7 +32,7 @@ class GoogleDriveLoginActivity : BaseOAuthLoginActivity() {
onFailure = { error ->
Toast.makeText(
this@GoogleDriveLoginActivity,
stringResource(MR.strings.google_drive_login_failed, error),
stringResource(SYMR.strings.google_drive_login_failed, error),
Toast.LENGTH_LONG,
).show()
returnToSettings()
Expand All @@ -42,7 +42,7 @@ class GoogleDriveLoginActivity : BaseOAuthLoginActivity() {
} else if (error != null) {
Toast.makeText(
this@GoogleDriveLoginActivity,
stringResource(MR.strings.google_drive_login_failed, error),
stringResource(SYMR.strings.google_drive_login_failed, error),
Toast.LENGTH_LONG,
).show()

Expand Down
Loading

0 comments on commit 739f7bc

Please sign in to comment.