Add support for cumulative changelogs

This commit is contained in:
moezbhatti
2019-08-30 20:05:38 +02:00
parent f92afde645
commit 3200956f4f
10 changed files with 156 additions and 52 deletions
@@ -18,18 +18,38 @@
*/
package com.moez.QKSMS.feature.changelog
import android.content.Context
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.manager.ChangelogManager
import kotlinx.android.synthetic.main.changelog_list_item.*
class ChangelogAdapter(val keywords: List<String>, data: List<String>) : QkAdapter<String>() {
class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapter.ChangelogItem>() {
init {
this.data = data
data class ChangelogItem(val type: Int, val label: String)
fun setChangelog(changelog: ChangelogManager.Changelog) {
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 += ChangelogItem(0, "")
}
if (changelog.improved.isNotEmpty()) {
changes += ChangelogItem(0, context.getString(R.string.changelog_improved))
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 += ChangelogItem(0, "")
}
data = changes
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
@@ -44,11 +64,11 @@ class ChangelogAdapter(val keywords: List<String>, data: List<String>) : QkAdapt
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val item = getItem(position)
holder.changelogItem.text = item
holder.changelogItem.text = item.label
}
override fun getItemViewType(position: Int): Int {
return if (getItem(position) in keywords) 0 else 1
return getItem(position).type
}
}
@@ -23,6 +23,7 @@ import androidx.appcompat.app.AlertDialog
import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.R
import com.moez.QKSMS.feature.main.MainActivity
import com.moez.QKSMS.manager.ChangelogManager
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.changelog_dialog.view.*
@@ -32,9 +33,7 @@ class ChangelogDialog(activity: MainActivity) {
val moreClicks: Subject<Unit> = PublishSubject.create()
private val dialog: AlertDialog
private val adapter = ChangelogAdapter(
activity.resources.getStringArray(R.array.changelog_keywords).asList(),
activity.resources.getStringArray(R.array.changelog).asList())
private val adapter = ChangelogAdapter(activity)
init {
val layout = LayoutInflater.from(activity).inflate(R.layout.changelog_dialog, null)
@@ -50,6 +49,9 @@ class ChangelogDialog(activity: MainActivity) {
layout.dismiss.setOnClickListener { dialog.dismiss() }
}
fun show() = dialog.show()
fun show(changelog: ChangelogManager.Changelog) {
adapter.setChangelog(changelog)
dialog.show()
}
}
@@ -53,6 +53,7 @@ import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.feature.changelog.ChangelogDialog
import com.moez.QKSMS.feature.conversations.ConversationItemTouchCallback
import com.moez.QKSMS.feature.conversations.ConversationsAdapter
import com.moez.QKSMS.manager.ChangelogManager
import com.moez.QKSMS.repository.SyncRepository
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
@@ -106,7 +107,7 @@ class MainActivity : QkThemedActivity(), MainView {
override val conversationsSelectedIntent by lazy { conversationsAdapter.selectionChanges }
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()
override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
override val changelogMoreIntent by lazy { changelog.moreClicks }
override val changelogMoreIntent by lazy { changelogDialog.moreClicks }
override val undoArchiveIntent: Subject<Unit> = PublishSubject.create()
override val snackbarButtonIntent: Subject<Unit> = PublishSubject.create()
@@ -114,7 +115,7 @@ class MainActivity : QkThemedActivity(), MainView {
private val toggle by lazy { ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.main_drawer_open_cd, 0) }
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
private val progressAnimator by lazy { ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0) }
private val changelog by lazy { ChangelogDialog(this) }
private val changelogDialog by lazy { ChangelogDialog(this) }
private val snackbar by lazy { findViewById<View>(R.id.snackbar) }
private val syncing by lazy { findViewById<View>(R.id.syncing) }
private val backPressedSubject: Subject<NavItem> = PublishSubject.create()
@@ -342,8 +343,8 @@ class MainActivity : QkThemedActivity(), MainView {
.show()
}
override fun showChangelog() {
changelog.show()
override fun showChangelog(changelog: ChangelogManager.Changelog) {
changelogDialog.show(changelog)
}
override fun showArchivedSnackbar() {
@@ -19,6 +19,7 @@
package com.moez.QKSMS.feature.main
import com.moez.QKSMS.common.base.QkView
import com.moez.QKSMS.manager.ChangelogManager
import io.reactivex.Observable
interface MainView : QkView<MainState> {
@@ -44,7 +45,7 @@ interface MainView : QkView<MainState> {
fun clearSearch()
fun clearSelection()
fun showDeleteDialog(conversations: List<Long>)
fun showChangelog()
fun showChangelog(changelog: ChangelogManager.Changelog)
fun showArchivedSnackbar()
}
@@ -50,6 +50,7 @@ import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import io.reactivex.schedulers.Schedulers
import io.realm.Realm
import timber.log.Timber
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -145,8 +146,17 @@ class MainViewModel @Inject constructor(
.subscribe { syncMessages.execute(Unit) }
// Show changelog
if (changelogManager.didUpdate() && Locale.getDefault().language.startsWith("en")) {
view.showChangelog()
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)
}, Timber::w)
} else {
changelogManager.markChangelogSeen()
}
}
view.changelogMoreIntent