refactors changelog and version handling, fixes crash on startup due to version mismatch.

This commit is contained in:
octoshrimpy
2024-11-02 15:11:20 -04:00
parent b2c5aab7d5
commit 2d902150b1
8 changed files with 74 additions and 44 deletions
@@ -20,8 +20,10 @@ package dev.octoshrimpy.quik.common.util.extensions
import android.app.job.JobScheduler import android.app.job.JobScheduler
import android.content.Context import android.content.Context
import android.content.pm.PackageManager
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.util.TypedValue import android.util.TypedValue
import android.widget.Toast import android.widget.Toast
import androidx.annotation.StringRes import androidx.annotation.StringRes
@@ -85,7 +87,12 @@ fun Context.isInstalled(packageName: String): Boolean {
} }
val Context.versionCode: Int val Context.versionCode: Int
get() = packageManager.getPackageInfo(packageName, 0).versionCode get() {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0)).longVersionCode.toInt()
} else {
packageManager.getPackageInfo(packageName, 0).versionCode
}
}
val Context.jobScheduler: JobScheduler val Context.jobScheduler: JobScheduler
get() = getSystemService()!! get() = getSystemService()!!
+29 -28
View File
@@ -1,16 +1,17 @@
[ { [ {
"versionCode": "2225", "versionCode": 2225,
"versionName": "4.0.8", "versionName": "4.0.8",
"fixed": [ "fixed": [
"Padding on number input field for new message", "Padding on number input field for new message",
"Clean up telephony permissions", "Clean up telephony permissions",
"min SDK version support: 23", "min SDK version support: 23",
"registers as APP_MESSAGING" "registers as APP_MESSAGING",
"refactors changelog and version handling"
] ]
}, },
{ {
"versionCode": "2224", "versionCode": 2224,
"versionName": "4.0.7", "versionName": "4.0.7",
"removed": [ "removed": [
"Analytics trackers", "Analytics trackers",
@@ -19,14 +20,14 @@
] ]
}, },
{ {
"versionCode": "2223", "versionCode": 2223,
"versionName": "4.0.6", "versionName": "4.0.6",
"fixed": [ "fixed": [
"Renaming conversations has been patched." "Renaming conversations has been patched."
] ]
}, },
{ {
"versionCode": "2222", "versionCode": 2222,
"versionName": "4.0.5", "versionName": "4.0.5",
"fixed": [ "fixed": [
], ],
@@ -34,7 +35,7 @@
] ]
}, },
{ {
"versionCode": "2221", "versionCode": 2221,
"versionName": "4.0.4", "versionName": "4.0.4",
"fixed": [ "fixed": [
"Revived!", "Revived!",
@@ -48,14 +49,14 @@
] ]
}, },
{ {
"versionCode": "2220", "versionCode": 2220,
"versionName": "3.10.1", "versionName": "3.10.1",
"fixed": [ "fixed": [
"Crash when launching the app" "Crash when launching the app"
] ]
}, },
{ {
"versionCode": "2219", "versionCode": 2219,
"versionName": "3.10.0", "versionName": "3.10.0",
"added": [ "added": [
"Support for Call Blocker (blocking manager)" "Support for Call Blocker (blocking manager)"
@@ -70,28 +71,28 @@
] ]
}, },
{ {
"versionCode": "2218", "versionCode": 2218,
"versionName": "3.9.4", "versionName": "3.9.4",
"fixed": [ "fixed": [
"Incorrect handling of shared text that contains a question mark" "Incorrect handling of shared text that contains a question mark"
] ]
}, },
{ {
"versionCode": "2217", "versionCode": 2217,
"versionName": "3.9.3", "versionName": "3.9.3",
"improved": [ "improved": [
"Message sync is now 2x faster" "Message sync is now 2x faster"
] ]
}, },
{ {
"versionCode": "2216", "versionCode": 2216,
"versionName": "3.9.2", "versionName": "3.9.2",
"fixed": [ "fixed": [
"Crash when launching app in 3.9.1" "Crash when launching app in 3.9.1"
] ]
}, },
{ {
"versionCode": "2215", "versionCode": 2215,
"versionName": "3.9.1", "versionName": "3.9.1",
"improved": [ "improved": [
"Support SMS URIs that only have a body" "Support SMS URIs that only have a body"
@@ -101,7 +102,7 @@
] ]
}, },
{ {
"versionCode": "2214", "versionCode": 2214,
"versionName": "3.9.0", "versionName": "3.9.0",
"added": [ "added": [
"Auto-delete old messages", "Auto-delete old messages",
@@ -140,7 +141,7 @@
] ]
}, },
{ {
"versionCode": "2213", "versionCode": 2213,
"versionName": "3.8.1", "versionName": "3.8.1",
"fixed": [ "fixed": [
"MMS not sending", "MMS not sending",
@@ -150,14 +151,14 @@
] ]
}, },
{ {
"versionCode": "2212", "versionCode": 2212,
"versionName": "3.8.0", "versionName": "3.8.0",
"improved": [ "improved": [
"Updated translations" "Updated translations"
] ]
}, },
{ {
"versionCode": "2211", "versionCode": 2211,
"versionName": "3.8.0-beta2", "versionName": "3.8.0-beta2",
"fixed": [ "fixed": [
"Crash when starting new conversation", "Crash when starting new conversation",
@@ -165,7 +166,7 @@
] ]
}, },
{ {
"versionCode": "2210", "versionCode": 2210,
"versionName": "3.8.0-beta1", "versionName": "3.8.0-beta1",
"added": [ "added": [
"Support for Contact Groups and Starred Contacts", "Support for Contact Groups and Starred Contacts",
@@ -203,7 +204,7 @@
] ]
}, },
{ {
"versionCode": "2209", "versionCode": 2209,
"versionName": "3.7.10", "versionName": "3.7.10",
"improved": [ "improved": [
"Include archived conversations in search results", "Include archived conversations in search results",
@@ -215,7 +216,7 @@
] ]
}, },
{ {
"versionCode": "2208", "versionCode": 2208,
"versionName": "3.7.9", "versionName": "3.7.9",
"improved": [ "improved": [
"Better reliability for sending MMS" "Better reliability for sending MMS"
@@ -225,7 +226,7 @@
] ]
}, },
{ {
"versionCode": "2207", "versionCode": 2207,
"versionName": "3.7.8", "versionName": "3.7.8",
"fixed": [ "fixed": [
"Contact not always linked to conversation", "Contact not always linked to conversation",
@@ -234,14 +235,14 @@
] ]
}, },
{ {
"versionCode": "2206", "versionCode": 2206,
"versionName": "3.7.7", "versionName": "3.7.7",
"fixed": [ "fixed": [
"New conversations may not appear in inbox" "New conversations may not appear in inbox"
] ]
}, },
{ {
"versionCode": "2204", "versionCode": 2204,
"versionName": "3.7.5", "versionName": "3.7.5",
"added": [ "added": [
"Added ability to retry sending failed MMS" "Added ability to retry sending failed MMS"
@@ -259,7 +260,7 @@
] ]
}, },
{ {
"versionCode": "2203", "versionCode": 2203,
"versionName": "3.7.4", "versionName": "3.7.4",
"added": [ "added": [
"Support for Android Q Roles" "Support for Android Q Roles"
@@ -274,7 +275,7 @@
] ]
}, },
{ {
"versionCode": "2202", "versionCode": 2202,
"versionName": "3.7.3", "versionName": "3.7.3",
"added": [ "added": [
"You can now view attachments of any filetype" "You can now view attachments of any filetype"
@@ -297,21 +298,21 @@
] ]
}, },
{ {
"versionCode": "2201", "versionCode": 2201,
"versionName": "3.7.2", "versionName": "3.7.2",
"fixed": [ "fixed": [
"Various crashes from 3.7.1" "Various crashes from 3.7.1"
] ]
}, },
{ {
"versionCode": "2200", "versionCode": 2200,
"versionName": "3.7.1", "versionName": "3.7.1",
"fixed": [ "fixed": [
"Various crashes from 3.7.0" "Various crashes from 3.7.0"
] ]
}, },
{ {
"versionCode": "2198", "versionCode": 2198,
"versionName": "3.6.8", "versionName": "3.6.8",
"fixed": [ "fixed": [
"Messages can't be sent or received on older devices", "Messages can't be sent or received on older devices",
@@ -319,7 +320,7 @@
] ]
}, },
{ {
"versionCode": "2197", "versionCode": 2197,
"versionName": "3.6.7", "versionName": "3.6.7",
"added": [ "added": [
"Signature support", "Signature support",
@@ -19,6 +19,7 @@
package dev.octoshrimpy.quik.manager package dev.octoshrimpy.quik.manager
import android.content.Context import android.content.Context
import android.util.Log
import dev.octoshrimpy.quik.common.util.extensions.versionCode import dev.octoshrimpy.quik.common.util.extensions.versionCode
import dev.octoshrimpy.quik.util.Preferences import dev.octoshrimpy.quik.util.Preferences
import com.squareup.moshi.Json import com.squareup.moshi.Json
@@ -42,25 +43,33 @@ class ChangelogManagerImpl @Inject constructor(
private val prefs: Preferences private val prefs: Preferences
) : ChangelogManager { ) : ChangelogManager {
override fun didUpdate(): Boolean = prefs.changelogVersion.get() != context.versionCode override fun didUpdate(): Boolean = (prefs.changelogVersion.get() ?: 0) != context.versionCode
override suspend fun getChangelog(): ChangelogManager.CumulativeChangelog { override suspend fun getChangelog(): ChangelogManager.CumulativeChangelog {
val listType = Types.newParameterizedType(List::class.java, Changeset::class.java) val listType = Types.newParameterizedType(List::class.java, Changeset::class.java)
val adapter = moshi.adapter<List<Changeset>>(listType) val adapter = moshi.adapter<List<Changeset>>(listType)
return withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
val changelogs = context.assets.open("changelog.json").bufferedReader().use { it.readText() } try {
.let(adapter::fromJson) val changelogs = context.assets.open("changelog.json").bufferedReader().use { it.readText() }
.orEmpty() .let(adapter::fromJson)
.sortedBy { changelog -> changelog.versionCode } .orEmpty()
.filter { changelog -> .sortedBy { changelog -> changelog.versionCode }
changelog.versionCode in prefs.changelogVersion.get().inc()..context.versionCode .filter { changelog ->
} changelog.versionCode in (prefs.changelogVersion.get() ?: 0).inc()..context.versionCode
}
ChangelogManager.CumulativeChangelog( ChangelogManager.CumulativeChangelog(
added = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.added.orEmpty()}, added = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.added.orEmpty()},
improved = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.improved.orEmpty()}, improved = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.improved.orEmpty()},
fixed = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.fixed.orEmpty()}) removed = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.removed.orEmpty()},
fixed = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.fixed.orEmpty()}
)
} catch (e: Exception) {
Log.e("ChangelogManager", "Error parsing changelog JSON", e)
ChangelogManager.CumulativeChangelog(emptyList(), emptyList(), emptyList(), emptyList())
}
} }
} }
@@ -68,10 +77,11 @@ class ChangelogManagerImpl @Inject constructor(
prefs.changelogVersion.set(context.versionCode) prefs.changelogVersion.set(context.versionCode)
} }
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = false)
data class Changeset( data class Changeset(
@Json(name = "added") val added: List<String>?, @Json(name = "added") val added: List<String>?,
@Json(name = "improved") val improved: List<String>?, @Json(name = "improved") val improved: List<String>?,
@Json(name = "removed") val removed: List<String>?,
@Json(name = "fixed") val fixed: List<String>?, @Json(name = "fixed") val fixed: List<String>?,
@Json(name = "versionName") val versionName: String, @Json(name = "versionName") val versionName: String,
@Json(name = "versionCode") val versionCode: Int @Json(name = "versionCode") val versionCode: Int
@@ -23,6 +23,7 @@ interface ChangelogManager {
data class CumulativeChangelog( data class CumulativeChangelog(
val added: List<String>, val added: List<String>,
val improved: List<String>, val improved: List<String>,
val removed: List<String>,
val fixed: List<String> val fixed: List<String>
) )
+1 -1
View File
@@ -187,7 +187,7 @@ dependencies {
// moshi // moshi
implementation "com.squareup.moshi:moshi:$moshi_version" implementation "com.squareup.moshi:moshi:$moshi_version"
debugImplementation "com.squareup.moshi:moshi-kotlin:$moshi_version" debugImplementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
kaptRelease "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version" kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
// coroutines // coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
+5
View File
@@ -60,6 +60,11 @@
} }
# Retain generated JsonAdapters if annotated type is retained. # Retain generated JsonAdapters if annotated type is retained.
-keep class **JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class * -if @com.squareup.moshi.JsonClass class *
-keep class <1>JsonAdapter { -keep class <1>JsonAdapter {
<init>(...); <init>(...);
@@ -49,6 +49,11 @@ class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapte
changes += changelog.fixed.map { change -> ChangelogItem(1, "• $change") } changes += changelog.fixed.map { change -> ChangelogItem(1, "• $change") }
changes += ChangelogItem(0, "") changes += ChangelogItem(0, "")
} }
if (changelog.removed.isNotEmpty()) {
changes += ChangelogItem(0, context.getString(R.string.changelog_removed))
changes += changelog.removed.map { change -> ChangelogItem(1, "• $change") }
changes += ChangelogItem(0, "")
}
data = changes data = changes
} }
@@ -397,6 +397,7 @@
<string name="changelog_added" translatable="false">Added</string> <string name="changelog_added" translatable="false">Added</string>
<string name="changelog_improved" translatable="false">Improved</string> <string name="changelog_improved" translatable="false">Improved</string>
<string name="changelog_fixed" translatable="false">Fixed</string> <string name="changelog_fixed" translatable="false">Fixed</string>
<string name="changelog_removed" translatable="false">Removed</string>
<string name="changelog_more" translatable="false">More</string> <string name="changelog_more" translatable="false">More</string>
<string name="changelog_dismiss" translatable="false">Dismiss</string> <string name="changelog_dismiss" translatable="false">Dismiss</string>