Add toast if extension could not be installed

This commit is contained in:
Jays2Kings 2021-06-24 01:37:37 -04:00
parent 0b9754c5fa
commit 6ba677f9a4
2 changed files with 8 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import android.content.pm.PackageInstaller
import android.content.pm.PackageInstaller.SessionParams import android.content.pm.PackageInstaller.SessionParams
import android.os.Bundle import android.os.Bundle
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -67,11 +68,11 @@ class ExtensionInstallActivity : Activity() {
} }
private fun packageInstallStep(intent: Intent) { private fun packageInstallStep(intent: Intent) {
val extras = intent.extras val extras = intent.extras ?: return
if (PACKAGE_INSTALLED_ACTION == intent.action) { if (PACKAGE_INSTALLED_ACTION == intent.action) {
val downloadId = intent.extras!!.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID) val downloadId = extras.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID)
val extensionManager: ExtensionManager by injectLazy() val extensionManager: ExtensionManager by injectLazy()
when (extras!!.getInt(PackageInstaller.EXTRA_STATUS)) { when (val status = extras.getInt(PackageInstaller.EXTRA_STATUS)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> { PackageInstaller.STATUS_PENDING_USER_ACTION -> {
val confirmIntent = extras[Intent.EXTRA_INTENT] as? Intent val confirmIntent = extras[Intent.EXTRA_INTENT] as? Intent
startActivityForResult(confirmIntent, INSTALL_REQUEST_CODE) startActivityForResult(confirmIntent, INSTALL_REQUEST_CODE)
@ -83,6 +84,9 @@ class ExtensionInstallActivity : Activity() {
} }
PackageInstaller.STATUS_FAILURE, PackageInstaller.STATUS_FAILURE_ABORTED, PackageInstaller.STATUS_FAILURE_BLOCKED, PackageInstaller.STATUS_FAILURE_CONFLICT, PackageInstaller.STATUS_FAILURE_INCOMPATIBLE, PackageInstaller.STATUS_FAILURE_INVALID, PackageInstaller.STATUS_FAILURE_STORAGE -> { PackageInstaller.STATUS_FAILURE, PackageInstaller.STATUS_FAILURE_ABORTED, PackageInstaller.STATUS_FAILURE_BLOCKED, PackageInstaller.STATUS_FAILURE_CONFLICT, PackageInstaller.STATUS_FAILURE_INCOMPATIBLE, PackageInstaller.STATUS_FAILURE_INVALID, PackageInstaller.STATUS_FAILURE_STORAGE -> {
extensionManager.cancelInstallation(downloadId, false) extensionManager.cancelInstallation(downloadId, false)
if (status != PackageInstaller.STATUS_FAILURE_ABORTED) {
toast(R.string.could_not_install_extension)
}
finish() finish()
} }
else -> { else -> {

View File

@ -302,6 +302,7 @@
<string name="may_contain_nsfw">May contain NSFW (18+) content</string> <string name="may_contain_nsfw">May contain NSFW (18+) content</string>
<string name="app_info">App info</string> <string name="app_info">App info</string>
<string name="_must_be_enabled_first">%1$s must be enabled first</string> <string name="_must_be_enabled_first">%1$s must be enabled first</string>
<string name="could_not_install_extension">Could not install extension</string>
<plurals name="_updates_pending"> <plurals name="_updates_pending">
<item quantity="one">%d update pending</item> <item quantity="one">%d update pending</item>
<item quantity="other">%d updates pending</item> <item quantity="other">%d updates pending</item>