Skip to content

Commit

Permalink
refactors changelog and version handling, fixes crash on startup due …
Browse files Browse the repository at this point in the history
…to version mismatch.
  • Loading branch information
octoshrimpy committed Nov 2, 2024
1 parent b2c5aab commit 2d90215
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ package dev.octoshrimpy.quik.common.util.extensions

import android.app.job.JobScheduler
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Build
import android.util.TypedValue
import android.widget.Toast
import androidx.annotation.StringRes
Expand Down Expand Up @@ -85,7 +87,12 @@ fun Context.isInstalled(packageName: String): Boolean {
}

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
get() = getSystemService()!!
57 changes: 29 additions & 28 deletions data/src/main/assets/changelog.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

[ {
"versionCode": "2225",
"versionCode": 2225,
"versionName": "4.0.8",
"fixed": [
"Padding on number input field for new message",
"Clean up telephony permissions",
"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",
"removed": [
"Analytics trackers",
Expand All @@ -19,22 +20,22 @@
]
},
{
"versionCode": "2223",
"versionCode": 2223,
"versionName": "4.0.6",
"fixed": [
"Renaming conversations has been patched."
]
},
{
"versionCode": "2222",
"versionCode": 2222,
"versionName": "4.0.5",
"fixed": [
],
"removed": [
]
},
{
"versionCode": "2221",
"versionCode": 2221,
"versionName": "4.0.4",
"fixed": [
"Revived!",
Expand All @@ -48,14 +49,14 @@
]
},
{
"versionCode": "2220",
"versionCode": 2220,
"versionName": "3.10.1",
"fixed": [
"Crash when launching the app"
]
},
{
"versionCode": "2219",
"versionCode": 2219,
"versionName": "3.10.0",
"added": [
"Support for Call Blocker (blocking manager)"
Expand All @@ -70,28 +71,28 @@
]
},
{
"versionCode": "2218",
"versionCode": 2218,
"versionName": "3.9.4",
"fixed": [
"Incorrect handling of shared text that contains a question mark"
]
},
{
"versionCode": "2217",
"versionCode": 2217,
"versionName": "3.9.3",
"improved": [
"Message sync is now 2x faster"
]
},
{
"versionCode": "2216",
"versionCode": 2216,
"versionName": "3.9.2",
"fixed": [
"Crash when launching app in 3.9.1"
]
},
{
"versionCode": "2215",
"versionCode": 2215,
"versionName": "3.9.1",
"improved": [
"Support SMS URIs that only have a body"
Expand All @@ -101,7 +102,7 @@
]
},
{
"versionCode": "2214",
"versionCode": 2214,
"versionName": "3.9.0",
"added": [
"Auto-delete old messages",
Expand Down Expand Up @@ -140,7 +141,7 @@
]
},
{
"versionCode": "2213",
"versionCode": 2213,
"versionName": "3.8.1",
"fixed": [
"MMS not sending",
Expand All @@ -150,22 +151,22 @@
]
},
{
"versionCode": "2212",
"versionCode": 2212,
"versionName": "3.8.0",
"improved": [
"Updated translations"
]
},
{
"versionCode": "2211",
"versionCode": 2211,
"versionName": "3.8.0-beta2",
"fixed": [
"Crash when starting new conversation",
"Swipe actions not working"
]
},
{
"versionCode": "2210",
"versionCode": 2210,
"versionName": "3.8.0-beta1",
"added": [
"Support for Contact Groups and Starred Contacts",
Expand Down Expand Up @@ -203,7 +204,7 @@
]
},
{
"versionCode": "2209",
"versionCode": 2209,
"versionName": "3.7.10",
"improved": [
"Include archived conversations in search results",
Expand All @@ -215,7 +216,7 @@
]
},
{
"versionCode": "2208",
"versionCode": 2208,
"versionName": "3.7.9",
"improved": [
"Better reliability for sending MMS"
Expand All @@ -225,7 +226,7 @@
]
},
{
"versionCode": "2207",
"versionCode": 2207,
"versionName": "3.7.8",
"fixed": [
"Contact not always linked to conversation",
Expand All @@ -234,14 +235,14 @@
]
},
{
"versionCode": "2206",
"versionCode": 2206,
"versionName": "3.7.7",
"fixed": [
"New conversations may not appear in inbox"
]
},
{
"versionCode": "2204",
"versionCode": 2204,
"versionName": "3.7.5",
"added": [
"Added ability to retry sending failed MMS"
Expand All @@ -259,7 +260,7 @@
]
},
{
"versionCode": "2203",
"versionCode": 2203,
"versionName": "3.7.4",
"added": [
"Support for Android Q Roles"
Expand All @@ -274,7 +275,7 @@
]
},
{
"versionCode": "2202",
"versionCode": 2202,
"versionName": "3.7.3",
"added": [
"You can now view attachments of any filetype"
Expand All @@ -297,29 +298,29 @@
]
},
{
"versionCode": "2201",
"versionCode": 2201,
"versionName": "3.7.2",
"fixed": [
"Various crashes from 3.7.1"
]
},
{
"versionCode": "2200",
"versionCode": 2200,
"versionName": "3.7.1",
"fixed": [
"Various crashes from 3.7.0"
]
},
{
"versionCode": "2198",
"versionCode": 2198,
"versionName": "3.6.8",
"fixed": [
"Messages can't be sent or received on older devices",
"Norweigan translations not working"
]
},
{
"versionCode": "2197",
"versionCode": 2197,
"versionName": "3.6.7",
"added": [
"Signature support",
Expand Down
36 changes: 23 additions & 13 deletions data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package dev.octoshrimpy.quik.manager

import android.content.Context
import android.util.Log
import dev.octoshrimpy.quik.common.util.extensions.versionCode
import dev.octoshrimpy.quik.util.Preferences
import com.squareup.moshi.Json
Expand All @@ -42,36 +43,45 @@ class ChangelogManagerImpl @Inject constructor(
private val prefs: Preferences
) : 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 {
val listType = Types.newParameterizedType(List::class.java, Changeset::class.java)
val adapter = moshi.adapter<List<Changeset>>(listType)

return withContext(Dispatchers.IO) {
val changelogs = context.assets.open("changelog.json").bufferedReader().use { it.readText() }
.let(adapter::fromJson)
.orEmpty()
.sortedBy { changelog -> changelog.versionCode }
.filter { changelog ->
changelog.versionCode in prefs.changelogVersion.get().inc()..context.versionCode
}
try {
val changelogs = context.assets.open("changelog.json").bufferedReader().use { it.readText() }
.let(adapter::fromJson)
.orEmpty()
.sortedBy { changelog -> changelog.versionCode }
.filter { changelog ->
changelog.versionCode in (prefs.changelogVersion.get() ?: 0).inc()..context.versionCode
}

ChangelogManager.CumulativeChangelog(
added = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.added.orEmpty()},
improved = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.improved.orEmpty()},
fixed = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.fixed.orEmpty()})
ChangelogManager.CumulativeChangelog(
added = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.added.orEmpty()},
improved = changelogs.fold(listOf()) { acc, changelog -> acc + changelog.improved.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())
}
}
}

override fun markChangelogSeen() {
prefs.changelogVersion.set(context.versionCode)
}

@JsonClass(generateAdapter = true)
@JsonClass(generateAdapter = false)
data class Changeset(
@Json(name = "added") val added: 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 = "versionName") val versionName: String,
@Json(name = "versionCode") val versionCode: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface ChangelogManager {
data class CumulativeChangelog(
val added: List<String>,
val improved: List<String>,
val removed: List<String>,
val fixed: List<String>
)

Expand Down
2 changes: 1 addition & 1 deletion presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ dependencies {
// moshi
implementation "com.squareup.moshi:moshi:$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
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
Expand Down
5 changes: 5 additions & 0 deletions presentation/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
}

# Retain generated JsonAdapters if annotated type is retained.
-keep class **JsonAdapter {
<init>(...);
<fields>;
}

-if @com.squareup.moshi.JsonClass class *
-keep class <1>JsonAdapter {
<init>(...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapte
changes += changelog.fixed.map { change -> ChangelogItem(1, "$change") }
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
}

Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@
<string name="changelog_added" translatable="false">Added</string>
<string name="changelog_improved" translatable="false">Improved</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_dismiss" translatable="false">Dismiss</string>

Expand Down

0 comments on commit 2d90215

Please sign in to comment.