From 725fcbba0e45488c8553f2a5a88fbdfb2a63982c Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 30 Oct 2022 15:50:09 -0400 Subject: [PATCH] Add warning about F-Droid build support in More screen --- .../browse/ExtensionDetailsScreen.kt | 17 +---------------- .../kanade/presentation/components/Banners.kt | 18 ++++++++++++++++++ .../eu/kanade/presentation/more/MoreScreen.kt | 14 ++++++++++++++ .../tachiyomi/data/updater/AppUpdateChecker.kt | 4 ++-- .../kanade/tachiyomi/ui/more/MoreController.kt | 2 ++ .../tachiyomi/util/system/ContextExtensions.kt | 9 +++++++-- i18n/src/main/res/values/strings.xml | 1 + 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt index 2c8224dea..60bd90f9f 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt @@ -4,8 +4,6 @@ import android.content.Intent import android.net.Uri import android.provider.Settings import android.util.DisplayMetrics -import androidx.annotation.StringRes -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement @@ -56,6 +54,7 @@ import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.ScrollbarLazyColumn +import eu.kanade.presentation.components.WarningBanner import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.presentation.more.settings.widget.TrailingWidgetBuffer import eu.kanade.presentation.util.horizontalPadding @@ -195,20 +194,6 @@ private fun ExtensionDetails( } } -@Composable -private fun WarningBanner(@StringRes textRes: Int) { - Text( - text = stringResource(textRes), - modifier = Modifier - .fillMaxWidth() - .background(MaterialTheme.colorScheme.error) - .padding(16.dp), - color = MaterialTheme.colorScheme.onError, - style = MaterialTheme.typography.bodyMedium, - textAlign = TextAlign.Center, - ) -} - @Composable private fun DetailsHeader( extension: Extension, diff --git a/app/src/main/java/eu/kanade/presentation/components/Banners.kt b/app/src/main/java/eu/kanade/presentation/components/Banners.kt index 9aef71deb..3bb503b4d 100644 --- a/app/src/main/java/eu/kanade/presentation/components/Banners.kt +++ b/app/src/main/java/eu/kanade/presentation/components/Banners.kt @@ -1,5 +1,6 @@ package eu.kanade.presentation.components +import androidx.annotation.StringRes import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth @@ -13,6 +14,23 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import eu.kanade.tachiyomi.R +@Composable +fun WarningBanner( + @StringRes textRes: Int, + modifier: Modifier = Modifier, +) { + Text( + text = stringResource(textRes), + modifier = modifier + .fillMaxWidth() + .background(MaterialTheme.colorScheme.error) + .padding(16.dp), + color = MaterialTheme.colorScheme.onError, + style = MaterialTheme.typography.bodyMedium, + textAlign = TextAlign.Center, + ) +} + @Composable fun AppStateBanners( downloadedOnlyMode: Boolean, diff --git a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt index 2a56c1b91..fa07b962f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt @@ -1,5 +1,6 @@ package eu.kanade.presentation.more +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.navigationBars @@ -24,6 +25,7 @@ import androidx.compose.ui.res.vectorResource import eu.kanade.presentation.components.AppStateBanners import eu.kanade.presentation.components.Divider import eu.kanade.presentation.components.ScrollbarLazyColumn +import eu.kanade.presentation.components.WarningBanner import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.tachiyomi.R @@ -35,6 +37,7 @@ import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView @Composable fun MoreScreen( presenter: MorePresenter, + isFDroid: Boolean, onClickDownloadQueue: () -> Unit, onClickCategories: () -> Unit, onClickBackupAndRestore: () -> Unit, @@ -50,6 +53,17 @@ fun MoreScreen( WindowInsets.navigationBars.asPaddingValues(), ), ) { + if (isFDroid) { + item { + WarningBanner( + textRes = R.string.fdroid_warning, + modifier = Modifier.clickable { + uriHandler.openUri("https://tachiyomi.org/help/faq/#how-do-i-migrate-from-the-f-droid-version") + }, + ) + } + } + item { LogoHeader() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 6839000f6..ce34e1fee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -9,7 +9,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.await import eu.kanade.tachiyomi.network.parseAs import eu.kanade.tachiyomi.util.lang.withIOContext -import eu.kanade.tachiyomi.util.system.getInstallerPackageName +import eu.kanade.tachiyomi.util.system.isInstalledFromFDroid import uy.kohesive.injekt.injectLazy import java.util.Date import java.util.concurrent.TimeUnit @@ -38,7 +38,7 @@ class AppUpdateChecker { // Check if latest version is different from current version if (isNewVersion(it.version)) { - if (context.getInstallerPackageName() == "org.fdroid.fdroid") { + if (context.isInstalledFromFDroid()) { AppUpdateResult.NewUpdateFdroidInstallation } else { AppUpdateResult.NewUpdate(it) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 534d6c46a..a0ae9b93d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.setting.SettingsMainController +import eu.kanade.tachiyomi.util.system.isInstalledFromFDroid class MoreController : FullComposeController(), @@ -19,6 +20,7 @@ class MoreController : override fun ComposeContent() { MoreScreen( presenter = presenter, + isFDroid = activity?.isInstalledFromFDroid() ?: false, onClickDownloadQueue = { router.pushController(DownloadController()) }, onClickCategories = { router.pushController(CategoryController()) }, onClickBackupAndRestore = { router.pushController(SettingsMainController.toBackupScreen()) }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 9ba2d3385..b6edb4a0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -39,6 +39,7 @@ import androidx.core.net.toUri import com.hippo.unifile.UniFile import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.TabletUiMode +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences @@ -393,8 +394,8 @@ fun Context.isPackageInstalled(packageName: String): Boolean { } } -fun Context.getInstallerPackageName(): String? { - return try { +fun Context.isInstalledFromFDroid(): Boolean { + val installerPackageName = try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { packageManager.getInstallSourceInfo(packageName).installingPackageName } else { @@ -404,6 +405,10 @@ fun Context.getInstallerPackageName(): String? { } catch (e: Exception) { null } + + return installerPackageName == "org.fdroid.fdroid" || + // F-Droid builds typically disable the updater + (!BuildConfig.INCLUDE_UPDATER && !isDevFlavor) } fun Context.getApplicationIcon(pkgName: String): Drawable? { diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index baf425821..838592d2e 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -548,6 +548,7 @@ + F-Droid builds are not officially supported.\nTap to learn more. Downloaded only Incognito mode Pauses reading history