Store changelog locally

#1708
This commit is contained in:
Moez Bhatti
2021-03-14 15:31:23 -04:00
parent 48a0803bc4
commit f766745e12
8 changed files with 314 additions and 102 deletions
@@ -32,21 +32,21 @@ class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapte
data class ChangelogItem(val type: Int, val label: String)
fun setChangelog(changelog: ChangelogManager.Changelog) {
fun setChangelog(changelog: ChangelogManager.CumulativeChangelog) {
val changes = mutableListOf<ChangelogItem>()
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
@@ -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()
}
@@ -388,7 +388,7 @@ class MainActivity : QkThemedActivity(), MainView {
.show()
}
override fun showChangelog(changelog: ChangelogManager.Changelog) {
override fun showChangelog(changelog: ChangelogManager.CumulativeChangelog) {
changelogDialog.show(changelog)
}
@@ -50,7 +50,7 @@ interface MainView : QkView<MainState> {
fun themeChanged()
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
fun showDeleteDialog(conversations: List<Long>)
fun showChangelog(changelog: ChangelogManager.Changelog)
fun showChangelog(changelog: ChangelogManager.CumulativeChangelog)
fun showArchivedSnackbar()
}
@@ -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()
}