Show different update notification for F-Droid installations
(cherry picked from commit 821d9cdb02318464abb062e9a945ff8c35402b1e) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt
This commit is contained in:
parent
0a2684a1fe
commit
1be153e51c
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
|
|||||||
import eu.kanade.tachiyomi.network.await
|
import eu.kanade.tachiyomi.network.await
|
||||||
import eu.kanade.tachiyomi.network.parseAs
|
import eu.kanade.tachiyomi.network.parseAs
|
||||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
|
import eu.kanade.tachiyomi.util.system.getInstallerPackageName
|
||||||
import exh.syDebugVersion
|
import exh.syDebugVersion
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@ -34,14 +35,19 @@ class AppUpdateChecker {
|
|||||||
|
|
||||||
// Check if latest version is different from current version
|
// Check if latest version is different from current version
|
||||||
if (/* SY --> */ isNewVersionSY(it.version) /* SY <-- */) {
|
if (/* SY --> */ isNewVersionSY(it.version) /* SY <-- */) {
|
||||||
AppUpdateResult.NewUpdate(it)
|
if (context.getInstallerPackageName() == "org.fdroid.fdroid") {
|
||||||
|
AppUpdateResult.NewUpdateFdroidInstallation
|
||||||
|
} else {
|
||||||
|
AppUpdateResult.NewUpdate(it)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AppUpdateResult.NoNewUpdate
|
AppUpdateResult.NoNewUpdate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result is AppUpdateResult.NewUpdate) {
|
when (result) {
|
||||||
AppUpdateNotifier(context).promptUpdate(result.release)
|
is AppUpdateResult.NewUpdate -> AppUpdateNotifier(context).promptUpdate(result.release)
|
||||||
|
is AppUpdateResult.NewUpdateFdroidInstallation -> AppUpdateNotifier(context).promptFdroidUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -58,6 +58,22 @@ internal class AppUpdateNotifier(private val context: Context) {
|
|||||||
notificationBuilder.show()
|
notificationBuilder.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based
|
||||||
|
* updates.
|
||||||
|
*
|
||||||
|
* We can prompt them to migrate to the GitHub version though.
|
||||||
|
*/
|
||||||
|
fun promptFdroidUpdate() {
|
||||||
|
with(notificationBuilder) {
|
||||||
|
setContentTitle(context.getString(R.string.update_check_notification_update_available))
|
||||||
|
setContentText(context.getString(R.string.update_check_fdroid_migration_info))
|
||||||
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
|
setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/guides/troubleshooting/#unable-to-install-the-app-or-extensions"))
|
||||||
|
}
|
||||||
|
notificationBuilder.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call when apk download starts.
|
* Call when apk download starts.
|
||||||
*
|
*
|
||||||
|
@ -2,5 +2,6 @@ package eu.kanade.tachiyomi.data.updater
|
|||||||
|
|
||||||
sealed class AppUpdateResult {
|
sealed class AppUpdateResult {
|
||||||
class NewUpdate(val release: GithubRelease) : AppUpdateResult()
|
class NewUpdate(val release: GithubRelease) : AppUpdateResult()
|
||||||
|
object NewUpdateFdroidInstallation : AppUpdateResult()
|
||||||
object NoNewUpdate : AppUpdateResult()
|
object NoNewUpdate : AppUpdateResult()
|
||||||
}
|
}
|
||||||
|
@ -382,6 +382,19 @@ fun Context.isPackageInstalled(packageName: String): Boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getInstallerPackageName(): String? {
|
||||||
|
return try {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
packageManager.getInstallSourceInfo(packageName).installingPackageName
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
packageManager.getInstallerPackageName(packageName)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.getApplicationIcon(pkgName: String): Drawable? {
|
fun Context.getApplicationIcon(pkgName: String): Drawable? {
|
||||||
return try {
|
return try {
|
||||||
packageManager.getApplicationIcon(pkgName)
|
packageManager.getApplicationIcon(pkgName)
|
||||||
|
@ -765,6 +765,7 @@
|
|||||||
<string name="update_check_notification_download_complete">Download complete</string>
|
<string name="update_check_notification_download_complete">Download complete</string>
|
||||||
<string name="update_check_notification_download_error">Download error</string>
|
<string name="update_check_notification_download_error">Download error</string>
|
||||||
<string name="update_check_notification_update_available">New version available!</string>
|
<string name="update_check_notification_update_available">New version available!</string>
|
||||||
|
<string name="update_check_fdroid_migration_info">A new version is available from the official releases. Tap to learn how to migrate from unofficial F-Droid releases.</string>
|
||||||
|
|
||||||
<!--Extension Updates Notifications-->
|
<!--Extension Updates Notifications-->
|
||||||
<plurals name="update_check_notification_ext_updates">
|
<plurals name="update_check_notification_ext_updates">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user