Improve: Use single Installer instance in whole app

This commit is contained in:
LooKeR
2021-11-16 13:00:15 +05:30
parent 8b7294d467
commit bd55becfc9
6 changed files with 26 additions and 24 deletions

View File

@ -12,17 +12,15 @@ abstract class AppInstaller {
fun getInstance(context: Context?): AppInstaller? {
if (INSTANCE == null) {
synchronized(AppInstaller::class.java) {
if (INSTANCE == null) {
context?.let {
INSTANCE = object : AppInstaller() {
override val defaultInstaller: BaseInstaller
get() {
return when (rootInstallerEnabled) {
false -> DefaultInstaller(it)
true -> RootInstaller(it)
}
context?.let {
INSTANCE = object : AppInstaller() {
override val defaultInstaller: BaseInstaller
get() {
return when (rootInstallerEnabled) {
false -> DefaultInstaller(it)
true -> RootInstaller(it)
}
}
}
}
}
}

View File

@ -11,6 +11,10 @@ import kotlinx.coroutines.withContext
import java.io.File
class DefaultInstaller(context: Context) : BaseInstaller(context) {
override suspend fun install(cacheFileName: String) {
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
mDefaultInstaller(cacheFile)
}
override suspend fun install(packageName: String, cacheFileName: String) {
val cacheFile = Cache.getReleaseFile(context, cacheFileName)

View File

@ -3,6 +3,8 @@ package com.looker.droidify.installer
import java.io.File
interface InstallationEvents {
suspend fun install(cacheFileName: String)
suspend fun install(packageName: String, cacheFileName: String)
suspend fun install(packageName: String, cacheFile: File)

View File

@ -11,6 +11,10 @@ import kotlinx.coroutines.withContext
import java.io.File
class RootInstaller(context: Context) : BaseInstaller(context) {
override suspend fun install(cacheFileName: String) {
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
mRootInstaller(cacheFile)
}
override suspend fun install(packageName: String, cacheFileName: String) {
val cacheFile = Cache.getReleaseFile(context, cacheFileName)