mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-27 05:23:00 +00:00
added exception handling and changed manager update url to github
This commit is contained in:
parent
e2a5dddb20
commit
9841a83dbb
4 changed files with 49 additions and 49 deletions
|
@ -33,6 +33,7 @@ import com.vanced.manager.core.fragments.Home
|
|||
import com.vanced.manager.core.installer.RootAppUninstaller
|
||||
import com.vanced.manager.databinding.FragmentHomeBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.utils.InternetTools.displayJsonInt
|
||||
import com.vanced.manager.utils.PackageHelper.installApp
|
||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
@ -101,12 +102,8 @@ class HomeFragment : Home() {
|
|||
if (isConnectedToInternet) {
|
||||
vancedinstallbtn?.visibility = View.VISIBLE
|
||||
|
||||
val vancedRemoteCode =
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json")
|
||||
.get("versionCode").asInt
|
||||
val microgRemoteCode =
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json")
|
||||
.get("versionCode").asInt
|
||||
val vancedRemoteCode = activity?.let { displayJsonInt("vanced.json", "versionCode", it) }
|
||||
val microgRemoteCode = activity?.let { displayJsonInt("microg.json", "versionCode", it) }
|
||||
|
||||
if (variant == "nonroot") {
|
||||
val microginstallbtn =
|
||||
|
@ -121,7 +118,7 @@ class HomeFragment : Home() {
|
|||
else
|
||||
pm.getPackageInfo("com.mgoogle.android.gms", 0).versionCode
|
||||
when {
|
||||
microgRemoteCode > microgVerCode -> {
|
||||
microgRemoteCode!! > microgVerCode -> {
|
||||
microginstallbtn?.text =
|
||||
activity?.getString(R.string.update)
|
||||
microginstallbtn?.icon =
|
||||
|
@ -163,7 +160,7 @@ class HomeFragment : Home() {
|
|||
}
|
||||
|
||||
when {
|
||||
vancedRemoteCode > vancedVerCode!! -> {
|
||||
vancedRemoteCode!! > vancedVerCode!! -> {
|
||||
vancedinstallbtn?.text =
|
||||
activity?.getString(R.string.update)
|
||||
vancedinstallbtn?.icon =
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
|
@ -16,7 +13,6 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
|
@ -25,9 +21,6 @@ import com.vanced.manager.BuildConfig
|
|||
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.PackageHelper.installApp
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
class UpdateCheckFragment : DialogFragment() {
|
||||
|
||||
|
@ -76,8 +69,7 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
}
|
||||
|
||||
private fun upgradeManager(loadBar: ProgressBar) {
|
||||
val apkUrl = GetJson().AsJSONObject("https://vanced.app/api/v1/manager.json")
|
||||
val dwnldUrl = apkUrl.get("url").asString
|
||||
val dwnldUrl = "https://github.com/VancedManager/releases/latest/download/manager.apk"
|
||||
|
||||
PRDownloader.download(dwnldUrl, activity?.filesDir?.path, "manager.apk")
|
||||
.build()
|
||||
|
@ -96,7 +88,7 @@ class UpdateCheckFragment : DialogFragment() {
|
|||
activity?.let {
|
||||
installApp(
|
||||
it,
|
||||
it.filesDir.path + "/microg.apk",
|
||||
it.filesDir.path + "/manager.apk",
|
||||
"com.vanced.manager")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,11 @@ import androidx.core.content.ContextCompat.startActivity
|
|||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools.displayJsonString
|
||||
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
|
||||
|
||||
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private val connected: Boolean = GetJson().isConnected(application)
|
||||
class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private val vancedPkgName: String =
|
||||
if (getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot") == "root") {
|
||||
|
@ -30,34 +28,11 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
val microgInstalled: Boolean = isPackageInstalled("com.mgoogle.android.gms", application.packageManager)
|
||||
val vancedInstalled: Boolean = isPackageInstalled(vancedPkgName, application.packageManager)
|
||||
|
||||
val vancedInstalledVersion: String =
|
||||
if (vancedInstalled) {
|
||||
application.packageManager.getPackageInfo(vancedPkgName, 0).versionName
|
||||
} else {
|
||||
application.getString(R.string.unavailable)
|
||||
}
|
||||
val vancedInstalledVersion: MutableLiveData<String> = MutableLiveData()
|
||||
val microgInstalledVersion: MutableLiveData<String> = MutableLiveData()
|
||||
|
||||
|
||||
val microgInstalledVersion: String =
|
||||
if (microgInstalled) {
|
||||
application.packageManager.getPackageInfo("com.mgoogle.android.gms", 0).versionName
|
||||
} else {
|
||||
application.getString(R.string.unavailable)
|
||||
}
|
||||
|
||||
val vancedVersion: String =
|
||||
if (connected)
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json")
|
||||
.get("version").asString
|
||||
else
|
||||
application.getString(R.string.unavailable)
|
||||
|
||||
val microgVersion: String =
|
||||
if (connected)
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json")
|
||||
.get("version").asString
|
||||
else
|
||||
application.getString(R.string.unavailable)
|
||||
val vancedVersion: MutableLiveData<String> = MutableLiveData()
|
||||
val microgVersion: MutableLiveData<String> = MutableLiveData()
|
||||
|
||||
val isNonrootModeSelected: Boolean = getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot") == "nonroot"
|
||||
|
||||
|
@ -97,8 +72,21 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
signatureStatusTxt.value = signatureString
|
||||
vancedVersion.value = displayJsonString("vanced.json","version", application)
|
||||
microgVersion.value = displayJsonString("microg.json","version", application)
|
||||
vancedInstalledVersion.value = getPkgInfo(vancedInstalled, vancedPkgName, application)
|
||||
microgInstalledVersion.value = getPkgInfo(microgInstalled, "com.mgoogle.android.gms", application)
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,9 @@ import android.content.Context
|
|||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.vanced.manager.R
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
object InternetTools {
|
||||
|
||||
|
@ -16,5 +19,25 @@ object InternetTools {
|
|||
|
||||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
|
||||
|
||||
fun displayJsonString(json: String, obj: String, context: Context): String {
|
||||
return if (GetJson().isConnected(context)) {
|
||||
try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/$json").get(obj).asString
|
||||
} catch (e: IllegalStateException) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||
}
|
||||
} else {
|
||||
context.getString(R.string.unavailable)
|
||||
}
|
||||
}
|
||||
|
||||
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
||||
return try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/$json").get(obj).asInt
|
||||
} catch (e: IllegalStateException) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue