From 3892c4caac18c0203a3906545bc4cdd1687f0919 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 29 Jul 2023 09:51:46 -0400 Subject: [PATCH] Minor cleanup --- .../screen/SettingsAppearanceScreen.kt | 31 ++++++------------- .../webview/WebViewScreenContent.kt | 2 +- .../kanade/tachiyomi/ui/manga/MangaScreen.kt | 3 +- .../tachiyomi/ui/manga/MangaScreenModel.kt | 18 ++++++----- i18n/src/main/res/values/strings.xml | 1 - 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt index 14c54a2b4..cd2a53904 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt @@ -49,7 +49,6 @@ object SettingsAppearanceScreen : SearchableSettings { return listOf( getThemeGroup(context = context, uiPreferences = uiPreferences), getDisplayGroup(context = context, uiPreferences = uiPreferences), - getTimestampGroup(uiPreferences = uiPreferences), ) } @@ -122,6 +121,7 @@ object SettingsAppearanceScreen : SearchableSettings { ): Preference.PreferenceGroup { val langs = remember { getLangs(context) } var currentLanguage by remember { mutableStateOf(AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "") } + val now = remember { Date().time } LaunchedEffect(currentLanguage) { val locale = if (currentLanguage.isEmpty()) { @@ -153,25 +153,6 @@ object SettingsAppearanceScreen : SearchableSettings { true }, ), - ), - ) - } - - @Composable - private fun getTimestampGroup(uiPreferences: UiPreferences): Preference.PreferenceGroup { - val now = remember { Date().time } - return Preference.PreferenceGroup( - title = stringResource(R.string.pref_category_timestamps), - preferenceItems = listOf( - Preference.PreferenceItem.ListPreference( - pref = uiPreferences.relativeTime(), - title = stringResource(R.string.pref_relative_format), - entries = mapOf( - 0 to stringResource(R.string.off), - 2 to stringResource(R.string.pref_relative_time_short), - 7 to stringResource(R.string.pref_relative_time_long), - ), - ), Preference.PreferenceItem.ListPreference( pref = uiPreferences.dateFormat(), title = stringResource(R.string.pref_date_format), @@ -181,10 +162,18 @@ object SettingsAppearanceScreen : SearchableSettings { "${it.ifEmpty { stringResource(R.string.label_default) }} ($formattedDate)" }, ), + Preference.PreferenceItem.ListPreference( + pref = uiPreferences.relativeTime(), + title = stringResource(R.string.pref_relative_format), + entries = mapOf( + 0 to stringResource(R.string.off), + 2 to stringResource(R.string.pref_relative_time_short), + 7 to stringResource(R.string.pref_relative_time_long), + ), + ), ), ) } - private fun getLangs(context: Context): Map { val langs = mutableListOf>() val parser = context.resources.getXml(R.xml.locales_config) diff --git a/app/src/main/java/eu/kanade/presentation/webview/WebViewScreenContent.kt b/app/src/main/java/eu/kanade/presentation/webview/WebViewScreenContent.kt index e3da2dd6f..3a97d57ec 100644 --- a/app/src/main/java/eu/kanade/presentation/webview/WebViewScreenContent.kt +++ b/app/src/main/java/eu/kanade/presentation/webview/WebViewScreenContent.kt @@ -72,7 +72,7 @@ fun WebViewScreenContent( super.onPageFinished(view, url) scope.launch { val html = view.getHtml() - showCloudflareHelp = "Checking if the site connection is secure" in html + showCloudflareHelp = "window._cf_chl_opt" in html } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index 30a5d8029..87124b560 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -54,7 +54,6 @@ import logcat.LogPriority import tachiyomi.core.util.lang.withIOContext import tachiyomi.core.util.system.logcat import tachiyomi.domain.chapter.model.Chapter -import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_OUTSIDE_RELEASE_PERIOD import tachiyomi.domain.manga.model.Manga import tachiyomi.presentation.core.screens.LoadingScreen @@ -125,7 +124,7 @@ class MangaScreen( onShareClicked = { shareManga(context, screenModel.manga, screenModel.source) }.takeIf { isHttpSource }, onDownloadActionClicked = screenModel::runDownloadAction.takeIf { !successState.source.isLocalOrStub() }, onEditCategoryClicked = screenModel::showChangeCategoryDialog.takeIf { successState.manga.favorite }, - onEditIntervalClicked = screenModel::showSetMangaIntervalDialog.takeIf { MANGA_OUTSIDE_RELEASE_PERIOD in screenModel.libraryPreferences.libraryUpdateMangaRestriction().get() && successState.manga.favorite }, + onEditIntervalClicked = screenModel::showSetMangaIntervalDialog.takeIf { screenModel.isIntervalEnabled && successState.manga.favorite }, onMigrateClicked = { navigator.push(MigrateSearchScreen(successState.manga.id)) }.takeIf { successState.manga.favorite }, onMultiBookmarkClicked = screenModel::bookmarkChapters, onMultiMarkAsReadClicked = screenModel::markChaptersRead, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 398177da6..69dfb4b23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -82,9 +82,9 @@ class MangaScreenModel( val mangaId: Long, private val isFromSource: Boolean, private val downloadPreferences: DownloadPreferences = Injekt.get(), - val libraryPreferences: LibraryPreferences = Injekt.get(), - val readerPreferences: ReaderPreferences = Injekt.get(), - val uiPreferences: UiPreferences = Injekt.get(), + private val libraryPreferences: LibraryPreferences = Injekt.get(), + readerPreferences: ReaderPreferences = Injekt.get(), + uiPreferences: UiPreferences = Injekt.get(), private val trackManager: TrackManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), private val downloadCache: DownloadCache = Injekt.get(), @@ -130,6 +130,10 @@ class MangaScreenModel( val dateFormat by mutableStateOf(UiPreferences.dateFormat(uiPreferences.dateFormat().get())) private val skipFiltered by readerPreferences.skipFiltered().asState(coroutineScope) + val isIntervalEnabled = LibraryPreferences.MANGA_OUTSIDE_RELEASE_PERIOD in libraryPreferences.libraryUpdateMangaRestriction().get() + private val leadDay = libraryPreferences.leadingExpectedDays().get() + private val followDay = libraryPreferences.followingExpectedDays().get() + private val selectedPositions: Array = arrayOf(-1, -1) // first and last selected index in list private val selectedChapterIds: HashSet = HashSet() @@ -361,10 +365,8 @@ class MangaScreenModel( // TODO: this should be in the state/composables fun intervalDisplay(): Pair? { - val state = successState ?: return null - val leadDay = libraryPreferences.leadingExpectedDays().get() - val followDay = libraryPreferences.followingExpectedDays().get() - val effInterval = state.manga.calculateInterval + val manga = successState?.manga ?: return null + val effInterval = manga.calculateInterval return 1.coerceAtLeast(effInterval.absoluteValue - leadDay) to (effInterval.absoluteValue + followDay) } @@ -1010,7 +1012,7 @@ class MangaScreenModel( sealed interface State { @Immutable - object Loading : State + data object Loading : State @Immutable data class Success( diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 73ee53059..feeee4a90 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -201,7 +201,6 @@ Yotsuba Tidal Wave Pure black dark mode - Timestamps Relative timestamps Short (Today, Yesterday) Long (Short+, n days ago)