Show changelog after app update

This commit is contained in:
moezbhatti
2019-06-17 02:17:30 -04:00
parent 74268a2c96
commit 274b217a56
14 changed files with 394 additions and 1 deletions
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.changelog
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 kotlinx.android.synthetic.main.changelog_list_item.*
class ChangelogAdapter(val keywords: List<String>, data: List<String>) : QkAdapter<String>() {
init {
this.data = data
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.changelog_list_item, parent, false)
return QkViewHolder(view).apply {
if (viewType == 0) {
changelogItem.setTypeface(changelogItem.typeface, Typeface.BOLD)
}
}
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val item = getItem(position)
holder.changelogItem.text = item
}
override fun getItemViewType(position: Int): Int {
return if (getItem(position) in keywords) 0 else 1
}
}
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.changelog
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.R
import com.moez.QKSMS.feature.main.MainActivity
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.changelog_dialog.view.*
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())
init {
val layout = LayoutInflater.from(activity).inflate(R.layout.changelog_dialog, null)
dialog = AlertDialog.Builder(activity)
.setCancelable(true)
.setView(layout)
.create()
layout.version.text = activity.getString(R.string.changelog_version, BuildConfig.VERSION_NAME)
layout.changelog.adapter = adapter
layout.more.setOnClickListener { dialog.dismiss(); moreClicks.onNext(Unit) }
layout.dismiss.setOnClickListener { dialog.dismiss() }
}
fun show() = dialog.show()
}
@@ -52,6 +52,7 @@ import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
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.repository.SyncRepository
@@ -105,6 +106,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 undoArchiveIntent: Subject<Unit> = PublishSubject.create()
override val snackbarButtonIntent: Subject<Unit> = PublishSubject.create()
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
@@ -113,6 +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 archiveSnackbar by lazy {
Snackbar.make(drawerLayout, R.string.toast_archived, Snackbar.LENGTH_LONG).apply {
setAction(R.string.button_undo) { undoArchiveIntent.onNext(Unit) }
@@ -344,6 +347,10 @@ class MainActivity : QkThemedActivity(), MainView {
.show()
}
override fun showChangelog() {
changelog.show()
}
override fun showArchivedSnackbar() {
archiveSnackbar.show()
}
@@ -36,6 +36,7 @@ interface MainView : QkView<MainState> {
val conversationsSelectedIntent: Observable<List<Long>>
val confirmDeleteIntent: Observable<List<Long>>
val swipeConversationIntent: Observable<Pair<Long, Int>>
val changelogMoreIntent: Observable<*>
val undoArchiveIntent: Observable<Unit>
val snackbarButtonIntent: Observable<Unit>
val backPressedIntent: Observable<Unit>
@@ -44,6 +45,7 @@ interface MainView : QkView<MainState> {
fun clearSearch()
fun clearSelection()
fun showDeleteDialog(conversations: List<Long>)
fun showChangelog()
fun showArchivedSnackbar()
}
@@ -36,6 +36,7 @@ import com.moez.QKSMS.interactor.MarkUnpinned
import com.moez.QKSMS.interactor.MarkUnread
import com.moez.QKSMS.interactor.MigratePreferences
import com.moez.QKSMS.interactor.SyncMessages
import com.moez.QKSMS.manager.ChangelogManager
import com.moez.QKSMS.manager.PermissionManager
import com.moez.QKSMS.manager.RatingManager
import com.moez.QKSMS.model.SyncLog
@@ -57,6 +58,7 @@ class MainViewModel @Inject constructor(
markAllSeen: MarkAllSeen,
migratePreferences: MigratePreferences,
syncRepository: SyncRepository,
private val changelogManager: ChangelogManager,
private val conversationRepo: ConversationRepository,
private val deleteConversations: DeleteConversations,
private val markArchived: MarkArchived,
@@ -141,6 +143,15 @@ class MainViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { syncMessages.execute(Unit) }
// Show changelog
if (changelogManager.didUpdate()) {
view.showChangelog()
}
view.changelogMoreIntent
.autoDisposable(view.scope())
.subscribe { navigator.showChangelog() }
view.queryChangedIntent
.debounce(200, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())