0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-22 19:25:11 +00:00

exception test 3

This commit is contained in:
X1nto 2020-07-01 17:18:14 +04:00
parent 2f191bbb7e
commit a9da78ff71
3 changed files with 26 additions and 23 deletions

View file

@ -3,7 +3,6 @@ package com.vanced.manager.core.downloader
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.IBinder
import android.widget.Toast
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@ -19,17 +18,11 @@ import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
import com.vanced.manager.utils.NotificationHelper
import com.vanced.manager.utils.NotificationHelper.cancelNotif
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
import java.lang.IllegalStateException
import java.util.concurrent.ExecutionException
class MicrogDownloadService: Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
try {
downloadMicrog()
} catch (e: Exception) {
Toast.makeText(this, "Unable to download MicroG", Toast.LENGTH_SHORT).show()
}
downloadMicrog()
stopSelf()
return START_NOT_STICKY
}
@ -37,10 +30,18 @@ class MicrogDownloadService: Service() {
private fun downloadMicrog() {
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
val dwnldUrl = apkUrl.get("url").asString
val apkUrl =
if(GetJson().isConnected(this))
try {
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json").get("url").asString
} catch (e: Exception) {
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json").get("url").asString
}
else
""
val channel = 420
PRDownloader.download(dwnldUrl, filesDir.path, "microg.apk")
PRDownloader.download(apkUrl, filesDir.path, "microg.apk")
.build()
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
.setOnProgressListener { progress ->
@ -48,7 +49,7 @@ class MicrogDownloadService: Service() {
NotificationHelper.displayDownloadNotif(
channel,
mProgress.toInt(),
getFileNameFromUrl(dwnldUrl),
getFileNameFromUrl(apkUrl),
this
)
}

View file

@ -41,7 +41,15 @@ class VancedDownloadService: Service() {
type: String = "arch"
) {
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
val vancedVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
val vancedVer =
if(GetJson().isConnected(this))
try {
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json").get("vanced").asString
} catch (e: Exception) {
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("vanced").asString
}
else
""
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
val lang = prefs?.getString("lang", "en")

View file

@ -26,14 +26,10 @@ object InternetTools {
fun displayJsonString(json: String, obj: String, context: Context): String {
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return if (GetJson().isConnected(context)) {
try {
return try {
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
} catch (e: Exception) {
when (e) {
is InterruptedException, is ExecutionException -> GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
else -> throw e
}
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
}
} else {
context.getString(R.string.unavailable)
@ -43,7 +39,7 @@ object InternetTools {
fun displayJsonInt(json: String, obj: String, context: Context): Int {
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return if (GetJson().isConnected(context)) {
try {
return try {
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
} catch (e: Exception) {
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
@ -60,6 +56,4 @@ object InternetTools {
const val baseUrl = "https://vanced.app/api/v1"
}
}