mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 04:09:18 +01:00
Using typealias for extension session pair
also fix issue with progress flashing away after selecting install from package installer popup Also setting the rate to 500ms for install status
This commit is contained in:
parent
c8049b2307
commit
0b9754c5fa
@ -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<Pair<InstallStep, PackageInstaller.SessionInfo?>> {
|
||||
fun installExtension(extension: Extension.Available): Observable<ExtensionIntallInfo> {
|
||||
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<Pair<InstallStep, PackageInstaller.SessionInfo?>> {
|
||||
fun updateExtension(extension: Extension.Installed): Observable<ExtensionIntallInfo> {
|
||||
val availableExt = availableExtensions.find { it.pkgName == extension.pkgName }
|
||||
?: return Observable.empty()
|
||||
return installExtension(availableExt)
|
||||
|
@ -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<Pair<InstallStep, PackageInstaller.SessionInfo?>> {
|
||||
private fun pollStatus(id: Long): Observable<ExtensionIntallInfo> {
|
||||
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<Pair<InstallStep, PackageInstaller.SessionInfo?>> {
|
||||
return Observable.interval(0, 250, TimeUnit.MILLISECONDS)
|
||||
private fun pollInstallStatus(id: Long): Observable<ExtensionIntallInfo> {
|
||||
return Observable.interval(0, 500, TimeUnit.MILLISECONDS)
|
||||
.flatMap {
|
||||
val sessionId = downloadInstallerMap[id] ?: return@flatMap Observable.empty()
|
||||
val session = context.packageManager.packageInstaller.getSessionInfo(sessionId)
|
||||
|
@ -30,6 +30,7 @@ import uy.kohesive.injekt.api.get
|
||||
|
||||
typealias ExtensionTuple =
|
||||
Triple<List<Extension.Installed>, List<Extension.Untrusted>, List<Extension.Available>>
|
||||
typealias ExtensionIntallInfo = Pair<InstallStep, PackageInstaller.SessionInfo?>
|
||||
|
||||
/**
|
||||
* Presenter of [ExtensionBottomSheet].
|
||||
@ -48,7 +49,7 @@ class ExtensionBottomPresenter(
|
||||
var mangaItems = hashMapOf<Long, List<MangaItem>>()
|
||||
private set
|
||||
|
||||
private var currentDownloads = hashMapOf<String, InstallStep>()
|
||||
private var currentDownloads = hashMapOf<String, ExtensionIntallInfo>()
|
||||
|
||||
private val sourceManager: SourceManager = Injekt.get()
|
||||
|
||||
@ -247,8 +248,8 @@ class ExtensionBottomPresenter(
|
||||
extensionManager.updateExtension(extension).subscribeToInstallUpdate(extension)
|
||||
}
|
||||
|
||||
private fun Observable<Pair<InstallStep, PackageInstaller.SessionInfo?>>.subscribeToInstallUpdate(extension: Extension) {
|
||||
this.doOnNext { currentDownloads[extension.pkgName] = it.first }
|
||||
private fun Observable<ExtensionIntallInfo>.subscribeToInstallUpdate(extension: Extension) {
|
||||
this.doOnNext { currentDownloads[extension.pkgName] = it }
|
||||
.doOnUnsubscribe { currentDownloads.remove(extension.pkgName) }
|
||||
.map { state -> updateInstallStep(extension, state.first, state.second) }
|
||||
.subscribe { item ->
|
||||
|
@ -25,6 +25,12 @@ data class ExtensionItem(
|
||||
) :
|
||||
AbstractSectionableItem<ExtensionHolder, ExtensionGroupItem>(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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user