mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-06 23:41:00 +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
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.homeRefresh.isRefreshing = true
|
||||||
|
|
||||||
with(binding.includeChangelogsLayout) {
|
with(binding.includeChangelogsLayout) {
|
||||||
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
|
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
|
||||||
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.InternetTools
|
import com.vanced.manager.utils.InternetTools
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -23,17 +22,10 @@ class ManagerChangelogFragment : Fragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
launch {
|
launch {
|
||||||
val changelogTxt = view.findViewById<TextView>(R.id.manager_changelog)
|
val changelog = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "changelog")
|
||||||
|
view.findViewById<TextView>(R.id.manager_changelog).text = 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.vanced.manager.ui.fragments
|
package com.vanced.manager.ui.fragments
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.InputType
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -25,17 +23,12 @@ class MicrogChangelogFragment : Fragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
launch {
|
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)
|
val changelog = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog")
|
||||||
.getString("install_url", InternetTools.baseUrl)
|
view.findViewById<TextView>(R.id.vanced_changelog).text = changelog
|
||||||
baseUrl = baseUrl?.trimEnd('/')
|
|
||||||
|
|
||||||
var changelog = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog");
|
|
||||||
changelogTxt.text = changelog
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.vanced.manager.ui.fragments
|
package com.vanced.manager.ui.fragments
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -10,7 +9,6 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.InternetTools
|
import com.vanced.manager.utils.InternetTools
|
||||||
import com.vanced.manager.utils.PackageHelper
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
|
@ -25,52 +23,14 @@ class VancedChangelogFragment : Fragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val context = context
|
|
||||||
val appContext = activity?.applicationContext
|
|
||||||
val application = activity?.application
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
launch {
|
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.
|
val changelog = InternetTools.getObjectFromJson("$baseUrl/changelog/$vancedVersion.json", "message");
|
||||||
// This is also now giving you the changelog of the currently installed version.
|
view.findViewById<TextView>(R.id.vanced_changelog).text = changelog
|
||||||
// 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..."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.google.android.material.button.MaterialButton
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -35,18 +36,23 @@ class VancedLanguageSelectionFragment : Fragment() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
runBlocking {
|
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 {
|
view.findViewById<MaterialButton>(R.id.vanced_install_finish).setOnClickListener {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val chosenLangs = mutableListOf("en")
|
launch {
|
||||||
for (lang in getLangs()!!) {
|
val chosenLangs = mutableListOf("en")
|
||||||
if (view.findViewWithTag<CheckBox>(lang).isChecked) {
|
for (lang in getLangs()!!) {
|
||||||
chosenLangs.add(lang)
|
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 nonrootModeSelected: Boolean = variant == "nonroot"
|
||||||
|
|
||||||
val expanded = ObservableField<Boolean>()
|
|
||||||
|
|
||||||
val fetching = ObservableField<Boolean>()
|
val fetching = ObservableField<Boolean>()
|
||||||
|
|
||||||
val shouldBeDisabled = ObservableField<Boolean>()
|
val shouldBeDisabled = ObservableField<Boolean>()
|
||||||
|
@ -77,20 +75,20 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||||
microgVersionCode.set(getJsonInt("microg.json", "versionCode", getApplication()))
|
microgVersionCode.set(getJsonInt("microg.json", "versionCode", getApplication()))
|
||||||
vancedInstalledVersionCode.set(getPkgVerCode(vancedInstalled.get()!!, vancedPkgName))
|
vancedInstalledVersionCode.set(getPkgVerCode(vancedInstalled.get()!!, vancedPkgName))
|
||||||
microgInstalledVersionCode.set(getPkgVerCode(microgInstalled.get()!!, "com.mgoogle.android.gms"))
|
microgInstalledVersionCode.set(getPkgVerCode(microgInstalled.get()!!, "com.mgoogle.android.gms"))
|
||||||
microgInstallButtonTxt.set(compareInt(microgVersionCode.get()!!, microgInstalledVersionCode.get()!!, getApplication()))
|
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||||
microgInstallButtonIcon.set(compareIntDrawable(microgVersionCode.get()!!, microgInstalledVersionCode.get()!!, getApplication()))
|
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
|
||||||
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
|
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
|
||||||
vancedInstallButtonIcon.set(
|
vancedInstallButtonIcon.set(
|
||||||
if (shouldBeDisabled.get()!!) {
|
if (shouldBeDisabled.get()!!) {
|
||||||
null
|
null
|
||||||
} else
|
} else
|
||||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
compareIntDrawable(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
|
||||||
)
|
)
|
||||||
vancedInstallButtonTxt.set(
|
vancedInstallButtonTxt.set(
|
||||||
if (shouldBeDisabled.get()!!) {
|
if (shouldBeDisabled.get()!!) {
|
||||||
getApplication<Application>().getString(R.string.no_microg)
|
getApplication<Application>().getString(R.string.no_microg)
|
||||||
} else
|
} else
|
||||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
compareInt(vancedInstalledVersionCode.get()!!, vancedVersionCode.get()!!, getApplication())
|
||||||
)
|
)
|
||||||
fetching.set(false)
|
fetching.set(false)
|
||||||
}
|
}
|
||||||
|
@ -175,8 +173,8 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
expanded.set(false)
|
//expanded.set(false)
|
||||||
fetchData()
|
//fetchData()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue