replaced runBlocking methods with coroutinescope
This commit is contained in:
parent
90f5d3a337
commit
e9c3e7aad5
|
@ -22,8 +22,9 @@ import com.vanced.manager.utils.AppUtils.isInstallationRunning
|
||||||
import com.vanced.manager.utils.InternetTools
|
import com.vanced.manager.utils.InternetTools
|
||||||
import com.vanced.manager.utils.PackageHelper
|
import com.vanced.manager.utils.PackageHelper
|
||||||
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
|
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@ -143,12 +144,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUpdates() {
|
private fun checkUpdates() {
|
||||||
runBlocking {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
launch {
|
if (InternetTools.isUpdateAvailable()) {
|
||||||
if (InternetTools.isUpdateAvailable()) {
|
val fm = supportFragmentManager
|
||||||
val fm = supportFragmentManager
|
UpdateCheckFragment().show(fm, "UpdateCheck")
|
||||||
UpdateCheckFragment().show(fm, "UpdateCheck")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
||||||
|
|
||||||
}.attach()
|
}.attach()
|
||||||
}
|
}
|
||||||
viewModel.fetchData()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
|
|
|
@ -37,9 +37,10 @@ class VancedLanguageSelectionFragment : Fragment() {
|
||||||
@ExperimentalStdlibApi
|
@ExperimentalStdlibApi
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
langs = runBlocking { getArrayFromJson("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json", "langs") }
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
langs = getArrayFromJson("${PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", baseUrl)}/vanced.json", "langs")
|
||||||
|
}
|
||||||
loadBoxes(view.findViewById(R.id.lang_button_ll))
|
loadBoxes(view.findViewById(R.id.lang_button_ll))
|
||||||
|
|
||||||
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
||||||
val chosenLangs = mutableListOf("en")
|
val chosenLangs = mutableListOf("en")
|
||||||
if (!langs.contains("null"))
|
if (!langs.contains("null"))
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
@ -19,8 +20,9 @@ import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.InternetTools.getJsonInt
|
import com.vanced.manager.utils.InternetTools.getJsonInt
|
||||||
import com.vanced.manager.utils.InternetTools.getJsonString
|
import com.vanced.manager.utils.InternetTools.getJsonString
|
||||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
|
|
||||||
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||||
|
|
||||||
|
@ -57,31 +59,33 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
||||||
|
|
||||||
val fetching = ObservableField<Boolean>()
|
val fetching = ObservableField<Boolean>()
|
||||||
|
|
||||||
val shouldBeDisabled = ObservableField<Boolean>()
|
private val shouldBeDisabled = ObservableField<Boolean>()
|
||||||
|
|
||||||
//this too
|
//this too
|
||||||
fun fetchData() {
|
fun fetchData() {
|
||||||
runBlocking {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
launch {
|
fetching.set(true)
|
||||||
fetching.set(true)
|
try {
|
||||||
Crowdin.forceUpdate(getApplication())
|
Crowdin.forceUpdate(getApplication())
|
||||||
vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
|
} catch (e: Exception) {
|
||||||
microgVersion.set(getJsonString("microg.json", "version", getApplication()))
|
Log.d("VMLocalisation", "Error: ", e)
|
||||||
microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm))
|
|
||||||
vancedInstalled.set(isPackageInstalled(vancedPkgName, pm))
|
|
||||||
vancedInstalledVersion.set(getPkgInfo(vancedInstalled.get()!!, vancedPkgName, getApplication()))
|
|
||||||
microgInstalledVersion.set(getPkgInfo(microgInstalled.get()!!, "com.mgoogle.android.gms", getApplication()))
|
|
||||||
vancedVersionCode.set(getJsonInt("vanced.json", "versionCode", getApplication()))
|
|
||||||
microgVersionCode.set(getJsonInt("microg.json", "versionCode", getApplication()))
|
|
||||||
vancedInstalledVersionCode.set(getPkgVerCode(vancedInstalled.get()!!, vancedPkgName))
|
|
||||||
microgInstalledVersionCode.set(getPkgVerCode(microgInstalled.get()!!, "com.mgoogle.android.gms"))
|
|
||||||
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
|
||||||
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
|
||||||
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
|
|
||||||
vancedInstallButtonIcon.set(compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
|
|
||||||
vancedInstallButtonTxt.set(compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
|
|
||||||
fetching.set(false)
|
|
||||||
}
|
}
|
||||||
|
vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
|
||||||
|
microgVersion.set(getJsonString("microg.json", "version", getApplication()))
|
||||||
|
microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm))
|
||||||
|
vancedInstalled.set(isPackageInstalled(vancedPkgName, pm))
|
||||||
|
vancedInstalledVersion.set(getPkgInfo(vancedInstalled.get()!!, vancedPkgName, getApplication()))
|
||||||
|
microgInstalledVersion.set(getPkgInfo(microgInstalled.get()!!, "com.mgoogle.android.gms", getApplication()))
|
||||||
|
vancedVersionCode.set(getJsonInt("vanced.json", "versionCode", getApplication()))
|
||||||
|
microgVersionCode.set(getJsonInt("microg.json", "versionCode", getApplication()))
|
||||||
|
vancedInstalledVersionCode.set(getPkgVerCode(vancedInstalled.get()!!, vancedPkgName))
|
||||||
|
microgInstalledVersionCode.set(getPkgVerCode(microgInstalled.get()!!, "com.mgoogle.android.gms"))
|
||||||
|
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||||
|
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||||
|
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
|
||||||
|
vancedInstallButtonIcon.set(compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
|
||||||
|
vancedInstallButtonTxt.set(compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication()))
|
||||||
|
fetching.set(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,4 +166,8 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
fetchData()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,9 +10,7 @@ import com.vanced.manager.R
|
||||||
import com.vanced.manager.core.downloader.*
|
import com.vanced.manager.core.downloader.*
|
||||||
import com.vanced.manager.core.installer.*
|
import com.vanced.manager.core.installer.*
|
||||||
import com.vanced.manager.ui.fragments.HomeFragment
|
import com.vanced.manager.ui.fragments.HomeFragment
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
|
|
||||||
object AppUtils {
|
object AppUtils {
|
||||||
|
|
||||||
|
@ -36,13 +34,11 @@ object AppUtils {
|
||||||
|
|
||||||
fun sendFailure(status: Int, context: Context) {
|
fun sendFailure(status: Int, context: Context) {
|
||||||
//Delay error broadcast until activity (and fragment) get back to the screen
|
//Delay error broadcast until activity (and fragment) get back to the screen
|
||||||
runBlocking {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
launch {
|
delay(500)
|
||||||
delay(500)
|
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
||||||
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
||||||
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue