mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-05 15:01:01 +00:00
coroutine fixes
This commit is contained in:
parent
ac4cc3ff7a
commit
dcafca2230
6 changed files with 30 additions and 79 deletions
|
@ -77,6 +77,8 @@ class HomeFragment : Home(), View.OnClickListener {
|
|||
true
|
||||
}
|
||||
|
||||
binding.homeRefresh.isRefreshing = true
|
||||
|
||||
with(binding.includeChangelogsLayout) {
|
||||
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
|
||||
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -23,17 +22,10 @@ class ManagerChangelogFragment : Fragment() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.manager_changelog)
|
||||
|
||||
var baseUrl = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("install_url", InternetTools.baseUrl)
|
||||
baseUrl = baseUrl?.trimEnd('/')
|
||||
|
||||
val changelog = InternetTools.getObjectFromJson("$baseUrl/manager.json", "changelog");
|
||||
changelogTxt.text = changelog
|
||||
val changelog = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "changelog")
|
||||
view.findViewById<TextView>(R.id.manager_changelog).text = changelog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -25,17 +23,12 @@ class MicrogChangelogFragment : Fragment() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.microg_changelog)
|
||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", InternetTools.baseUrl)
|
||||
|
||||
var baseUrl = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("install_url", InternetTools.baseUrl)
|
||||
baseUrl = baseUrl?.trimEnd('/')
|
||||
|
||||
var changelog = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog");
|
||||
changelogTxt.text = changelog
|
||||
val changelog = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog")
|
||||
view.findViewById<TextView>(R.id.vanced_changelog).text = changelog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -10,7 +9,6 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
|
@ -25,52 +23,14 @@ class VancedChangelogFragment : Fragment() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val context = context
|
||||
val appContext = activity?.applicationContext
|
||||
val application = activity?.application
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.vanced_changelog)
|
||||
val vancedVersion = activity?.let { InternetTools.getJsonString("vanced.json", "version", it) }
|
||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", InternetTools.baseUrl)
|
||||
|
||||
// Not very clean code, I know.
|
||||
// This is also now giving you the changelog of the currently installed version.
|
||||
// Should probably give the changelog of the newest version available?
|
||||
if (context != null && application != null) {
|
||||
val variant = PreferenceManager.getDefaultSharedPreferences(appContext)
|
||||
.getString("vanced_variant", "nonroot")
|
||||
|
||||
val vancedPkgName: String =
|
||||
if (variant== "root") {
|
||||
"com.google.android.youtube"
|
||||
} else {
|
||||
"com.vanced.android.youtube"
|
||||
}
|
||||
|
||||
val vancedInstalled = (PackageHelper.isPackageInstalled(vancedPkgName, application.packageManager))
|
||||
var vancedVersion = getPkgInfo(vancedInstalled, vancedPkgName, application)
|
||||
vancedVersion = vancedVersion.replace('.', '_')
|
||||
|
||||
InternetTools.getJsonString("vanced.json", "version", context)
|
||||
var baseUrl = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("install_url", InternetTools.baseUrl)
|
||||
baseUrl = baseUrl?.trimEnd('/')
|
||||
|
||||
val changelog = InternetTools.getObjectFromJson("$baseUrl/changelog/$vancedVersion.json", "message");
|
||||
changelogTxt.text = changelog
|
||||
}
|
||||
else {
|
||||
changelogTxt.text = "No changelog..."
|
||||
}
|
||||
val changelog = InternetTools.getObjectFromJson("$baseUrl/changelog/$vancedVersion.json", "message");
|
||||
view.findViewById<TextView>(R.id.vanced_changelog).text = changelog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPkgInfo(toCheck: Boolean, pkg: String, application: Application): String {
|
||||
return if (toCheck) {
|
||||
application.packageManager.getPackageInfo(pkg, 0).versionName
|
||||
} else {
|
||||
application.getString(R.string.unavailable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.github.kittinunf.fuel.httpGet
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.*
|
||||
|
||||
|
@ -35,18 +36,23 @@ class VancedLanguageSelectionFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
runBlocking {
|
||||
loadBoxes(view.findViewById(R.id.lang_button_ll))
|
||||
launch {
|
||||
loadBoxes(view.findViewById(R.id.lang_button_ll))
|
||||
}
|
||||
}
|
||||
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
||||
runBlocking {
|
||||
val chosenLangs = mutableListOf("en")
|
||||
for (lang in getLangs()!!) {
|
||||
if (view.findViewWithTag<CheckBox>(lang).isChecked) {
|
||||
chosenLangs.add(lang)
|
||||
launch {
|
||||
val chosenLangs = mutableListOf("en")
|
||||
for (lang in getLangs()!!) {
|
||||
if (view.findViewWithTag<CheckBox>(lang).isChecked) {
|
||||
chosenLangs.add(lang)
|
||||
}
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit()
|
||||
?.putString("lang", chosenLangs.joinToString())?.apply()
|
||||
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit()?.putString("lang", chosenLangs.joinToString())?.apply()
|
||||
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,8 +55,6 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
|||
|
||||
val nonrootModeSelected: Boolean = variant == "nonroot"
|
||||
|
||||
val expanded = ObservableField<Boolean>()
|
||||
|
||||
val fetching = ObservableField<Boolean>()
|
||||
|
||||
val shouldBeDisabled = ObservableField<Boolean>()
|
||||
|
@ -77,20 +75,20 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
|||
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(microgVersionCode.get()!!, microgInstalledVersionCode.get()!!, getApplication()))
|
||||
microgInstallButtonIcon.set(compareIntDrawable(microgVersionCode.get()!!, microgInstalledVersionCode.get()!!, getApplication()))
|
||||
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
|
||||
vancedInstallButtonIcon.set(
|
||||
if (shouldBeDisabled.get()!!) {
|
||||
null
|
||||
} else
|
||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
|
||||
)
|
||||
vancedInstallButtonTxt.set(
|
||||
if (shouldBeDisabled.get()!!) {
|
||||
getApplication<Application>().getString(R.string.no_microg)
|
||||
} else
|
||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
|
||||
)
|
||||
fetching.set(false)
|
||||
}
|
||||
|
@ -175,8 +173,8 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
|||
}
|
||||
|
||||
init {
|
||||
expanded.set(false)
|
||||
fetchData()
|
||||
//expanded.set(false)
|
||||
//fetchData()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue