forked from upstream-mirrors/quik
Add support for cumulative changelogs
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user