mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Improve: Use single Installer instance in whole app
This commit is contained in:
parent
8b7294d467
commit
bd55becfc9
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -19,7 +19,6 @@ import com.looker.droidify.R
|
||||
import com.looker.droidify.content.ProductPreferences
|
||||
import com.looker.droidify.database.Database
|
||||
import com.looker.droidify.entity.*
|
||||
import com.looker.droidify.installer.AppInstaller
|
||||
import com.looker.droidify.service.Connection
|
||||
import com.looker.droidify.service.DownloadService
|
||||
import com.looker.droidify.utility.RxUtils
|
||||
@ -358,13 +357,9 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||
}
|
||||
(recyclerView?.adapter as? ProductAdapter)?.setStatus(status)
|
||||
if (state is DownloadService.State.Success && isResumed) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
state.consume()
|
||||
AppInstaller
|
||||
.getInstance(context)?.defaultInstaller?.install(
|
||||
"",
|
||||
state.release.cacheFileName
|
||||
)
|
||||
screenActivity.defaultInstaller?.install(state.release.cacheFileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -411,8 +406,8 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||
)
|
||||
}
|
||||
ProductAdapter.Action.UNINSTALL -> {
|
||||
lifecycleScope.launch {
|
||||
AppInstaller.getInstance(context)?.defaultInstaller?.uninstall(packageName)
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
screenActivity.defaultInstaller?.uninstall(packageName)
|
||||
}
|
||||
Unit
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
return supportFragmentManager.findFragmentById(R.id.main_content)
|
||||
}
|
||||
|
||||
val defaultInstaller = AppInstaller.getInstance(this)?.defaultInstaller
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(Preferences[Preferences.Key.Theme].getResId(resources.configuration))
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -218,12 +220,9 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
is SpecialIntent.Install -> {
|
||||
val packageName = specialIntent.packageName
|
||||
if (!packageName.isNullOrEmpty()) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
specialIntent.cacheFileName?.let {
|
||||
AppInstaller
|
||||
.getInstance(
|
||||
this@ScreenActivity
|
||||
)?.defaultInstaller?.install(packageName, it)
|
||||
defaultInstaller?.install(packageName, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user