aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-23 16:39:31 -0700
committerAllan Wang <me@allanwang.ca>2017-06-23 16:39:31 -0700
commit9b916cc37572bec9234fa1b60c9e2241e384d939 (patch)
treef0f1d9a03a90966b9e3940e29bb30ee4d323582e
parentd6b4ebb938e5efd2900ee9c7f50dddffb856d2fa (diff)
downloadkau-9b916cc37572bec9234fa1b60c9e2241e384d939.tar.gz
kau-9b916cc37572bec9234fa1b60c9e2241e384d939.tar.bz2
kau-9b916cc37572bec9234fa1b60c9e2241e384d939.zip
Themable changelog
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/changelog/Changelog.kt36
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt21
-rw-r--r--library/src/main/res/layout/kau_changelog_content.xml1
3 files changed, 34 insertions, 24 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/changelog/Changelog.kt b/library/src/main/kotlin/ca/allanwang/kau/changelog/Changelog.kt
index bca9b12..074bc35 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/changelog/Changelog.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/changelog/Changelog.kt
@@ -2,6 +2,8 @@ package ca.allanwang.kau.changelog
import android.content.Context
import android.content.res.XmlResourceParser
+import android.os.Handler
+import android.support.annotation.ColorInt
import android.support.annotation.LayoutRes
import android.support.annotation.XmlRes
import android.support.v7.widget.RecyclerView
@@ -10,22 +12,49 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import ca.allanwang.kau.R
+import ca.allanwang.kau.utils.bindOptionalView
+import ca.allanwang.kau.utils.bindView
+import com.afollestad.materialdialogs.MaterialDialog
import org.xmlpull.v1.XmlPullParser
+import java.util.*
/**
* Created by Allan Wang on 2017-05-28.
- *
+ */
+
+fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.Builder.() -> Unit = {}) {
+ val mHandler = Handler()
+ Thread(Runnable {
+ val items = parse(this, xmlRes)
+ mHandler.post(object : TimerTask() {
+ override fun run() {
+ val builder = MaterialDialog.Builder(this@showChangelog)
+ .title(R.string.kau_changelog)
+ .positiveText(R.string.kau_great)
+ .adapter(ChangelogAdapter(items, textColor), null)
+ builder.customize()
+ builder.show()
+ }
+ })
+ }).start()
+}
+
+/**
* Internals of the changelog dialog
* Contains an adapter for each item, as well as the tags to parse
*/
-internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>) : RecyclerView.Adapter<ChangelogAdapter.ChangelogVH>() {
+internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>, @ColorInt val textColor: Int? = null) : RecyclerView.Adapter<ChangelogAdapter.ChangelogVH>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ChangelogVH(LayoutInflater.from(parent.context)
.inflate(items[viewType].second.layout, parent, false))
override fun onBindViewHolder(holder: ChangelogVH, position: Int) {
holder.text.text = items[position].first
+ if (textColor != null) {
+ holder.text.setTextColor(textColor)
+ holder.bullet?.setTextColor(textColor)
+ }
}
override fun getItemId(position: Int) = position.toLong()
@@ -35,7 +64,8 @@ internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>) :
override fun getItemCount() = items.size
internal class ChangelogVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
- val text: TextView = itemView.findViewById<TextView>(R.id.kau_changelog_text)
+ val text: TextView by bindView(R.id.kau_changelog_text)
+ val bullet: TextView? by bindOptionalView(R.id.kau_changelog_text)
}
}
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 72a808a..7597f80 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -7,17 +7,13 @@ import android.graphics.drawable.Drawable
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Bundle
-import android.os.Handler
import android.support.annotation.*
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import android.util.TypedValue
import android.widget.Toast
import ca.allanwang.kau.R
-import ca.allanwang.kau.changelog.ChangelogAdapter
-import ca.allanwang.kau.changelog.parse
import com.afollestad.materialdialogs.MaterialDialog
-import java.util.*
/**
@@ -108,23 +104,6 @@ fun Context.resolveString(@AttrRes attr: Int, fallback: String = ""): String {
return if (theme.resolveAttribute(attr, v, true)) v.string.toString() else fallback
}
-fun Context.showChangelog(@XmlRes xmlRes: Int, customize: MaterialDialog.Builder.() -> Unit = {}) {
- val mHandler = Handler()
- Thread(Runnable {
- val items = parse(this, xmlRes)
- mHandler.post(object : TimerTask() {
- override fun run() {
- val builder = MaterialDialog.Builder(this@showChangelog)
- .title(R.string.kau_changelog)
- .positiveText(R.string.kau_great)
- .adapter(ChangelogAdapter(items), null)
- builder.customize()
- builder.show()
- }
- })
- }).start()
-}
-
/**
* Wrapper function for the MaterialDialog adapterBuilder
* There is no need to call build() or show() as those are done by default
diff --git a/library/src/main/res/layout/kau_changelog_content.xml b/library/src/main/res/layout/kau_changelog_content.xml
index 90cca40..92b87b9 100644
--- a/library/src/main/res/layout/kau_changelog_content.xml
+++ b/library/src/main/res/layout/kau_changelog_content.xml
@@ -10,6 +10,7 @@
<!--padding bottom is 14sp * 0.6-->
<TextView
+ android:id="@+id/kau_changelog_bullet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.6"