diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 21f78ab2d0..e77f16d88c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -1,20 +1,19 @@ package eu.kanade.tachiyomi.extension import android.content.Context -import android.content.pm.PackageInstaller import android.graphics.drawable.Drawable import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.model.Extension -import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver import eu.kanade.tachiyomi.extension.util.ExtensionInstaller import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.ui.extension.ExtensionIntallInfo import eu.kanade.tachiyomi.util.system.launchNow import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async @@ -239,7 +238,7 @@ class ExtensionManager( * * @param extension The extension to be installed. */ - fun installExtension(extension: Extension.Available): Observable> { + fun installExtension(extension: Extension.Available): Observable { return installer.downloadAndInstall(api.getApkUrl(extension), extension) } @@ -250,7 +249,7 @@ class ExtensionManager( * * @param extension The extension to be updated. */ - fun updateExtension(extension: Extension.Installed): Observable> { + fun updateExtension(extension: Extension.Installed): Observable { val availableExt = availableExtensions.find { it.pkgName == extension.pkgName } ?: return Observable.empty() return installExtension(availableExt) 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 846c353777..9b2ceda0d7 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 @@ -12,6 +12,7 @@ import androidx.core.net.toUri import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep +import eu.kanade.tachiyomi.ui.extension.ExtensionIntallInfo import eu.kanade.tachiyomi.util.storage.getUriCompat import rx.Observable import rx.android.schedulers.AndroidSchedulers @@ -110,7 +111,7 @@ internal class ExtensionInstaller(private val context: Context) { * * @param id The id of the download to poll. */ - private fun pollStatus(id: Long): Observable> { + private fun pollStatus(id: Long): Observable { val query = DownloadManager.Query().setFilterById(id) return Observable.interval(0, 1, TimeUnit.SECONDS) @@ -132,15 +133,15 @@ internal class ExtensionInstaller(private val context: Context) { DownloadManager.STATUS_RUNNING -> InstallStep.Downloading else -> return@flatMap Observable.empty() } - Observable.just(step to null as PackageInstaller.SessionInfo?) + Observable.just(ExtensionIntallInfo(step, null)) } .doOnError { Timber.e(it) } } - private fun pollInstallStatus(id: Long): Observable> { - return Observable.interval(0, 250, TimeUnit.MILLISECONDS) + private fun pollInstallStatus(id: Long): Observable { + return Observable.interval(0, 500, TimeUnit.MILLISECONDS) .flatMap { val sessionId = downloadInstallerMap[id] ?: return@flatMap Observable.empty() val session = context.packageManager.packageInstaller.getSessionInfo(sessionId) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt index 82183e3ddf..bb286760fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt @@ -30,6 +30,7 @@ import uy.kohesive.injekt.api.get typealias ExtensionTuple = Triple, List, List> +typealias ExtensionIntallInfo = Pair /** * Presenter of [ExtensionBottomSheet]. @@ -48,7 +49,7 @@ class ExtensionBottomPresenter( var mangaItems = hashMapOf>() private set - private var currentDownloads = hashMapOf() + private var currentDownloads = hashMapOf() private val sourceManager: SourceManager = Injekt.get() @@ -247,8 +248,8 @@ class ExtensionBottomPresenter( extensionManager.updateExtension(extension).subscribeToInstallUpdate(extension) } - private fun Observable>.subscribeToInstallUpdate(extension: Extension) { - this.doOnNext { currentDownloads[extension.pkgName] = it.first } + private fun Observable.subscribeToInstallUpdate(extension: Extension) { + this.doOnNext { currentDownloads[extension.pkgName] = it } .doOnUnsubscribe { currentDownloads.remove(extension.pkgName) } .map { state -> updateInstallStep(extension, state.first, state.second) } .subscribe { item -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt index 2266a60cd2..32d102fe38 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt @@ -25,6 +25,12 @@ data class ExtensionItem( ) : AbstractSectionableItem(header) { + constructor( + extension: Extension, + header: ExtensionGroupItem? = null, + installInfo: ExtensionIntallInfo? + ) : this(extension, header, installInfo?.first, installInfo?.second) + val sessionProgress: Int? get() = (session?.progress?.times(100)?.toInt())