mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-27 05:23:00 +00:00
replaced observable fields with livedata
This commit is contained in:
parent
620c96f83b
commit
ec92a8b415
16 changed files with 69 additions and 86 deletions
|
@ -31,11 +31,11 @@ class AppListAdapter(
|
||||||
|
|
||||||
inner class ListViewHolder(private val binding: ViewAppBinding) : RecyclerView.ViewHolder(binding.root) {
|
inner class ListViewHolder(private val binding: ViewAppBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
val appCard = binding.appCard
|
val appCard = binding.appCard
|
||||||
|
|
||||||
fun bind(position: Int) {
|
fun bind(position: Int) {
|
||||||
val dataModel = if (isRoot) rootDataModels[position] else dataModels[position]
|
val dataModel = if (isRoot) rootDataModels[position] else dataModels[position]
|
||||||
with(binding) {
|
with(binding) {
|
||||||
appName.text = dataModel?.appName
|
appName.text = dataModel?.appName
|
||||||
|
if (dataModel?.buttonTxt?.value != null) appInstallButton.text = dataModel.buttonTxt.value
|
||||||
dataModel?.buttonTxt?.observe(this@AppListAdapter.lifecycleOwner) {
|
dataModel?.buttonTxt?.observe(this@AppListAdapter.lifecycleOwner) {
|
||||||
appInstallButton.text = it
|
appInstallButton.text = it
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,14 @@ class AppListAdapter(
|
||||||
dataModel?.appPkg?.let { it1 -> viewModel.uninstallPackage(it1) }
|
dataModel?.appPkg?.let { it1 -> viewModel.uninstallPackage(it1) }
|
||||||
}
|
}
|
||||||
appUninstall.isVisible = dataModel?.isAppInstalled?.value == true
|
appUninstall.isVisible = dataModel?.isAppInstalled?.value == true
|
||||||
|
dataModel?.isAppInstalled?.observe(lifecycleOwner) {
|
||||||
|
appUninstall.isVisible = it
|
||||||
|
}
|
||||||
|
if (dataModel?.versionName?.value != null) appRemoteVersion.text = dataModel.versionName.value
|
||||||
dataModel?.versionName?.observe(this@AppListAdapter.lifecycleOwner) {
|
dataModel?.versionName?.observe(this@AppListAdapter.lifecycleOwner) {
|
||||||
appRemoteVersion.text = it
|
appRemoteVersion.text = it
|
||||||
}
|
}
|
||||||
|
if (dataModel?.installedVersionName?.value != null) appInstalledVersion.text = dataModel.installedVersionName.value
|
||||||
dataModel?.installedVersionName?.observe(this@AppListAdapter.lifecycleOwner) {
|
dataModel?.installedVersionName?.observe(this@AppListAdapter.lifecycleOwner) {
|
||||||
appInstalledVersion.text = it
|
appInstalledVersion.text = it
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ object MicrogDownloader {
|
||||||
private const val folderName = "microg"
|
private const val folderName = "microg"
|
||||||
|
|
||||||
fun downloadMicrog(context: Context) {
|
fun downloadMicrog(context: Context) {
|
||||||
val url = microg.get()?.string("url") ?: ""
|
val url = microg.value?.string("url") ?: ""
|
||||||
fuelDownload(url, folderName, fileName, context, onDownloadComplete = {
|
fuelDownload(url, folderName, fileName, context, onDownloadComplete = {
|
||||||
startMicrogInstall(context)
|
startMicrogInstall(context)
|
||||||
}, onError = {
|
}, onError = {
|
||||||
|
|
|
@ -29,8 +29,8 @@ object MusicDownloader {
|
||||||
|
|
||||||
fun downloadMusic(context: Context) {
|
fun downloadMusic(context: Context) {
|
||||||
val prefs = getDefaultSharedPreferences(context)
|
val prefs = getDefaultSharedPreferences(context)
|
||||||
version = prefs.getString("music_version", "latest")?.getLatestAppVersion(musicVersions.get()?.value ?: listOf(""))
|
version = prefs.getString("music_version", "latest")?.getLatestAppVersion(musicVersions.value?.value ?: listOf(""))
|
||||||
versionCode = music.get()?.int("versionCode")
|
versionCode = music.value?.int("versionCode")
|
||||||
variant = prefs.getString("vanced_variant", "nonroot")
|
variant = prefs.getString("vanced_variant", "nonroot")
|
||||||
baseurl = "${prefs.getInstallUrl()}/music/v$version"
|
baseurl = "${prefs.getInstallUrl()}/music/v$version"
|
||||||
folderName = "music/$variant"
|
folderName = "music/$variant"
|
||||||
|
|
|
@ -56,14 +56,14 @@ object VancedDownloader {
|
||||||
lang = it.split(", ").toMutableList()
|
lang = it.split(", ").toMutableList()
|
||||||
}
|
}
|
||||||
theme = prefs.getString("theme", "dark")
|
theme = prefs.getString("theme", "dark")
|
||||||
vancedVersion = defPrefs.getString("vanced_version", "latest")?.getLatestAppVersion(vancedVersions.get()?.value ?: listOf(""))
|
vancedVersion = defPrefs.getString("vanced_version", "latest")?.getLatestAppVersion(vancedVersions.value?.value ?: listOf(""))
|
||||||
themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme"
|
themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme"
|
||||||
hashUrl = "apks/v$vancedVersion/$variant/Theme/hash.json"
|
hashUrl = "apks/v$vancedVersion/$variant/Theme/hash.json"
|
||||||
//newInstaller = defPrefs.getBoolean("new_installer", false)
|
//newInstaller = defPrefs.getBoolean("new_installer", false)
|
||||||
arch = getArch()
|
arch = getArch()
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
vancedVersionCode = vanced.get()?.int("versionCode") ?: 0
|
vancedVersionCode = vanced.value?.int("versionCode") ?: 0
|
||||||
downloadSplits(context)
|
downloadSplits(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,18 @@ package com.vanced.manager.model
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.databinding.Observable
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.databinding.ObservableField
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
|
import com.vanced.manager.utils.Extensions.lifecycleOwner
|
||||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
open class DataModel(
|
open class DataModel(
|
||||||
private val jsonObject: ObservableField<JsonObject?>,
|
private val jsonObject: LiveData<JsonObject?>,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
val appPkg: String,
|
val appPkg: String,
|
||||||
val appName: String,
|
val appName: String,
|
||||||
|
@ -30,28 +30,32 @@ open class DataModel(
|
||||||
val buttonTxt = MutableLiveData<String>()
|
val buttonTxt = MutableLiveData<String>()
|
||||||
val changelog = MutableLiveData<String>()
|
val changelog = MutableLiveData<String>()
|
||||||
|
|
||||||
fun fetch() = CoroutineScope(Dispatchers.IO).launch {
|
private fun fetch() = CoroutineScope(Dispatchers.IO).launch {
|
||||||
val jobj = jsonObject.get()
|
val jobj = jsonObject.value
|
||||||
isAppInstalled.postValue(isPackageInstalled(appPkg, context.packageManager))
|
isAppInstalled.postValue(isPackageInstalled(appPkg, context.packageManager))
|
||||||
versionName.postValue(
|
|
||||||
jobj?.string("version")?.removeSuffix("-vanced") ?: context.getString(
|
|
||||||
R.string.unavailable
|
|
||||||
)
|
|
||||||
)
|
|
||||||
installedVersionName.postValue(getPkgVersionName(isAppInstalled.value, appPkg))
|
|
||||||
versionCode.postValue(jobj?.int("versionCode") ?: 0)
|
versionCode.postValue(jobj?.int("versionCode") ?: 0)
|
||||||
installedVersionCode.postValue(getPkgVersionCode(isAppInstalled.value, appPkg))
|
installedVersionCode.postValue(getPkgVersionCode(isAppInstalled.value, appPkg))
|
||||||
buttonTxt.postValue(compareInt(installedVersionCode.value, versionCode.value))
|
versionName.postValue(jobj?.string("version")?.removeSuffix("-vanced") ?: context.getString(
|
||||||
|
R.string.unavailable
|
||||||
|
))
|
||||||
|
installedVersionName.postValue(getPkgVersionName(isAppInstalled.value, appPkg))
|
||||||
changelog.postValue(jobj?.string("changelog") ?: context.getString(R.string.unavailable))
|
changelog.postValue(jobj?.string("changelog") ?: context.getString(R.string.unavailable))
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
fetch()
|
fetch()
|
||||||
jsonObject.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
|
with(context.lifecycleOwner()) {
|
||||||
override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
|
this?.let {
|
||||||
fetch()
|
jsonObject.observe(it) {
|
||||||
|
fetch()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
this?.let { versionCode.observe(it) { versionCode ->
|
||||||
|
installedVersionCode.observe(it) { installedVersionCode ->
|
||||||
|
buttonTxt.value = compareInt(installedVersionCode, versionCode)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPkgVersionName(toCheck: Boolean?, pkg: String): String {
|
private fun getPkgVersionName(toCheck: Boolean?, pkg: String): String {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||||
import com.crowdin.platform.Crowdin
|
import com.crowdin.platform.Crowdin
|
||||||
import com.crowdin.platform.LoadingStateListener
|
import com.crowdin.platform.LoadingStateListener
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
|
import com.vanced.manager.BuildConfig.VERSION_CODE
|
||||||
import com.vanced.manager.BuildConfig.ENABLE_CROWDIN_AUTH
|
import com.vanced.manager.BuildConfig.ENABLE_CROWDIN_AUTH
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.databinding.ActivityMainBinding
|
import com.vanced.manager.databinding.ActivityMainBinding
|
||||||
|
@ -25,13 +26,14 @@ import com.vanced.manager.ui.dialogs.URLChangeDialog
|
||||||
import com.vanced.manager.ui.fragments.HomeFragmentDirections
|
import com.vanced.manager.ui.fragments.HomeFragmentDirections
|
||||||
import com.vanced.manager.ui.fragments.SettingsFragmentDirections
|
import com.vanced.manager.ui.fragments.SettingsFragmentDirections
|
||||||
import com.vanced.manager.utils.Extensions.show
|
import com.vanced.manager.utils.Extensions.show
|
||||||
import com.vanced.manager.utils.InternetTools
|
import com.vanced.manager.utils.InternetTools.manager
|
||||||
import com.vanced.manager.utils.LanguageContextWrapper
|
import com.vanced.manager.utils.LanguageContextWrapper
|
||||||
import com.vanced.manager.utils.LanguageHelper.authCrowdin
|
import com.vanced.manager.utils.LanguageHelper.authCrowdin
|
||||||
import com.vanced.manager.utils.LanguageHelper.onActivityResult
|
import com.vanced.manager.utils.LanguageHelper.onActivityResult
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
lateinit var binding: ActivityMainBinding
|
lateinit var binding: ActivityMainBinding
|
||||||
|
@ -70,6 +72,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
initDialogs(intent.getBooleanExtra("firstLaunch", false))
|
initDialogs(intent.getBooleanExtra("firstLaunch", false))
|
||||||
|
manager.observe(this) {
|
||||||
|
if (manager.value?.int("versionCode") ?: 0 > VERSION_CODE) {
|
||||||
|
ManagerUpdateDialog.newInstance(false).show(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
@ -106,7 +113,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
navHost.navigate(HomeFragmentDirections.toSettingsFragment())
|
navHost.navigate(HomeFragmentDirections.toSettingsFragment())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.toolbar_update_manager -> {
|
R.id.toolbar_update_manager -> {
|
||||||
ManagerUpdateDialog.newInstance(false).show(supportFragmentManager, "manager_update")
|
ManagerUpdateDialog.newInstance(false).show(supportFragmentManager, "manager_update")
|
||||||
}
|
}
|
||||||
|
@ -175,14 +181,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkUpdates()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkUpdates() {
|
|
||||||
if (InternetTools.isUpdateAvailable()) {
|
|
||||||
ManagerUpdateDialog.newInstance(false).show(supportFragmentManager, "UpdateCheck")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,13 @@ import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
|
import com.vanced.manager.BuildConfig.VERSION_CODE
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.core.ui.base.BindingDialogFragment
|
import com.vanced.manager.core.ui.base.BindingDialogFragment
|
||||||
import com.vanced.manager.databinding.DialogManagerUpdateBinding
|
import com.vanced.manager.databinding.DialogManagerUpdateBinding
|
||||||
import com.vanced.manager.utils.DownloadHelper.downloadManager
|
import com.vanced.manager.utils.DownloadHelper.downloadManager
|
||||||
import com.vanced.manager.utils.DownloadHelper.downloadProgress
|
import com.vanced.manager.utils.DownloadHelper.downloadProgress
|
||||||
import com.vanced.manager.utils.InternetTools.isUpdateAvailable
|
import com.vanced.manager.utils.InternetTools.manager
|
||||||
|
|
||||||
class ManagerUpdateDialog : BindingDialogFragment<DialogManagerUpdateBinding>() {
|
class ManagerUpdateDialog : BindingDialogFragment<DialogManagerUpdateBinding>() {
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ class ManagerUpdateDialog : BindingDialogFragment<DialogManagerUpdateBinding>()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUpdates() {
|
private fun checkUpdates() {
|
||||||
if (isUpdateAvailable()) {
|
if (manager.value?.int("versionCode") ?: 0 > VERSION_CODE) {
|
||||||
binding.managerUpdatePatient.text = requireActivity().getString(R.string.please_be_patient)
|
binding.managerUpdatePatient.text = requireActivity().getString(R.string.please_be_patient)
|
||||||
downloadManager(requireActivity())
|
downloadManager(requireActivity())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -34,7 +34,7 @@ class MusicPreferencesDialog : BindingBottomSheetDialogFragment<DialogMusicPrefe
|
||||||
|
|
||||||
private fun bindData() {
|
private fun bindData() {
|
||||||
with(binding) {
|
with(binding) {
|
||||||
val musicVersionsConv = musicVersions.get()?.value?.reversed()?.convertToAppVersions()
|
val musicVersionsConv = musicVersions.value?.value?.reversed()?.convertToAppVersions()
|
||||||
musicInstallTitle.text = getString(R.string.app_installation_preferences, getString(R.string.music))
|
musicInstallTitle.text = getString(R.string.app_installation_preferences, getString(R.string.music))
|
||||||
musicVersion.text = getString(R.string.chosen_version, prefs.getString("music_version", "latest"))
|
musicVersion.text = getString(R.string.chosen_version, prefs.getString("music_version", "latest"))
|
||||||
openVersionSelector.setOnClickListener {
|
openVersionSelector.setOnClickListener {
|
||||||
|
|
|
@ -30,7 +30,7 @@ class VancedLanguageSelectionDialog : BindingBottomSheetDialogFragment<DialogVan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val langs = vanced.get()?.array<String>("langs")?.value
|
private val langs = vanced.value?.array<String>("langs")?.value
|
||||||
private val prefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
|
private val prefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
|
||||||
|
|
||||||
override fun binding(
|
override fun binding(
|
||||||
|
|
|
@ -44,7 +44,7 @@ class VancedPreferencesDialog : BindingBottomSheetDialogFragment<DialogVancedPre
|
||||||
val loc = Locale(lang)
|
val loc = Locale(lang)
|
||||||
showLang.add(loc.getDisplayLanguage(loc).capitalize(Locale.ROOT))
|
showLang.add(loc.getDisplayLanguage(loc).capitalize(Locale.ROOT))
|
||||||
}
|
}
|
||||||
val vancedVersionsConv = vancedVersions.get()?.value?.reversed()?.convertToAppVersions()
|
val vancedVersionsConv = vancedVersions.value?.value?.reversed()?.convertToAppVersions()
|
||||||
vancedInstallTitle.text = getString(R.string.app_installation_preferences, getString(R.string.vanced))
|
vancedInstallTitle.text = getString(R.string.app_installation_preferences, getString(R.string.vanced))
|
||||||
vancedTheme.text = getString(R.string.chosen_theme, installPrefs.getString("theme", "dark")?.convertToAppTheme(requireActivity()))
|
vancedTheme.text = getString(R.string.chosen_theme, installPrefs.getString("theme", "dark")?.convertToAppTheme(requireActivity()))
|
||||||
vancedVersion.text = getString(R.string.chosen_version, defPrefs.getString("vanced_version", "latest"))
|
vancedVersion.text = getString(R.string.chosen_version, defPrefs.getString("vanced_version", "latest"))
|
||||||
|
|
|
@ -60,7 +60,7 @@ class VancedThemeSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadButtons() = vanced.get()?.array<String>("themes")?.value?.map {theme ->
|
private fun loadButtons() = vanced.value?.array<String>("themes")?.value?.map {theme ->
|
||||||
ThemedMaterialRadioButton(requireActivity()).apply {
|
ThemedMaterialRadioButton(requireActivity()).apply {
|
||||||
text = theme.convertToAppTheme(requireActivity())
|
text = theme.convertToAppTheme(requireActivity())
|
||||||
tag = theme
|
tag = theme
|
||||||
|
|
|
@ -42,7 +42,7 @@ class AboutFragment : BindingFragment<FragmentAboutBinding>() {
|
||||||
AppInfoDialog.newInstance(
|
AppInfoDialog.newInstance(
|
||||||
appName = getString(R.string.app_name),
|
appName = getString(R.string.app_name),
|
||||||
appIcon = AppCompatResources.getDrawable(requireActivity(), R.mipmap.ic_launcher),
|
appIcon = AppCompatResources.getDrawable(requireActivity(), R.mipmap.ic_launcher),
|
||||||
changelog = manager.get()?.string("changelog")
|
changelog = manager.value?.string("changelog")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
|
||||||
private fun bindData() {
|
private fun bindData() {
|
||||||
requireActivity().title = getString(R.string.title_home)
|
requireActivity().title = getString(R.string.title_home)
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
with(binding) {
|
with (binding) {
|
||||||
homeRefresh.setOnRefreshListener { viewModel.fetchData() }
|
homeRefresh.setOnRefreshListener { viewModel.fetchData() }
|
||||||
tooltip = ViewTooltip
|
tooltip = ViewTooltip
|
||||||
.on(recyclerAppList)
|
.on(recyclerAppList)
|
||||||
|
@ -108,13 +108,11 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
localBroadcastManager.unregisterReceiver(broadcastReceiver)
|
localBroadcastManager.unregisterReceiver(broadcastReceiver)
|
||||||
tooltip.close()
|
tooltip.close()
|
||||||
//binding.mainTablayout.removeOnTabSelectedListener(tabListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
registerReceivers()
|
registerReceivers()
|
||||||
// binding.mainTablayout.addOnTabSelectedListener(tabListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||||
|
|
|
@ -7,33 +7,31 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.databinding.ObservableField
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||||
import com.beust.klaxon.JsonArray
|
import com.beust.klaxon.JsonArray
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.vanced.manager.BuildConfig
|
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.utils.AppUtils.generateChecksum
|
import com.vanced.manager.utils.AppUtils.generateChecksum
|
||||||
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object InternetTools {
|
object InternetTools {
|
||||||
|
|
||||||
private const val TAG = "VMNetTools"
|
private const val TAG = "VMNetTools"
|
||||||
|
|
||||||
var vanced = ObservableField<JsonObject?>()
|
var vanced = MutableLiveData<JsonObject?>()
|
||||||
var music = ObservableField<JsonObject?>()
|
var music = MutableLiveData<JsonObject?>()
|
||||||
var microg = ObservableField<JsonObject?>()
|
var microg = MutableLiveData<JsonObject?>()
|
||||||
var manager = ObservableField<JsonObject?>()
|
var manager = MutableLiveData<JsonObject?>()
|
||||||
|
|
||||||
var vancedVersions = ObservableField<JsonArray<String>>()
|
var vancedVersions = MutableLiveData<JsonArray<String>>()
|
||||||
var musicVersions = ObservableField<JsonArray<String>>()
|
var musicVersions = MutableLiveData<JsonArray<String>>()
|
||||||
|
|
||||||
//var braveTiers = ObservableField<JsonObject?>()
|
//var braveTiers = MutableLiveData<JsonObject?>()
|
||||||
|
|
||||||
fun openUrl(url: String, color: Int, context: Context) {
|
fun openUrl(url: String, color: Int, context: Context) {
|
||||||
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_custom_tabs", true)
|
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_custom_tabs", true)
|
||||||
|
@ -56,32 +54,20 @@ object InternetTools {
|
||||||
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||||
val minute = calendar.get(Calendar.MINUTE)
|
val minute = calendar.get(Calendar.MINUTE)
|
||||||
val second = calendar.get(Calendar.SECOND)
|
val second = calendar.get(Calendar.SECOND)
|
||||||
val latest = JsonHelper.getJson("$installUrl/latest.json?fetchTime=$hour$minute$second")
|
val fetchTime = "fetchTime=$hour$minute$second"
|
||||||
Log.d("test", "$installUrl/latest.json?fetchTime=$hour$minute$second")
|
val latest = JsonHelper.getJson("$installUrl/latest.json?$fetchTime")
|
||||||
val versions = JsonHelper.getJson("$installUrl/versions.json?fetchTime=${SimpleDateFormat("HHmmss", Locale.ROOT)}")
|
val versions = JsonHelper.getJson("$installUrl/versions.json?$fetchTime")
|
||||||
// braveTiers.apply {
|
// braveTiers.apply {
|
||||||
// set(getJson("$installUrl/sponsor.json"))
|
// set(getJson("$installUrl/sponsor.json"))
|
||||||
// notifyChange()
|
// notifyChange()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
vanced.apply {
|
vanced.postValue(latest?.obj("vanced"))
|
||||||
set(latest?.obj("vanced"))
|
vancedVersions.postValue(versions?.array("vanced") )
|
||||||
notifyChange()
|
music.postValue(latest?.obj("music"))
|
||||||
}
|
musicVersions.postValue(versions?.array("music"))
|
||||||
vancedVersions.set(versions?.array("vanced"))
|
microg.postValue(latest?.obj("microg"))
|
||||||
music.apply {
|
manager.postValue(latest?.obj("manager"))
|
||||||
set(latest?.obj("music"))
|
|
||||||
notifyChange()
|
|
||||||
}
|
|
||||||
musicVersions.set(versions?.array("music"))
|
|
||||||
microg.apply {
|
|
||||||
set(latest?.obj("microg"))
|
|
||||||
notifyChange()
|
|
||||||
}
|
|
||||||
manager.apply {
|
|
||||||
set(latest?.obj("manager"))
|
|
||||||
notifyChange()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +81,6 @@ object InternetTools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isUpdateAvailable(): Boolean {
|
|
||||||
while (true) {
|
|
||||||
if (manager.get() != null) {
|
|
||||||
return manager.get()?.int("versionCode") ?: 0 > BuildConfig.VERSION_CODE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getSha256(hashUrl: String, obj: String, context: Context): String {
|
suspend fun getSha256(hashUrl: String, obj: String, context: Context): String {
|
||||||
return getJsonString(hashUrl, obj, context)
|
return getJsonString(hashUrl, obj, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ object LanguageHelper {
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
fun getDefaultVancedLanguages(): String {
|
fun getDefaultVancedLanguages(): String {
|
||||||
val serverLangs = vanced.get()?.array("langs") ?: mutableListOf("")
|
val serverLangs = vanced.value?.array("langs") ?: mutableListOf("")
|
||||||
val sysLocales = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) Resources.getSystem().configuration.locales.toLangTags() else arrayOf(Resources.getSystem().configuration.locale.language)
|
val sysLocales = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) Resources.getSystem().configuration.locales.toLangTags() else arrayOf(Resources.getSystem().configuration.locale.language)
|
||||||
val finalLangs = mutableListOf<String>()
|
val finalLangs = mutableListOf<String>()
|
||||||
sysLocales.forEach { sysLocale ->
|
sysLocales.forEach { sysLocale ->
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.regex.Pattern
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
|
|
||||||
object PackageHelper {
|
object PackageHelper {
|
||||||
|
|
||||||
private const val apkInstallPath = "/data/adb"
|
private const val apkInstallPath = "/data/adb"
|
||||||
|
@ -167,7 +166,7 @@ object PackageHelper {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun installRootApp(context: Context, app: String, appVerCode: Int, pkg: String, modApkBool: (fileName: String) -> Boolean) = CoroutineScope(Dispatchers.IO).launch {
|
private fun installRootApp(context: Context, app: String, appVerCode: Int, pkg: String, modApkBool: (fileName: String) -> Boolean) = CoroutineScope(Dispatchers.IO).launch {
|
||||||
Shell.getShell {
|
Shell.getShell {
|
||||||
val apkFilesPath = context.getExternalFilesDir("$app/root")?.path
|
val apkFilesPath = context.getExternalFilesDir("$app/root")?.path
|
||||||
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
|
||||||
|
@ -195,7 +194,7 @@ object PackageHelper {
|
||||||
installRootApp(
|
installRootApp(
|
||||||
context,
|
context,
|
||||||
"music",
|
"music",
|
||||||
music.get()?.int("versionCode")!!,
|
music.value?.int("versionCode")!!,
|
||||||
musicRootPkg
|
musicRootPkg
|
||||||
) {
|
) {
|
||||||
it == "root.apk"
|
it == "root.apk"
|
||||||
|
@ -206,7 +205,7 @@ object PackageHelper {
|
||||||
installRootApp(
|
installRootApp(
|
||||||
context,
|
context,
|
||||||
"vanced",
|
"vanced",
|
||||||
vanced.get()?.int("versionCode")!!,
|
vanced.value?.int("versionCode")!!,
|
||||||
vancedRootPkg
|
vancedRootPkg
|
||||||
) { fileName ->
|
) { fileName ->
|
||||||
vancedThemes.any { fileName == "$it.apk" }
|
vancedThemes.any { fileName == "$it.apk" }
|
||||||
|
|
Loading…
Reference in a new issue