mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-23 11:45:11 +00:00
replaced runBlocking methods with coroutinescope
This commit is contained in:
parent
90f5d3a337
commit
e9c3e7aad5
5 changed files with 45 additions and 41 deletions
|
@ -22,8 +22,9 @@ import com.vanced.manager.utils.AppUtils.isInstallationRunning
|
|||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
|
@ -143,14 +144,12 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun checkUpdates() {
|
||||
runBlocking {
|
||||
launch {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
if (InternetTools.isUpdateAvailable()) {
|
||||
val fm = supportFragmentManager
|
||||
UpdateCheckFragment().show(fm, "UpdateCheck")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
|
||||
}.attach()
|
||||
}
|
||||
viewModel.fetchData()
|
||||
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
|
|
|
@ -37,9 +37,10 @@ class VancedLanguageSelectionFragment : Fragment() {
|
|||
@ExperimentalStdlibApi
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
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))
|
||||
|
||||
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
||||
val chosenLangs = mutableListOf("en")
|
||||
if (!langs.contains("null"))
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
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.getJsonString
|
||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
|
@ -57,14 +59,17 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
|
||||
val fetching = ObservableField<Boolean>()
|
||||
|
||||
val shouldBeDisabled = ObservableField<Boolean>()
|
||||
private val shouldBeDisabled = ObservableField<Boolean>()
|
||||
|
||||
//this too
|
||||
fun fetchData() {
|
||||
runBlocking {
|
||||
launch {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
fetching.set(true)
|
||||
try {
|
||||
Crowdin.forceUpdate(getApplication())
|
||||
} catch (e: Exception) {
|
||||
Log.d("VMLocalisation", "Error: ", e)
|
||||
}
|
||||
vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
|
||||
microgVersion.set(getJsonString("microg.json", "version", getApplication()))
|
||||
microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm))
|
||||
|
@ -83,7 +88,6 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
fetching.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openMicrogSettings() {
|
||||
try {
|
||||
|
@ -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.installer.*
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
object AppUtils {
|
||||
|
||||
|
@ -36,15 +34,13 @@ object AppUtils {
|
|||
|
||||
fun sendFailure(status: Int, context: Context) {
|
||||
//Delay error broadcast until activity (and fragment) get back to the screen
|
||||
runBlocking {
|
||||
launch {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(500)
|
||||
val intent = Intent(HomeFragment.INSTALL_FAILED)
|
||||
intent.putExtra("errorMsg", getErrorMessage(status, context))
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getErrorMessage(status: Int, context: Context): String {
|
||||
return when (status) {
|
||||
|
|
Loading…
Reference in a new issue