mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 21:31:47 +01:00
Sort extensions by package name. Minor changes to extension installer
This commit is contained in:
parent
eb8479ac9a
commit
c1845aec83
@ -1,8 +1,12 @@
|
|||||||
package eu.kanade.tachiyomi.extension.util
|
package eu.kanade.tachiyomi.extension.util
|
||||||
|
|
||||||
import android.app.DownloadManager
|
import android.app.DownloadManager
|
||||||
import android.content.*
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import com.jakewharton.rxrelay.PublishRelay
|
import com.jakewharton.rxrelay.PublishRelay
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
@ -74,7 +78,7 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
// Force an error if the download takes more than 3 minutes
|
// Force an error if the download takes more than 3 minutes
|
||||||
.mergeWith(Observable.timer(3, TimeUnit.MINUTES).map { InstallStep.Error })
|
.mergeWith(Observable.timer(3, TimeUnit.MINUTES).map { InstallStep.Error })
|
||||||
// Force an error if the install process takes more than 10 seconds
|
// Force an error if the install process takes more than 10 seconds
|
||||||
.flatMap { timeoutWhenInstalling(it) }
|
.flatMap { Observable.just(it).mergeWith(timeoutWhenInstalling(it)) }
|
||||||
// Stop when the application is installed or errors
|
// Stop when the application is installed or errors
|
||||||
.takeUntil { it.isCompleted() }
|
.takeUntil { it.isCompleted() }
|
||||||
// Always notify on main thread
|
// Always notify on main thread
|
||||||
@ -121,13 +125,10 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
* @param currentStep The current step of the installation process.
|
* @param currentStep The current step of the installation process.
|
||||||
*/
|
*/
|
||||||
private fun timeoutWhenInstalling(currentStep: InstallStep): Observable<InstallStep> {
|
private fun timeoutWhenInstalling(currentStep: InstallStep): Observable<InstallStep> {
|
||||||
return if (currentStep == InstallStep.Installing) {
|
return Observable.just(currentStep)
|
||||||
Observable.timer(10, TimeUnit.SECONDS)
|
.filter { it == InstallStep.Installing }
|
||||||
.map { InstallStep.Error }
|
.delay(10, TimeUnit.SECONDS)
|
||||||
.startWith(currentStep)
|
.map { InstallStep.Error }
|
||||||
} else {
|
|
||||||
Observable.just(currentStep)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,13 +234,9 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Due to a bug in older Android versions (L and M at least), the installer can't open
|
// Due to a bug in Android versions prior to N, the installer can't open files that do
|
||||||
// files that do not contain the apk extension, even if you specify the correct MIME.
|
// not contain the extension in the path, even if you specify the correct MIME.
|
||||||
// We workaround it by querying the actual file path and using the file provider when
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
// it fails.
|
|
||||||
try {
|
|
||||||
installApk(uri)
|
|
||||||
} catch (_: ActivityNotFoundException) {
|
|
||||||
val query = DownloadManager.Query().setFilterById(id)
|
val query = DownloadManager.Query().setFilterById(id)
|
||||||
downloadManager.query(query).use { cursor ->
|
downloadManager.query(query).use { cursor ->
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
@ -249,6 +246,8 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
installApk(uriCompat)
|
installApk(uriCompat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
installApk(uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ open class ExtensionPresenter(
|
|||||||
|
|
||||||
val items = mutableListOf<ExtensionItem>()
|
val items = mutableListOf<ExtensionItem>()
|
||||||
|
|
||||||
val installedSorted = installed.sortedWith(compareBy({ !it.hasUpdate }, { it.name }))
|
val installedSorted = installed.sortedWith(compareBy({ !it.hasUpdate }, { it.pkgName }))
|
||||||
val untrustedSorted = untrusted.sortedBy { it.name }
|
val untrustedSorted = untrusted.sortedBy { it.pkgName }
|
||||||
val availableSorted = available
|
val availableSorted = available
|
||||||
// Filter out already installed extensions
|
// Filter out already installed extensions
|
||||||
.filter { avail -> installed.none { it.pkgName == avail.pkgName }
|
.filter { avail -> installed.none { it.pkgName == avail.pkgName }
|
||||||
&& untrusted.none { it.pkgName == avail.pkgName } }
|
&& untrusted.none { it.pkgName == avail.pkgName } }
|
||||||
.sortedBy { it.name }
|
.sortedBy { it.pkgName }
|
||||||
|
|
||||||
if (installedSorted.isNotEmpty() || untrustedSorted.isNotEmpty()) {
|
if (installedSorted.isNotEmpty() || untrustedSorted.isNotEmpty()) {
|
||||||
val header = ExtensionGroupItem(true, installedSorted.size + untrustedSorted.size)
|
val header = ExtensionGroupItem(true, installedSorted.size + untrustedSorted.size)
|
||||||
|
Loading…
Reference in New Issue
Block a user