mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 00:37:58 +03:00
Show different update notification for F-Droid installations
This commit is contained in:
parent
28575936d3
commit
821d9cdb02
5 changed files with 40 additions and 3 deletions
|
@ -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 uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -33,14 +34,19 @@ class AppUpdateChecker {
|
||||||
|
|
||||||
// Check if latest version is different from current version
|
// Check if latest version is different from current version
|
||||||
if (isNewVersion(it.version)) {
|
if (isNewVersion(it.version)) {
|
||||||
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…
Reference in a new issue