Skip to content

Commit

Permalink
update flags mechanic
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Jul 18, 2021
1 parent a010e9a commit ab460e3
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 278 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId "de.dertyp7214.rboardthememanager"
minSdkVersion 26
targetSdkVersion 30
versionCode 312
versionName "3.1.2"
versionCode 313
versionName "3.1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class SafeJSON(private val json: JSONObject) {
defaultValue
}
}

override fun toString(): String {
return try {
json.toString(2)
} catch (e: Exception) {
""
}
}
}

fun JSONObject.safeParse(string: String): JSONObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,34 @@ class SplashScreen : AppCompatActivity() {
}

File(applicationInfo.dataDir, "flags.json").apply {
val timeStamp = let {
if (!it.exists()) -1
else SafeJSON(JSONObject(it.readText())).getLong("time", -1)
}
doAsync(URL("https://raw.githubusercontent.com/AkosPaha/Rboard-ColorsTheme/master/flags-R.json")::getTextFromUrl) {
if (it.isBlank()) {
if (!exists() || lastModified() < packageManager.getPackageInfo(
packageName,
0
).lastUpdateTime
) {
if (!exists()) {
writeText(
resources.openRawResource(
FileUtils.getResourceId(
this@SplashScreen,
"flags",
"raw",
packageName
)
).bufferedReader().use { reader -> reader.readText() }
SafeJSON(
JSONObject(resources.openRawResource(
FileUtils.getResourceId(
this@SplashScreen,
"flags",
"raw",
packageName
)
).bufferedReader().use { reader -> reader.readText() })
).toString()
)
}
} else {
val json = SafeJSON(JSONObject(it))
if (!exists() || lastModified() < json.getLong("time"))
writeText(json.getJSONArray("flags").toString())
if (!exists() || timeStamp < json.getLong("time"))
writeText(json.toString())
}
}
}


val scheme = intent.scheme
val data = intent.data

Expand Down Expand Up @@ -215,4 +216,4 @@ class SplashScreen : AppCompatActivity() {
notificationManager.createNotificationChannel(channelPush)
notificationManager.createNotificationChannel(channelDownload)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Flags(val context: Context) {

val json = File(context.applicationInfo.dataDir, "flags.json").let {
if (!it.exists()) null
else JSONArray(it.readText())
else it.readText().let { text -> SafeJSON(JSONObject(text)).getJSONArray("flags") }
}

json?.forEach<JSONObject> { obj, _ ->
Expand Down
Loading

0 comments on commit ab460e3

Please sign in to comment.