From f766745e127b97509d7af610399c5515021c1264 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 14 Mar 2021 15:31:23 -0400 Subject: [PATCH] Store changelog locally #1708 --- data/src/main/assets/changelog.json | 272 ++++++++++++++++++ .../QKSMS/manager/ChangelogManagerImpl.kt | 110 ++----- .../moez/QKSMS/manager/ChangelogManager.kt | 6 +- .../feature/changelog/ChangelogAdapter.kt | 8 +- .../feature/changelog/ChangelogDialog.kt | 2 +- .../moez/QKSMS/feature/main/MainActivity.kt | 2 +- .../com/moez/QKSMS/feature/main/MainView.kt | 2 +- .../moez/QKSMS/feature/main/MainViewModel.kt | 14 +- 8 files changed, 314 insertions(+), 102 deletions(-) create mode 100644 data/src/main/assets/changelog.json diff --git a/data/src/main/assets/changelog.json b/data/src/main/assets/changelog.json new file mode 100644 index 00000000..c4d2e917 --- /dev/null +++ b/data/src/main/assets/changelog.json @@ -0,0 +1,272 @@ +[ + { + "versionCode": "2218", + "versionName": "3.9.4", + "fixed": [ + "Incorrect handling of shared text that contains a question mark" + ] + }, + { + "versionCode": "2217", + "versionName": "3.9.3", + "improved": [ + "Message sync is now 2x faster" + ] + }, + { + "versionCode": "2216", + "versionName": "3.9.2", + "fixed": [ + "Crash when launching app in 3.9.1" + ] + }, + { + "versionCode": "2215", + "versionName": "3.9.1", + "improved": [ + "Support SMS URIs that only have a body" + ], + "fixed": [ + "Slowness introduced in 3.9.0" + ] + }, + { + "versionCode": "2214", + "versionName": "3.9.0", + "added": [ + "Auto-delete old messages", + "Block/archive messages from notification", + "Swipe to block conversation", + "Share vCard from other apps" + ], + "improved": [ + "Better visibility for conversations with drafts", + "Remember send-as-group preference", + "Shorten \"mark read\" string for notification actions", + "Clarify delayed message durations", + "Trim whitespace when searching", + "Line count limit for contact groups in compose screen", + "Buzz and show warning when SIM is changed", + "Removed Mixpanel" + ], + "fixed": [ + "Incorrect selection state when picking contact phone number", + "Max height for QK dialog", + "Duplicate phone numbers when multiple contacts apps are installed", + "Swipe state gets stuck when marking read conversation as read again", + "Titles and special characters included in contact's initials", + "Subject text not included when sharing", + "Message history not appearing", + "Dismiss notification for failed message not working", + "Incorrect padding for SIM selector", + "Incorrect padding for contact search", + "Incorrect empty state for messasge search", + "Pressing enter creates line break when searching", + "Crash when composing message", + "Scheduled message date picker can be blocked by keyboard", + "Cursor set to wrong position when cancelling message", + "Can't share to group via Simple Contacts", + "\"View more conversations\" button on widget broken" + ] + }, + { + "versionCode": "2213", + "versionName": "3.8.1", + "fixed": [ + "MMS not sending", + "Crash when deleting conversation", + "Crash on startup when upgrading from old version", + "Contact Groups not showing up in some cases" + ] + }, + { + "versionCode": "2212", + "versionName": "3.8.0", + "improved": [ + "Updated translations" + ] + }, + { + "versionCode": "2211", + "versionName": "3.8.0-beta2", + "fixed": [ + "Crash when starting new conversation", + "Swipe actions not working" + ] + }, + { + "versionCode": "2210", + "versionName": "3.8.0-beta1", + "added": [ + "Support for Contact Groups and Starred Contacts", + "Wake screen setting", + "Per-contact colours", + "Automatic colours", + "Option to send long messages as MMS", + "Long-press recipient to copy phone number", + "Copy text from multiple messages", + "Share photos externally" + ], + "improved": [ + "Redesigned compose message screen", + "Redesigned avatars", + "More reliable contact photo loading", + "Custom colours for contacts will appear everywhere, not just inside the conversation", + "More intuitive unicode stripping", + "Make drafts easier to find", + "Faster scrolling performance everywhere", + "Increased max signature length" + ], + "fixed": [ + "Sent attachments are always low quality", + "Not receiving all MMS", + "Contact name/photo might be out of sync with contacts app", + "MMS might appear in the wrong thread", + "Duplicate phone numbers appear when Whatsapp is installed", + "Can't share to multiple people via another app", + "Body not parsed correctly in SMS Uri", + "Notification sounds not working on Android 7", + "Sometimes can't add number to contacts", + "Default SMS \"CHANGE\" button sometimes doesn't work", + "24h timestamps don't work correctly when language set to Japanese", + "Conversation details page slow when there are lots of attachments" + ] + }, + { + "versionCode": "2209", + "versionName": "3.7.10", + "improved": [ + "Include archived conversations in search results", + "Allow manually blocking non-numeric addresses" + ], + "fixed": [ + "MMS appear to have sent, but they haven't", + "New conversations sometimes don't appear" + ] + }, + { + "versionCode": "2208", + "versionName": "3.7.9", + "improved": [ + "Better reliability for sending MMS" + ], + "fixed": [ + "Fixed delayed messages getting stuck \"Sending...\"" + ] + }, + { + "versionCode": "2207", + "versionName": "3.7.8", + "fixed": [ + "Contact not always linked to conversation", + "Wrong colour for disabled preference icons", + "Multiple crashes" + ] + }, + { + "versionCode": "2206", + "versionName": "3.7.7", + "fixed": [ + "New conversations may not appear in inbox" + ] + }, + { + "versionCode": "2204", + "versionName": "3.7.5", + "added": [ + "Added ability to retry sending failed MMS" + ], + "improved": [ + "Show hint for signature setting", + "Keep widget more up-to-date", + "Improve MMS support for Dual-SIM phones", + "Display sent time for incoming MMS", + "Improve MMS sending reliability" + ], + "fixed": [ + "Contacts sometimes not linked to conversation correctly", + "Sometimes can't save multiple attachments to phone" + ] + }, + { + "versionCode": "2203", + "versionName": "3.7.4", + "added": [ + "Support for Android Q Roles" + ], + "improved": [ + "Use theme color for text cursor", + "Better matching between phone number and conversation" + ], + "fixed": [ + "Messages often stuck \"Sending...\"", + "Short codes won't show up as valid number when composing new message" + ] + }, + { + "versionCode": "2202", + "versionName": "3.7.3", + "added": [ + "You can now view attachments of any filetype" + ], + "improved": [ + "Improve search for contacts with accents in their names", + "Custom labels for phone numbers will show the custom text", + "Include MMS in search results", + "Made it easier to access blocked numbers list", + "Added option to add number to contacts from main conversation list", + "Conversations with drafts will be indicated appropriately in conversation list", + "You can now copy text from a scheduled message", + "Show blocking reason for numbers blocked via Call Control" + ], + "fixed": [ + "Can't open vCard attachments", + "Phone number gets blocked when it shouldn't", + "Icon gets stretched when swiping conversation", + "Can't forward text in MMS message" + ] + }, + { + "versionCode": "2201", + "versionName": "3.7.2", + "fixed": [ + "Various crashes from 3.7.1" + ] + }, + { + "versionCode": "2200", + "versionName": "3.7.1", + "fixed": [ + "Various crashes from 3.7.0" + ] + }, + { + "versionCode": "2198", + "versionName": "3.6.8", + "fixed": [ + "Messages can't be sent or received on older devices", + "Norweigan translations not working" + ] + }, + { + "versionCode": "2197", + "versionName": "3.6.7", + "added": [ + "Signature support", + "System dark mode support for Android Q" + ], + "improved": [ + "You'll be asked for storage permission before trying to save a photo if necessary", + "Smaller download size", + "Load high resolution contact photos" + ], + "fixed": [ + "Contact photos never update", + "Can't create new conversation on Huawei devices", + "Can't receive MMS on Xiaomi devices", + "Visual glitch on compose bar in night mode", + "Theme doesn't update in preview after going back to settings", + "Search hint gets cut off after rotating screen" + ] + } +] diff --git a/data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt b/data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt index 3b09f6d2..6d414de0 100644 --- a/data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt @@ -24,14 +24,14 @@ import com.moez.QKSMS.util.Preferences import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import com.squareup.moshi.Moshi +import com.squareup.moshi.Types import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import okhttp3.Call import okhttp3.Callback -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -import okhttp3.OkHttpClient -import okhttp3.Request import okhttp3.Response import java.io.IOException import javax.inject.Inject @@ -44,54 +44,24 @@ class ChangelogManagerImpl @Inject constructor( override fun didUpdate(): Boolean = prefs.changelogVersion.get() != context.versionCode - override fun getChangelog(): Single { - val url = "https://firestore.googleapis.com/v1/projects/qksms-app/databases/(default)/documents/changelog" - val request = url.toHttpUrlOrNull()?.let { Request.Builder().url(it).build() } - val call = request?.let { OkHttpClient().newCall(it) } - val adapter = moshi.adapter(ChangelogResponse::class.java) + override suspend fun getChangelog(): ChangelogManager.CumulativeChangelog { + val listType = Types.newParameterizedType(List::class.java, Changeset::class.java) + val adapter = moshi.adapter>(listType) - return Single - .create { emitter -> - call?.enqueue(object : Callback { - override fun onResponse(call: Call, response: Response) { - if (!emitter.isDisposed) { - emitter.onSuccess(response) - } - } + 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 + } - override fun onFailure(call: Call, e: IOException) { - if (!emitter.isDisposed) { - emitter.onError(e) - } - } - }) - emitter.setCancellable { - call?.cancel() - } - } - .map { response -> response.body?.string()?.let(adapter::fromJson) } - .map { response -> - response.documents - .sortedBy { document -> document.fields.versionCode.value } - .filter { document -> - val range = (prefs.changelogVersion.get() + 1)..context.versionCode - document.fields.versionCode.value.toInt() in range - } - } - .map { documents -> - val added = documents.fold(listOf()) { acc, document -> - acc + document.fields.added?.value?.values?.map { value -> value.value }.orEmpty() - } - val improved = documents.fold(listOf()) { acc, document -> - acc + document.fields.improved?.value?.values?.map { value -> value.value }.orEmpty() - } - val fixed = documents.fold(listOf()) { acc, document -> - acc + document.fields.fixed?.value?.values?.map { value -> value.value }.orEmpty() - } - ChangelogManager.Changelog(added, improved, fixed) - } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + 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()}) + } } override fun markChangelogSeen() { @@ -99,42 +69,12 @@ class ChangelogManagerImpl @Inject constructor( } @JsonClass(generateAdapter = true) - data class ChangelogResponse( - @Json(name = "documents") val documents: List - ) - - @JsonClass(generateAdapter = true) - data class Document( - @Json(name = "fields") val fields: Changelog - ) - - @JsonClass(generateAdapter = true) - data class Changelog( - @Json(name = "added") val added: ArrayField?, - @Json(name = "improved") val improved: ArrayField?, - @Json(name = "fixed") val fixed: ArrayField?, - @Json(name = "versionName") val versionName: StringField, - @Json(name = "versionCode") val versionCode: IntegerField - ) - - @JsonClass(generateAdapter = true) - data class ArrayField( - @Json(name = "arrayValue") val value: ArrayValues - ) - - @JsonClass(generateAdapter = true) - data class ArrayValues( - @Json(name = "values") val values: List - ) - - @JsonClass(generateAdapter = true) - data class StringField( - @Json(name = "stringValue") val value: String - ) - - @JsonClass(generateAdapter = true) - data class IntegerField( - @Json(name = "integerValue") val value: String + data class Changeset( + @Json(name = "added") val added: List?, + @Json(name = "improved") val improved: List?, + @Json(name = "fixed") val fixed: List?, + @Json(name = "versionName") val versionName: String, + @Json(name = "versionCode") val versionCode: Int ) } diff --git a/domain/src/main/java/com/moez/QKSMS/manager/ChangelogManager.kt b/domain/src/main/java/com/moez/QKSMS/manager/ChangelogManager.kt index 37f714b7..4ba22f8b 100644 --- a/domain/src/main/java/com/moez/QKSMS/manager/ChangelogManager.kt +++ b/domain/src/main/java/com/moez/QKSMS/manager/ChangelogManager.kt @@ -18,11 +18,9 @@ */ package com.moez.QKSMS.manager -import io.reactivex.Single - interface ChangelogManager { - data class Changelog( + data class CumulativeChangelog( val added: List, val improved: List, val fixed: List @@ -33,7 +31,7 @@ interface ChangelogManager { */ fun didUpdate(): Boolean - fun getChangelog(): Single + suspend fun getChangelog(): CumulativeChangelog fun markChangelogSeen() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogAdapter.kt index 43de0339..efba6cfc 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogAdapter.kt @@ -32,21 +32,21 @@ class ChangelogAdapter(private val context: Context) : QkAdapter() if (changelog.added.isNotEmpty()) { changes += ChangelogItem(0, context.getString(R.string.changelog_added)) - changes += changelog.added.map { change -> ChangelogItem(1, change) } + changes += changelog.added.map { change -> ChangelogItem(1, "• $change") } changes += ChangelogItem(0, "") } if (changelog.improved.isNotEmpty()) { changes += ChangelogItem(0, context.getString(R.string.changelog_improved)) - changes += changelog.improved.map { change -> ChangelogItem(1, change) } + changes += changelog.improved.map { change -> ChangelogItem(1, "• $change") } changes += ChangelogItem(0, "") } if (changelog.fixed.isNotEmpty()) { changes += ChangelogItem(0, context.getString(R.string.changelog_fixed)) - changes += changelog.fixed.map { change -> ChangelogItem(1, change) } + changes += changelog.fixed.map { change -> ChangelogItem(1, "• $change") } changes += ChangelogItem(0, "") } data = changes diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogDialog.kt b/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogDialog.kt index 04dc1d4c..9d0deba6 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogDialog.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/changelog/ChangelogDialog.kt @@ -49,7 +49,7 @@ class ChangelogDialog(activity: MainActivity) { layout.dismiss.setOnClickListener { dialog.dismiss() } } - fun show(changelog: ChangelogManager.Changelog) { + fun show(changelog: ChangelogManager.CumulativeChangelog) { adapter.setChangelog(changelog) dialog.show() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt index 068bc4be..362f66a6 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt @@ -388,7 +388,7 @@ class MainActivity : QkThemedActivity(), MainView { .show() } - override fun showChangelog(changelog: ChangelogManager.Changelog) { + override fun showChangelog(changelog: ChangelogManager.CumulativeChangelog) { changelogDialog.show(changelog) } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt index 47511e09..70bbf36b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt @@ -50,7 +50,7 @@ interface MainView : QkView { fun themeChanged() fun showBlockingDialog(conversations: List, block: Boolean) fun showDeleteDialog(conversations: List) - fun showChangelog(changelog: ChangelogManager.Changelog) + fun showChangelog(changelog: ChangelogManager.CumulativeChangelog) fun showArchivedSnackbar() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt index f79b1928..e4fec32b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt @@ -50,6 +50,9 @@ import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.withLatestFrom import io.reactivex.schedulers.Schedulers import io.realm.Realm +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import java.util.* import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -168,12 +171,11 @@ class MainViewModel @Inject constructor( // Show changelog if (changelogManager.didUpdate()) { if (Locale.getDefault().language.startsWith("en")) { - disposables += changelogManager.getChangelog() - .timeout(3, TimeUnit.SECONDS) // If it takes long than 3s, we'll just try again next time - .subscribe({ changelog -> - changelogManager.markChangelogSeen() - view.showChangelog(changelog) - }, {}) // Ignore error + GlobalScope.launch(Dispatchers.Main) { + val changelog = changelogManager.getChangelog() + changelogManager.markChangelogSeen() + view.showChangelog(changelog) + } } else { changelogManager.markChangelogSeen() }