fixed crash
This commit is contained in:
parent
506d530c13
commit
d5fecfb2c0
|
@ -1,6 +1,5 @@
|
||||||
package com.vanced.manager.core.downloader
|
package com.vanced.manager.core.downloader
|
||||||
|
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
@ -9,6 +8,7 @@ import android.os.IBinder
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.dezlum.codelabs.getjson.GetJson
|
||||||
import com.downloader.Error
|
import com.downloader.Error
|
||||||
import com.downloader.OnDownloadListener
|
import com.downloader.OnDownloadListener
|
||||||
import com.downloader.OnStartOrResumeListener
|
import com.downloader.OnStartOrResumeListener
|
||||||
|
@ -17,14 +17,12 @@ import com.vanced.manager.R
|
||||||
import com.vanced.manager.core.installer.RootSplitInstallerService
|
import com.vanced.manager.core.installer.RootSplitInstallerService
|
||||||
import com.vanced.manager.core.installer.SplitInstaller
|
import com.vanced.manager.core.installer.SplitInstaller
|
||||||
import com.vanced.manager.ui.fragments.HomeFragment
|
import com.vanced.manager.ui.fragments.HomeFragment
|
||||||
|
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||||
import com.vanced.manager.utils.InternetTools.getLatestVancedUrl
|
|
||||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||||
import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
|
import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import java.lang.IllegalStateException
|
|
||||||
import java.lang.RuntimeException
|
|
||||||
import java.util.concurrent.ExecutionException
|
import java.util.concurrent.ExecutionException
|
||||||
|
|
||||||
class VancedDownloadService: Service() {
|
class VancedDownloadService: Service() {
|
||||||
|
@ -46,10 +44,10 @@ class VancedDownloadService: Service() {
|
||||||
private fun downloadSplits(
|
private fun downloadSplits(
|
||||||
type: String = "arch"
|
type: String = "arch"
|
||||||
) {
|
) {
|
||||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", getLatestVancedUrl(this))
|
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
|
||||||
|
val vancedVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
|
||||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||||
val variant = PreferenceManager.getDefaultSharedPreferences(this)
|
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
|
||||||
.getString("vanced_variant", "nonroot")
|
|
||||||
val lang = prefs?.getString("lang", "en")
|
val lang = prefs?.getString("lang", "en")
|
||||||
val theme = prefs?.getString("theme", "dark")
|
val theme = prefs?.getString("theme", "dark")
|
||||||
val arch =
|
val arch =
|
||||||
|
@ -60,10 +58,10 @@ class VancedDownloadService: Service() {
|
||||||
}
|
}
|
||||||
val url =
|
val url =
|
||||||
when (type) {
|
when (type) {
|
||||||
"arch" -> "$baseUrl/$variant/Config/config.$arch.apk"
|
"arch" -> "$baseUrl/apks/v$vancedVer/$variant/Config/config.$arch.apk"
|
||||||
"theme" -> "$baseUrl/$variant/Theme/$theme.apk"
|
"theme" -> "$baseUrl/apks/v$vancedVer/$variant/Theme/$theme.apk"
|
||||||
"lang" -> "$baseUrl/$variant/Language/split_config.$lang.apk"
|
"lang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.$lang.apk"
|
||||||
"enlang" -> "$baseUrl/$variant/Language/split_config.en.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?")
|
else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.preference.PreferenceManager
|
||||||
import com.dezlum.codelabs.getjson.GetJson
|
import com.dezlum.codelabs.getjson.GetJson
|
||||||
import com.vanced.manager.BuildConfig
|
import com.vanced.manager.BuildConfig
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
|
import java.lang.Exception
|
||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
object InternetTools {
|
object InternetTools {
|
||||||
|
@ -22,12 +23,16 @@ object InternetTools {
|
||||||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
|
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
|
||||||
|
|
||||||
fun displayJsonString(json: String, obj: String, context: Context): String {
|
fun displayJsonString(json: String, obj: String, context: Context): String {
|
||||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", getLatestVancedUrl(context))
|
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||||
return if (GetJson().isConnected(context)) {
|
return if (GetJson().isConnected(context)) {
|
||||||
try {
|
try {
|
||||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: Exception) {
|
||||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
when (e) {
|
||||||
|
is InterruptedException, is IllegalStateException -> GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||||
|
else -> throw e
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.unavailable)
|
context.getString(R.string.unavailable)
|
||||||
|
@ -35,12 +40,16 @@ object InternetTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
||||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", getLatestVancedUrl(context))
|
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||||
return if (GetJson().isConnected(context)) {
|
return if (GetJson().isConnected(context)) {
|
||||||
try {
|
try {
|
||||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: Exception) {
|
||||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
when (e) {
|
||||||
|
is InterruptedException, is IllegalStateException -> GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
||||||
|
else -> throw e
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else 0
|
} else 0
|
||||||
}
|
}
|
||||||
|
@ -52,13 +61,8 @@ object InternetTools {
|
||||||
return remoteVersion > BuildConfig.VERSION_CODE
|
return remoteVersion > BuildConfig.VERSION_CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLatestVancedUrl(context: Context): String {
|
const val baseUrl = "https://vanced.app/api/v1/"
|
||||||
return if (GetJson().isConnected(context)) {
|
|
||||||
val latestVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
|
|
||||||
"https://vanced.app/api/v1/apks/v$latestVer"
|
|
||||||
} else
|
|
||||||
"https://vanced.app/api/v1/apks/v15.05.54"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue