0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-15 23:35:06 +00:00

Merge pull request #253 from HaliksaR/fix-npe

Fix npe
This commit is contained in:
Tornike Khintibidze 2020-11-15 11:51:52 +04:00 committed by GitHub
commit d01e0f70d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 37 deletions

View file

@ -36,7 +36,7 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
private var installUrl: String? = null private var installUrl: String? = null
private var variant: String? = null private var variant: String? = null
private var theme: String? = null private var theme: String? = null
private var lang: MutableList<String>? = null private var lang = mutableListOf<String>()
private lateinit var themePath: String private lateinit var themePath: String
@ -56,7 +56,9 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
downloadPath = context.getExternalFilesDir("vanced/$variant")?.path downloadPath = context.getExternalFilesDir("vanced/$variant")?.path
File(downloadPath.toString()).deleteRecursively() File(downloadPath.toString()).deleteRecursively()
installUrl = defPrefs.getInstallUrl() installUrl = defPrefs.getInstallUrl()
lang = prefs.getString("lang", getDefaultVancedLanguages())?.split(", ")?.toMutableList() prefs.getString("lang", getDefaultVancedLanguages())?.let {
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.get()?.value ?: listOf(""))
themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme" themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme"
@ -112,7 +114,7 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
"lang" -> { "lang" -> {
count++ count++
succesfulLangCount++ succesfulLangCount++
if (count < lang?.size!!) if (count < lang.size)
downloadSplits(context, "lang") downloadSplits(context, "lang")
else else
startVancedInstall(context) startVancedInstall(context)
@ -132,9 +134,9 @@ object VancedDownloader: CoroutineScope by CoroutineScope(Dispatchers.IO) {
if (type == "lang") { if (type == "lang") {
count++ count++
when { when {
count < lang?.size!! -> downloadSplits(context, "lang") count < lang.size -> downloadSplits(context, "lang")
succesfulLangCount == 0 -> { succesfulLangCount == 0 -> {
lang?.add("en") lang.add("en")
downloadSplits(context, "lang") downloadSplits(context, "lang")
} }
else -> startVancedInstall(context) else -> startVancedInstall(context)

View file

@ -71,7 +71,7 @@ class VancedLanguageSelectionDialog : BottomSheetDialogFragment() {
val loc = Locale(lang) val loc = Locale(lang)
val box: MaterialCheckBox = MaterialCheckBox(requireActivity()).apply { val box: MaterialCheckBox = MaterialCheckBox(requireActivity()).apply {
tag = lang tag = lang
isChecked = langPrefs!!.contains(lang) isChecked = langPrefs?.contains(lang) ?: false
text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT) text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT)
textSize = 18F textSize = 18F
typeface = ResourcesCompat.getFont(requireActivity(), R.font.exo_bold) typeface = ResourcesCompat.getFont(requireActivity(), R.font.exo_bold)

View file

@ -100,9 +100,9 @@ object InternetTools {
return getJsonString(hashUrl, obj, context) return getJsonString(hashUrl, obj, context)
} }
fun checkSHA256(sha256: String, updateFile: File?): Boolean { fun checkSHA256(sha256: String, updateFile: File): Boolean {
return try { return try {
val dataBuffer = updateFile!!.readBytes() val dataBuffer = updateFile.readBytes()
// Generate the checksum // Generate the checksum
val sum = generateChecksum(dataBuffer) val sum = generateChecksum(dataBuffer)

View file

@ -12,15 +12,11 @@ object JsonHelper {
private var dataMap: HashMap<String, JsonObject> = HashMap() private var dataMap: HashMap<String, JsonObject> = HashMap()
suspend fun getJson(url: String): JsonObject? { suspend fun getJson(url: String): JsonObject? {
return try { return if (dataMap.containsKey(url)) {
if(dataMap.containsKey(url)) { dataMap[url]
dataMap[url]!! } else {
} else { dataMap[url] = getSuspendJson(url)
dataMap[url] = getSuspendJson(url) dataMap[url]
dataMap[url]!!
}
} catch (e: Exception) {
null
} }
} }

View file

@ -6,28 +6,20 @@ import java.io.InputStreamReader
object MiuiHelper { object MiuiHelper {
fun isMiui(): Boolean = getSystemProps("ro.miui.ui.version.name")!!.isNotEmpty() private const val MIUI_PROP_NAME = "ro.miui.ui.version.name"
fun isMiui(): Boolean = !getSystemProps(MIUI_PROP_NAME).isNullOrEmpty()
private fun getSystemProps(propname: String): String? { private fun getSystemProps(propname: String): String? {
val line: String
var input: BufferedReader? = null var input: BufferedReader? = null
try { return try {
val p = Runtime.getRuntime().exec("getprop $propname") val process = Runtime.getRuntime().exec("getprop $propname")
input = BufferedReader(InputStreamReader(p.inputStream), 1024) input = BufferedReader(InputStreamReader(process.inputStream), 1024)
line = input.readLine() input.readLine()
input.close()
} catch (e: IOException) { } catch (e: IOException) {
return null null
} finally { } finally {
if (input != null) { input?.close()
try {
input.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
} }
return line
} }
} }

View file

@ -298,7 +298,7 @@ object PackageHelper {
} }
} finally { } finally {
session!!.close() session?.close()
} }
} }
@ -579,8 +579,8 @@ object PackageHelper {
@Throws(IOException::class) @Throws(IOException::class)
fun copy(src: File?, dst: File?) { fun copy(src: File, dst: File) {
val cmd = Shell.su("mv ${src!!.absolutePath} ${dst!!.absolutePath}").exec().isSuccess val cmd = Shell.su("mv ${src.absolutePath} ${dst.absolutePath}").exec().isSuccess
Log.d("ZLog", cmd.toString()) Log.d("ZLog", cmd.toString())
} }