mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-26 05:05:15 +00:00
JSON Parsing from request
This commit is contained in:
parent
1224e01823
commit
7a1d7cced8
12 changed files with 277 additions and 167 deletions
|
@ -23,4 +23,5 @@ After 3 months of development, we are finally ready to introduce Vanced Manager
|
|||
- topjohnwu for his wonderful [LibSU](https://github.com/topjohnwu/libsu)
|
||||
- Mindorks for their amazing [PRDownloader](https://github.com/MindorksOpenSource/PRDownloader)
|
||||
- aefyr for [SAI](https://github.com/aefyr/SAI), which was an inspiration for our Manager
|
||||
- 100rabhkr for their [GetJson](https://github.com/100rabhkr/getjson) library
|
||||
- kittinunf for the [Fuel](https://github.com/kittinunf/Fuel) library
|
||||
- cbeust for the [klaxon](https://github.com/cbeust/klaxon) library
|
||||
|
|
|
@ -74,8 +74,15 @@ dependencies {
|
|||
|
||||
// Other
|
||||
implementation 'com.crowdin.platform:mobile-sdk:1.1.4'
|
||||
implementation 'com.github.100rabhkr:GetJSON:1.0'
|
||||
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
|
||||
implementation 'com.mindorks.android:prdownloader:0.6.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
|
||||
implementation 'com.beust:klaxon:5.0.1'
|
||||
|
||||
//core
|
||||
implementation 'com.github.kittinunf.fuel:fuel:2.2.3'
|
||||
//packages
|
||||
implementation 'com.github.kittinunf.fuel:fuel-json:2.2.3'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-coroutines:2.2.3'
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import com.vanced.manager.utils.InternetTools.getObjectFromJson
|
|||
import com.vanced.manager.utils.NotificationHelper
|
||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
class MicrogDownloadService: Service() {
|
||||
|
@ -37,18 +39,24 @@ class MicrogDownloadService: Service() {
|
|||
}
|
||||
|
||||
private fun downloadMicrog() {
|
||||
//val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val apkUrl = getObjectFromJson("${PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)}/microg.json", "url", this)
|
||||
val context = this
|
||||
runBlocking {
|
||||
launch {
|
||||
//val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val apkUrl = getObjectFromJson(
|
||||
"${PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("install_url", baseUrl)}/microg.json", "url")
|
||||
|
||||
val request = DownloadManager.Request(Uri.parse(apkUrl))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(getString(R.string.downloading_file, "MicroG"))
|
||||
request.setDestinationUri(Uri.fromFile(File("${filesDir.path}/microg.apk")))
|
||||
|
||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
val request = DownloadManager.Request(Uri.parse(apkUrl))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(getString(R.string.downloading_file, "MicroG"))
|
||||
request.setDestinationUri(Uri.fromFile(File("${filesDir.path}/microg.apk")))
|
||||
|
||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
}
|
||||
}
|
||||
/*
|
||||
val channel = 420
|
||||
PRDownloader.download(apkUrl, filesDir.path, "microg.apk")
|
||||
|
|
|
@ -25,6 +25,8 @@ import com.vanced.manager.utils.InternetTools.getObjectFromJson
|
|||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
class VancedDownloadService: Service() {
|
||||
|
@ -42,39 +44,52 @@ class VancedDownloadService: Service() {
|
|||
private fun downloadSplits(
|
||||
type: String = "arch"
|
||||
) {
|
||||
val defPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val baseUrl = defPrefs.getString("install_url", baseUrl)
|
||||
val vancedVer = getObjectFromJson("$baseUrl/vanced.json", "version", this)
|
||||
val context = this
|
||||
runBlocking {
|
||||
launch {
|
||||
val defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val baseUrl = defPrefs.getString("install_url", baseUrl)
|
||||
val vancedVer = getObjectFromJson("$baseUrl/vanced.json", "version")
|
||||
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
|
||||
val lang = prefs?.getString("lang", "en")
|
||||
val theme = prefs?.getString("theme", "dark")
|
||||
val arch =
|
||||
when {
|
||||
Build.SUPPORTED_ABIS.contains("x86") -> "x86"
|
||||
Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a"
|
||||
else -> "armeabi_v7a"
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val variant = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("vanced_variant", "nonroot")
|
||||
val lang = prefs?.getString("lang", "en")
|
||||
val theme = prefs?.getString("theme", "dark")
|
||||
val arch =
|
||||
when {
|
||||
Build.SUPPORTED_ABIS.contains("x86") -> "x86"
|
||||
Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a"
|
||||
else -> "armeabi_v7a"
|
||||
}
|
||||
val url =
|
||||
when (type) {
|
||||
"arch" -> "$baseUrl/apks/v$vancedVer/$variant/Arch/split_config.$arch.apk"
|
||||
"theme" -> "$baseUrl/apks/v$vancedVer/$variant/Theme/$theme.apk"
|
||||
"lang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.$lang.apk"
|
||||
"enlang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.en.apk"
|
||||
else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?")
|
||||
}
|
||||
|
||||
apkType = type
|
||||
val request = DownloadManager.Request(Uri.parse(url))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(getString(R.string.downloading_file, "MicroG"))
|
||||
request.setDestinationUri(
|
||||
Uri.fromFile(
|
||||
File(
|
||||
"${filesDir.path}/${getFileNameFromUrl(
|
||||
url
|
||||
)}"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
}
|
||||
val url =
|
||||
when (type) {
|
||||
"arch" -> "$baseUrl/apks/v$vancedVer/$variant/Arch/split_config.$arch.apk"
|
||||
"theme" -> "$baseUrl/apks/v$vancedVer/$variant/Theme/$theme.apk"
|
||||
"lang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.$lang.apk"
|
||||
"enlang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.en.apk"
|
||||
else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?")
|
||||
}
|
||||
|
||||
apkType = type
|
||||
val request = DownloadManager.Request(Uri.parse(url))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(getString(R.string.downloading_file, "MicroG"))
|
||||
request.setDestinationUri(Uri.fromFile(File("${filesDir.path}/${getFileNameFromUrl(url)}")))
|
||||
|
||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
|
||||
}
|
||||
/*
|
||||
val channel = 69
|
||||
PRDownloader
|
||||
|
|
|
@ -17,17 +17,24 @@ import androidx.navigation.ui.setupWithNavController
|
|||
import androidx.preference.PreferenceManager
|
||||
import com.crowdin.platform.Crowdin
|
||||
import com.crowdin.platform.LoadingStateListener
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.installer.AppInstaller
|
||||
import com.vanced.manager.databinding.ActivityMainBinding
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.launchVanced
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.regularPackageInstalled
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import com.vanced.manager.ui.fragments.UpdateCheckFragment
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.NotificationHelper
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
|
@ -178,9 +185,13 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun checkUpdates() {
|
||||
if (GetJson().isConnected(this) && InternetTools.isUpdateAvailable()) {
|
||||
val fm = supportFragmentManager
|
||||
UpdateCheckFragment().show(fm, "UpdateCheck")
|
||||
runBlocking {
|
||||
launch {
|
||||
if (InternetTools.isUpdateAvailable()) {
|
||||
val fm = supportFragmentManager
|
||||
UpdateCheckFragment().show(fm, "UpdateCheck")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class ManagerChangelogFragment : Fragment() {
|
||||
|
||||
|
@ -21,12 +24,17 @@ class ManagerChangelogFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.manager_changelog)
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.manager_changelog)
|
||||
|
||||
if (GetJson().isConnected(activity)) {
|
||||
val checkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
|
||||
val changelog = checkUrl.get("changelog").asString
|
||||
changelogTxt.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,13 +1,18 @@
|
|||
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
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class MicrogChangelogFragment : Fragment() {
|
||||
|
||||
|
@ -21,12 +26,17 @@ class MicrogChangelogFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.microg_changelog)
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.microg_changelog)
|
||||
|
||||
if (GetJson().isConnected(activity)) {
|
||||
val checkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
|
||||
val changelog = checkUrl.get("changelog").asString
|
||||
changelogTxt.text = changelog
|
||||
var baseUrl = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString("install_url", InternetTools.baseUrl)
|
||||
baseUrl = baseUrl?.trimEnd('/')
|
||||
|
||||
var changelog = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog");
|
||||
changelogTxt.text = changelog
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,15 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.InternetTools.isUpdateAvailable
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
class UpdateCheckFragment : DialogFragment() {
|
||||
|
@ -60,8 +62,8 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
private fun checkUpdates() {
|
||||
val updatebtn = view?.findViewById<Button>(R.id.update_center_update)
|
||||
val checkingTxt = view?.findViewById<TextView>(R.id.update_center_checking)
|
||||
if (GetJson().isConnected(requireContext())) {
|
||||
|
||||
runBlocking {
|
||||
if (isUpdateAvailable()) {
|
||||
view?.findViewById<Button>(R.id.update_center_recheck)?.visibility = View.GONE
|
||||
checkingTxt?.text = getString(R.string.update_found)
|
||||
|
@ -70,24 +72,27 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
upgradeManager()
|
||||
}
|
||||
} else checkingTxt?.text = getString(R.string.update_notfound)
|
||||
|
||||
} else {
|
||||
checkingTxt?.text = getString(R.string.network_error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun upgradeManager() {
|
||||
val dwnldUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json").get("url").asString
|
||||
//val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view?.findViewById<TextView>(R.id.microg_changelog)
|
||||
|
||||
val request = DownloadManager.Request(Uri.parse(dwnldUrl))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(activity?.getString(R.string.downloading_file, "Manager"))
|
||||
request.setDestinationUri(Uri.fromFile(File("${activity?.filesDir?.path}/manager.apk")))
|
||||
val dwnldUrl = InternetTools.getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url");
|
||||
//val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
|
||||
|
||||
val downloadManager = activity?.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
val request = DownloadManager.Request(Uri.parse(dwnldUrl))
|
||||
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
request.setTitle(activity?.getString(R.string.downloading_file, "Manager"))
|
||||
request.setDestinationUri(Uri.fromFile(File("${activity?.filesDir?.path}/manager.apk")))
|
||||
|
||||
val downloadManager = activity?.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
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
|
||||
|
||||
class VancedChangelogFragment : Fragment() {
|
||||
|
||||
|
@ -21,14 +26,51 @@ class VancedChangelogFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.vanced_changelog)
|
||||
val context = context
|
||||
val appContext = activity?.applicationContext
|
||||
val application = activity?.application
|
||||
runBlocking {
|
||||
launch {
|
||||
val changelogTxt = view.findViewById<TextView>(R.id.vanced_changelog)
|
||||
|
||||
if (GetJson().isConnected(activity)) {
|
||||
val checkUrl = GetJson().AsJSONObject("https://vanced.app/api/v1/changelog/15_05_54.json")
|
||||
val changelog = checkUrl.get("message").asString
|
||||
changelogTxt.text = changelog
|
||||
// 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..."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,13 @@ import androidx.lifecycle.AndroidViewModel
|
|||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.crowdin.platform.Crowdin
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.fragments.UpdateCheckFragment
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.InternetTools.getJsonInt
|
||||
import com.vanced.manager.utils.InternetTools.getJsonString
|
||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
|
@ -57,41 +61,45 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
|
|||
|
||||
//this too
|
||||
fun fetchData() {
|
||||
fetching.set(true)
|
||||
Crowdin.forceUpdate(getApplication())
|
||||
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()))
|
||||
vancedInstallButtonIcon.set(
|
||||
if (variant == "nonroot") {
|
||||
if (microgInstalled.get()!!)
|
||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
else
|
||||
null
|
||||
} else
|
||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
)
|
||||
runBlocking {
|
||||
launch {
|
||||
fetching.set(true)
|
||||
Crowdin.forceUpdate(getApplication())
|
||||
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()))
|
||||
vancedInstallButtonIcon.set(
|
||||
if (variant == "nonroot") {
|
||||
if (microgInstalled.get()!!)
|
||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
else
|
||||
null
|
||||
} else
|
||||
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
)
|
||||
|
||||
vancedInstallButtonTxt.set(
|
||||
if (variant == "nonroot") {
|
||||
if (microgInstalled.get()!!) {
|
||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
} else {
|
||||
getApplication<Application>().getString(R.string.no_microg)
|
||||
}
|
||||
} else
|
||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
)
|
||||
fetching.set(false)
|
||||
vancedInstallButtonTxt.set(
|
||||
if (variant == "nonroot") {
|
||||
if (microgInstalled.get()!!) {
|
||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
} else {
|
||||
getApplication<Application>().getString(R.string.no_microg)
|
||||
}
|
||||
} else
|
||||
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
|
||||
)
|
||||
fetching.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openMicrogSettings() {
|
||||
|
|
|
@ -8,14 +8,9 @@ import androidx.browser.customtabs.CustomTabsIntent
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.BuildConfig
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import okhttp3.*
|
||||
import com.vanced.manager.R
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
object InternetTools {
|
||||
const val TAG = "VancedManager"
|
||||
|
||||
fun openUrl(Url: String, color: Int, context: Context) {
|
||||
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_customtabs", true)
|
||||
|
@ -30,60 +25,41 @@ object InternetTools {
|
|||
|
||||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
|
||||
|
||||
fun getObjectFromJson(url: String, obj: String, context: Context): String {
|
||||
return if (GetJson().isConnected(context))
|
||||
GetJson().AsJSONObject(url).get(obj).asString
|
||||
else
|
||||
suspend fun getObjectFromJson(url: String, obj: String): String {
|
||||
return try {
|
||||
val result = JsonHelper.getJson(url)
|
||||
result.string(obj) ?: ""
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
fun getJsonInt(file: String, obj: String, context: Context): Int {
|
||||
val client = OkHttpClient()
|
||||
val url = "${getDefaultSharedPreferences(context).getString("install_url", baseUrl)}/$file"
|
||||
val toReturn = AtomicReference<Int>()
|
||||
|
||||
val request = Request.Builder().url(url).build()
|
||||
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
toReturn.set(0)
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
toReturn.set(JSONObject(response.body?.string()!!).getInt(obj))
|
||||
Log.d("VMResponse", toReturn.toString())
|
||||
}
|
||||
})
|
||||
|
||||
Log.d("VMResponse", toReturn.toString())
|
||||
return toReturn.get()
|
||||
suspend fun getJsonInt(file: String, obj: String, context: Context): Int {
|
||||
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return try {
|
||||
val result = JsonHelper.getJson("$installUrl/$file")
|
||||
result.int(obj) ?: 0
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fun getJsonString(file: String, obj: String, context: Context): String {
|
||||
val client = OkHttpClient()
|
||||
val url = "${getDefaultSharedPreferences(context).getString("install_url", baseUrl)}/$file"
|
||||
val toReturn = AtomicReference<String>()
|
||||
|
||||
val request = Request.Builder().url(url).build()
|
||||
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
toReturn.set(context.getString(R.string.unavailable))
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
toReturn.set(JSONObject(response.body?.string()!!).getString(obj))
|
||||
Log.d("VMResponse", toReturn.get())
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return toReturn.get()
|
||||
suspend fun getJsonString(file: String, obj: String, context: Context): String {
|
||||
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return try {
|
||||
val result = JsonHelper.getJson("$installUrl/$file")
|
||||
result.string(obj) ?: ""
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error: ", e)
|
||||
"Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
fun isUpdateAvailable(): Boolean {
|
||||
val checkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
|
||||
val remoteVersion = checkUrl.get("versionCode").asInt
|
||||
suspend fun isUpdateAvailable(): Boolean {
|
||||
val result = JsonHelper.getJson("https://x1nto.github.io/VancedFiles/manager.json")
|
||||
val remoteVersion = result.string("versionCode")?.toInt() ?: 0
|
||||
|
||||
return remoteVersion > BuildConfig.VERSION_CODE
|
||||
}
|
||||
|
|
19
app/src/main/java/com/vanced/manager/utils/JsonHelper.kt
Normal file
19
app/src/main/java/com/vanced/manager/utils/JsonHelper.kt
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import com.beust.klaxon.JsonObject
|
||||
import com.beust.klaxon.Parser
|
||||
import com.github.kittinunf.fuel.coroutines.awaitString
|
||||
import com.github.kittinunf.fuel.httpGet
|
||||
|
||||
object JsonHelper {
|
||||
|
||||
suspend fun getJson(url: String): JsonObject {
|
||||
val result = url.httpGet()
|
||||
.awaitString()
|
||||
|
||||
val parser: Parser = Parser.default()
|
||||
val stringBuilder: StringBuilder = StringBuilder(result)
|
||||
|
||||
return parser.parse(stringBuilder) as JsonObject
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue