Skip to content

Commit

Permalink
popup,no internet crash fix on app start, key so leaked version does …
Browse files Browse the repository at this point in the history
…not work
  • Loading branch information
AkosPaha01 committed Jul 18, 2021
1 parent 83e6985 commit 2105860
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fun Activity.openInputDialog(
@StringRes hint: Int,
negative: ((dialogInterface: DialogInterface) -> Unit) = { it.dismiss() },
positive: (dialogInterface: DialogInterface, text: String) -> Unit
) = openDialog(R.layout.loading_dialog, false) { dialog ->
) = openDialog(R.layout.input_dialog, false) { dialog ->
val input = findViewById<EditText>(R.id.editText)
input.setHint(hint)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class SafeJSON(private val json: JSONObject) {
}
}

fun JSONObject.safeParse(string: String): JSONObject {
fun JSONObject.safeParse(string: String): SafeJSON {
return try {
JSONObject(string)
SafeJSON(JSONObject(string))
} catch (e: Exception) {
this
SafeJSON(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,23 @@ AppWidgetManager.getInstance(this).let { appWidgetManager ->
val timeStamp = try {
let {
if (!it.exists()) -1
else SafeJSON(JSONObject(it.readText())).getLong("time", -1)
else JSONObject().safeParse(it.readText()).getLong("time", -1)
}
} catch (e: Exception) {
delete()
-1
}
doAsync(URL(flagsUrl)::getTextFromUrl) {
val flagFiles = listOf(
SafeJSON(
JSONObject(resources.openRawResource(
FileUtils.getResourceId(
this@SplashScreen,
"flags",
"raw",
packageName
)
).bufferedReader().use { reader -> reader.readText() })
),
SafeJSON(JSONObject(it))
JSONObject().safeParse(resources.openRawResource(
FileUtils.getResourceId(
this@SplashScreen,
"flags",
"raw",
packageName
)
).bufferedReader().use { reader -> reader.readText() }),
JSONObject().safeParse(it)
)
val latestJson =
flagFiles.reduce { acc, safeJSON -> if (acc.getLong("time") > safeJSON.getLong("time")) acc else safeJSON }
Expand Down Expand Up @@ -215,15 +213,34 @@ AppWidgetManager.getInstance(this).let { appWidgetManager ->
) {
finishAndRemoveTask()
}
else -> checkForUpdate {
else -> checkForUpdate { update ->
checkedForUpdate = true
startActivity(Intent(this, MainActivity::class.java).putExtra("update", it))
finish()
checkKey {
if (it) startActivity(
Intent(this, MainActivity::class.java).putExtra(
"update",
update
)
)
finish()
}
}
}
}
}
}

private fun validApp(callback: (valid: Boolean) -> Unit) {
PreferenceManager.getDefaultSharedPreferences(this).apply {
var valid = getBoolean("verified", false)
if (valid) callback(valid)
else openDialog(R.string.unreleased, R.string.notice) {
valid = true
callback(valid)
edit { putBoolean("verified", true) }
}
}
}

private fun checkForUpdate(callback: (update: Boolean) -> Unit) {
doAsync(URL(checkUpdateUrl)::getTextFromUrl) { text ->
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@
<string name="show_preinstalled_themes_long">Show preinstalled themes in themes section</string>
<string name="show_system_theme_long">Show system themes in themes section</string>
<string name="speedup_process">Speedup process</string>
<string name="key">Key</string>
<string name="unreleased">This app is unreleased, some features may not work. Please dont report any errors to the main group.</string>
<string name="notice">Notice</string>
</resources>

0 comments on commit 2105860

Please sign in to comment.