From 8e50ac67bc349d6439c4db6b18aff0b72fcd2dc0 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 2 Mar 2018 18:10:10 +0100 Subject: [PATCH] Bugfixes and extension installation improvements --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 3 ++ .../tachiyomi/extension/ExtensionManager.kt | 13 ++++-- .../util/ExtensionInstallActivity.kt | 45 +++++++++++++++++++ .../extension/util/ExtensionInstaller.kt | 38 ++++++---------- .../extension/ExtensionDetailsController.kt | 2 +- .../ui/extension/ExtensionDetailsPresenter.kt | 3 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 5 ++- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../catalogue_main_controller_card_item.xml | 21 ++++----- .../main/res/layout/extension_card_item.xml | 9 ++-- 11 files changed, 94 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt diff --git a/app/build.gradle b/app/build.gradle index c982d32c4..f9e73d2bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,7 +102,7 @@ android { dependencies { // Modified dependencies - implementation 'com.github.inorichi:subsampling-scale-image-view:c19b883' + implementation 'com.github.inorichi:subsampling-scale-image-view:81b9d68' implementation 'com.github.inorichi:junrar-android:634c1f5' // Android support library diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b45c798e5..a64d4d0b2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,6 +52,9 @@ android:scheme="tachiyomi" /> + () + extensionManager.setInstallationResult(downloadId, success) + } + + private companion object { + const val INSTALL_REQUEST_CODE = 500 + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt index 93638ee61..f6feabcb8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt @@ -77,8 +77,6 @@ internal class ExtensionInstaller(private val context: Context) { .mergeWith(pollStatus(id)) // Force an error if the download takes more than 3 minutes .mergeWith(Observable.timer(3, TimeUnit.MINUTES).map { InstallStep.Error }) - // Force an error if the install process takes more than 10 seconds - .flatMap { Observable.just(it).mergeWith(timeoutWhenInstalling(it)) } // Stop when the application is installed or errors .takeUntil { it.isCompleted() } // Always notify on main thread @@ -118,27 +116,15 @@ internal class ExtensionInstaller(private val context: Context) { } } - /** - * Returns an observable that timeouts the installation after a specified time when the apk has - * been downloaded. - * - * @param currentStep The current step of the installation process. - */ - private fun timeoutWhenInstalling(currentStep: InstallStep): Observable { - return Observable.just(currentStep) - .filter { it == InstallStep.Installing } - .delay(10, TimeUnit.SECONDS) - .map { InstallStep.Error } - } - /** * Starts an intent to install the extension at the given uri. * * @param uri The uri of the extension to install. */ - fun installApk(uri: Uri) { - val intent = Intent(Intent.ACTION_VIEW) + fun installApk(downloadId: Long, uri: Uri) { + val intent = Intent(context, ExtensionInstallActivity::class.java) .setDataAndType(uri, APK_MIME) + .putExtra(EXTRA_DOWNLOAD_ID, downloadId) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION) context.startActivity(intent) @@ -158,13 +144,14 @@ internal class ExtensionInstaller(private val context: Context) { } /** - * Called when an extension is installed, allowing to update its installation step. + * Sets the result of the installation of an extension. * - * @param pkgName The package name of the installed application. + * @param downloadId The id of the download. + * @param result Whether the extension was installed or not. */ - fun onApkInstalled(pkgName: String) { - val id = activeDownloads[pkgName] ?: return - downloadsRelay.call(id to InstallStep.Installed) + fun setInstallationResult(downloadId: Long, result: Boolean) { + val step = if (result) InstallStep.Installed else InstallStep.Error + downloadsRelay.call(downloadId to step) } /** @@ -243,17 +230,18 @@ internal class ExtensionInstaller(private val context: Context) { @Suppress("DEPRECATION") val uriCompat = File(cursor.getString(cursor.getColumnIndex( DownloadManager.COLUMN_LOCAL_FILENAME))).getUriCompat(context) - installApk(uriCompat) + installApk(id, uriCompat) } } } else { - installApk(uri) + installApk(id, uri) } } } - private companion object { + companion object { const val APK_MIME = "application/vnd.android.package-archive" + const val EXTRA_DOWNLOAD_ID = "ExtensionInstaller.extra.DOWNLOAD_ID" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index cd79f11d1..a38e95300 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -57,7 +57,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : override fun onViewCreated(view: View) { super.onViewCreated(view) - val extension = presenter.extension + val extension = presenter.extension ?: return val context = view.context extension_title.text = extension.name diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsPresenter.kt index f6a6d4d9a..1b9b958f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsPresenter.kt @@ -12,7 +12,7 @@ class ExtensionDetailsPresenter( private val extensionManager: ExtensionManager = Injekt.get() ) : BasePresenter() { - val extension = extensionManager.installedExtensions.first { it.pkgName == pkgName } + val extension = extensionManager.installedExtensions.find { it.pkgName == pkgName } override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) @@ -33,6 +33,7 @@ class ExtensionDetailsPresenter( } fun uninstallExtension() { + val extension = extension ?: return extensionManager.uninstallExtension(extension.pkgName) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index f1f010f0e..4cd8b2a81 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -148,7 +148,10 @@ class MainActivity : BaseActivity() { SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates) SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_drawer_recently_read) SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_drawer_catalogues) - SHORTCUT_MANGA -> router.setRoot(RouterTransaction.with(MangaController(intent.extras))) + SHORTCUT_MANGA -> { + val extras = intent.extras ?: return false + router.setRoot(RouterTransaction.with(MangaController(extras))) + } SHORTCUT_DOWNLOADS -> { if (router.backstack.none { it.controller() is DownloadController }) { setSelectedDrawerItem(R.id.nav_drawer_downloads) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 4bcf08a43..d6be75efd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -39,7 +39,7 @@ import java.util.* class MangaController : RxController, TabbedController { constructor(manga: Manga?, fromCatalogue: Boolean = false) : super(Bundle().apply { - putLong(MANGA_EXTRA, manga?.id!!) + putLong(MANGA_EXTRA, manga?.id ?: 0) putBoolean(FROM_CATALOGUE_EXTRA, fromCatalogue) }) { this.manga = manga diff --git a/app/src/main/res/layout/catalogue_main_controller_card_item.xml b/app/src/main/res/layout/catalogue_main_controller_card_item.xml index 9d06cd7d2..14954bc50 100644 --- a/app/src/main/res/layout/catalogue_main_controller_card_item.xml +++ b/app/src/main/res/layout/catalogue_main_controller_card_item.xml @@ -14,25 +14,22 @@ + app:layout_constraintTop_toTopOf="parent" + tools:src="@mipmap/ic_launcher_round" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/extension_card_item.xml b/app/src/main/res/layout/extension_card_item.xml index 6acbe21ba..3d25905a6 100644 --- a/app/src/main/res/layout/extension_card_item.xml +++ b/app/src/main/res/layout/extension_card_item.xml @@ -14,14 +14,15 @@ + tools:src="@mipmap/ic_launcher_round" />