aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-29 22:58:21 -0700
committerAllan Wang <me@allanwang.ca>2017-06-29 22:58:21 -0700
commit744b7680104eeead46345ede9d5a1aa22820247f (patch)
tree66955ee875188253f8b3429a873b1f47f8737d77 /library
parentf981c3e26b2a651326d8b5170fe086fa6fff3990 (diff)
downloadkau-744b7680104eeead46345ede9d5a1aa22820247f.tar.gz
kau-744b7680104eeead46345ede9d5a1aa22820247f.tar.bz2
kau-744b7680104eeead46345ede9d5a1aa22820247f.zip
Prepare release
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt11
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt10
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/iitems/LibraryIItem.kt30
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt10
-rw-r--r--library/src/main/res/layout/kau_iitem_library.xml2
6 files changed, 41 insertions, 23 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
index 1b80a46..9484299 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
@@ -79,6 +79,7 @@ abstract class AboutActivityBase(val rClass: Class<*>, val configBuilder: Config
setContentView(R.layout.kau_activity_about)
pageStatus = IntArray(pageCount)
libAdapter = FastItemThemedAdapter(configs)
+ LibraryIItem.bindClickEvents(libAdapter)
if (configs.textColor != null) indicator.setColour(configs.textColor!!)
with(pager) {
adapter = AboutPagerAdapter()
diff --git a/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
index f7a0ecb..06222a8 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
@@ -4,6 +4,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import ca.allanwang.kau.utils.adjustAlpha
+import ca.allanwang.kau.views.createSimpleRippleDrawable
import com.mikepenz.fastadapter.IExpandable
import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.ISubItem
@@ -121,7 +122,7 @@ interface ThemableIItemColors {
var accentColor: Int?
}
-class ThemableIItemColorsDelegate: ThemableIItemColors {
+class ThemableIItemColorsDelegate : ThemableIItemColors {
override var textColor: Int? = null
override var backgroundColor: Int? = null
override var accentColor: Int? = null
@@ -138,6 +139,7 @@ interface ThemableIItem : ThemableIItemColors {
fun bindDividerColor(vararg views: View)
fun bindAccentColor(vararg views: TextView)
fun bindBackgroundColor(vararg views: View)
+ fun bindBackgroundRipple(vararg views: View)
fun bindIconColor(vararg views: ImageView)
}
@@ -172,6 +174,13 @@ class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIIte
views.forEach { it.setBackgroundColor(color) }
}
+ override fun bindBackgroundRipple(vararg views: View) {
+ val foreground = accentColor ?: textColor ?: return
+ val background = backgroundColor ?: return
+ val ripple = createSimpleRippleDrawable(foreground, background)
+ views.forEach { it.background = ripple }
+ }
+
override fun bindIconColor(vararg views: ImageView) {
val color = accentColor ?: textColor ?: return
views.forEach { it.drawable.setTint(color) }
diff --git a/library/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/library/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
index 9992cc1..3380ade 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
@@ -14,6 +14,7 @@ import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.fastadapter.listeners.ClickEventHook
import com.mikepenz.iconics.typeface.IIcon
@@ -28,13 +29,14 @@ class CardIItem(val builder: Config.() -> Unit = {}
) : AbstractItem<CardIItem, CardIItem.ViewHolder>(), ThemableIItem by ThemableIItemDelegate() {
companion object {
- @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<CardIItem>) {
- fastAdapter.withEventHook(object : ClickEventHook<CardIItem>() {
+ @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<IItem<*,*>>) {
+ fastAdapter.withEventHook(object : ClickEventHook<IItem<*,*>>() {
override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null
}
- override fun onClick(v: View, position: Int, adapter: FastAdapter<CardIItem>, item: CardIItem) {
+ override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*,*>>, item: IItem<*,*>) {
+ if (item !is CardIItem) return
with(item.configs) {
when (v.id) {
R.id.kau_card_container -> cardClick?.onClick(v)
@@ -94,7 +96,7 @@ class CardIItem(val builder: Config.() -> Unit = {}
bindTextColorSecondary(description)
bindAccentColor(button)
if (configs.imageIIcon != null) bindIconColor(icon)
- bindBackgroundColor(card)
+ bindBackgroundRipple(card)
}
}
}
diff --git a/library/src/main/kotlin/ca/allanwang/kau/iitems/LibraryIItem.kt b/library/src/main/kotlin/ca/allanwang/kau/iitems/LibraryIItem.kt
index a66a563..aabd9e3 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/iitems/LibraryIItem.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/iitems/LibraryIItem.kt
@@ -11,11 +11,13 @@ import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.gone
+import ca.allanwang.kau.utils.startLink
import ca.allanwang.kau.utils.visible
+import ca.allanwang.kau.views.createSimpleRippleDrawable
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.items.AbstractItem
-import com.mikepenz.fastadapter.listeners.ClickEventHook
/**
* Created by Allan Wang on 2017-06-27.
@@ -24,23 +26,17 @@ class LibraryIItem(val lib: Library
) : AbstractItem<LibraryIItem, LibraryIItem.ViewHolder>(), ThemableIItem by ThemableIItemDelegate() {
companion object {
- @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<CardIItem>) {
- fastAdapter.withEventHook(object : ClickEventHook<CardIItem>() {
- override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
- return if (viewHolder is CardIItem.ViewHolder) listOf(viewHolder.card, viewHolder.button) else null
- }
-
- override fun onClick(v: View, position: Int, adapter: FastAdapter<CardIItem>, item: CardIItem) {
- with(item.configs) {
- when (v.id) {
- R.id.kau_card_container -> cardClick?.onClick(v)
- R.id.kau_card_button -> buttonClick?.onClick(v)
- else -> {
- }
- }
+ @JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
+ fastAdapter.withOnClickListener { v, _, item, _ ->
+ if (item !is LibraryIItem) false
+ else {
+ val c = v.context
+ with(item.lib) {
+ c.startLink(libraryWebsite, repositoryLink, authorWebsite)
}
+ true
}
- })
+ }
}
}
@@ -72,7 +68,7 @@ class LibraryIItem(val lib: Library
bindTextColorSecondary(description)
bindAccentColor(license, version)
bindDividerColor(divider, bottomDivider)
- bindBackgroundColor(card)
+ bindBackgroundRipple(card)
}
}
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 2a929a2..c56a09d 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -65,6 +65,16 @@ fun Context.startPlayStoreLink(packageId: String) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId")))
}
+/**
+ * Starts a url
+ * If given a series of links, will open the first one that isn't null
+ */
+fun Context.startLink(vararg url: String?) {
+ val link = url.firstOrNull { !it.isNullOrBlank() } ?: return
+ val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link))
+ startActivity(browserIntent)
+}
+
//Toast helpers
fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = toast(this.string(id), duration)
diff --git a/library/src/main/res/layout/kau_iitem_library.xml b/library/src/main/res/layout/kau_iitem_library.xml
index f486ac0..1c3de5c 100644
--- a/library/src/main/res/layout/kau_iitem_library.xml
+++ b/library/src/main/res/layout/kau_iitem_library.xml
@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/kau_padding_normal"
- android:foreground="?selectableItemBackground"
+ android:background="?android:selectableItemBackground"
android:clickable="true">
<android.support.constraint.ConstraintLayout