mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 03:19:18 +01:00
Update all extension button now runs extension job instead of throwing all exts into the dl queue
This commit is contained in:
parent
9eef1b48a8
commit
b3d05d50fa
@ -1,11 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.ui.extension
|
package eu.kanade.tachiyomi.ui.extension
|
||||||
|
|
||||||
import android.content.pm.PackageInstaller
|
import android.content.pm.PackageInstaller
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import eu.kanade.tachiyomi.extension.ExtensionInstallService
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionsChangedListener
|
import eu.kanade.tachiyomi.extension.ExtensionsChangedListener
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
@ -300,31 +302,37 @@ class ExtensionBottomPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun installExtension(extension: Extension.Available) {
|
fun installExtension(extension: Extension.Available) {
|
||||||
if (isNotMIUIOptimized()) {
|
presenterScope.launch {
|
||||||
presenterScope.launch {
|
extensionManager.installExtension(
|
||||||
extensionManager.installExtension(ExtensionManager.ExtensionInfo(extension), presenterScope)
|
ExtensionManager.ExtensionInfo(extension),
|
||||||
.launchIn(this)
|
presenterScope
|
||||||
}
|
)
|
||||||
|
.launchIn(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateExtension(extension: Extension.Installed) {
|
fun updateExtension(extension: Extension.Installed) {
|
||||||
if (isNotMIUIOptimized()) {
|
val availableExt =
|
||||||
val availableExt =
|
extensionManager.availableExtensions.find { it.pkgName == extension.pkgName } ?: return
|
||||||
extensionManager.availableExtensions.find { it.pkgName == extension.pkgName } ?: return
|
installExtension(availableExt)
|
||||||
presenterScope.launch {
|
|
||||||
extensionManager.installExtension(ExtensionManager.ExtensionInfo(availableExt), presenterScope)
|
|
||||||
.launchIn(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isNotMIUIOptimized(): Boolean {
|
fun updateExtensions(extensions: List<Extension.Installed>) {
|
||||||
// if (MiuiUtil.isMiui() && !MiuiUtil.isMiuiOptimizationDisabled()) {
|
if (extensions.isEmpty()) return
|
||||||
// preferences.context.toast(R.string.extensions_miui_warning, Toast.LENGTH_LONG)
|
val context = bottomSheet.context
|
||||||
// return false
|
extensions.forEach {
|
||||||
// }
|
val pkgName = it.pkgName
|
||||||
return true
|
currentDownloads[pkgName] = InstallStep.Pending to null
|
||||||
|
val item = updateInstallStep(it, InstallStep.Pending, null) ?: return@forEach
|
||||||
|
bottomSheet.downloadUpdate(item)
|
||||||
|
}
|
||||||
|
val intent = ExtensionInstallService.jobIntent(
|
||||||
|
bottomSheet.context,
|
||||||
|
extensions.mapNotNull { extension ->
|
||||||
|
extensionManager.availableExtensions.find { it.pkgName == extension.pkgName }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uninstallExtension(pkgName: String) {
|
fun uninstallExtension(pkgName: String) {
|
||||||
|
@ -235,15 +235,18 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
fun updateAllExtensions(position: Int) {
|
fun updateAllExtensions(position: Int) {
|
||||||
val header = (extAdapter?.getSectionHeader(position)) as? ExtensionGroupItem ?: return
|
val header = (extAdapter?.getSectionHeader(position)) as? ExtensionGroupItem ?: return
|
||||||
val items = extAdapter?.getSectionItemPositions(header)
|
val items = extAdapter?.getSectionItemPositions(header)
|
||||||
items?.forEach {
|
val extensions = items?.mapNotNull {
|
||||||
val extItem = (extAdapter?.getItem(it) as? ExtensionItem) ?: return
|
val extItem = (extAdapter?.getItem(it) as? ExtensionItem) ?: return
|
||||||
val extension = (extAdapter?.getItem(it) as? ExtensionItem)?.extension ?: return
|
val extension = (extAdapter?.getItem(it) as? ExtensionItem)?.extension ?: return
|
||||||
if (extItem.installStep == null &&
|
if (extItem.installStep == null &&
|
||||||
extension is Extension.Installed && extension.hasUpdate
|
extension is Extension.Installed && extension.hasUpdate
|
||||||
) {
|
) {
|
||||||
presenter.updateExtension(extension)
|
extension
|
||||||
|
} else {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}.orEmpty()
|
||||||
|
presenter.updateExtensions(extensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(view: View?, position: Int): Boolean {
|
override fun onItemClick(view: View?, position: Int): Boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user