diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-31 00:42:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-31 00:42:49 -0500 |
commit | 3076d9a97c203497aec1415d8ac6037d10eebb46 (patch) | |
tree | cdeb914fa95f2b230f6327be3e1527d15b41dc94 /app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt | |
parent | 041bafcceadbd5203e95f2692899ac903dd2e883 (diff) | |
download | frost-3076d9a97c203497aec1415d8ac6037d10eebb46.tar.gz frost-3076d9a97c203497aec1415d8ac6037d10eebb46.tar.bz2 frost-3076d9a97c203497aec1415d8ac6037d10eebb46.zip |
feature/menu-parser (#582)
* Test menu parser
* Add menu fragment implementation
* Test proguard
* Clean up
* Use async
* Use invoke
* Try without proguard
* Try 2
* Add fallback logic
* Use normal notification event
* Add custom event flag
* Add rest of menu fragment data
* Ensure fallback works
* Update docs
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt new file mode 100644 index 00000000..625ecff9 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt @@ -0,0 +1,97 @@ +package com.pitchedapps.frost.iitems + +import android.content.Context +import android.view.View +import android.widget.TextView +import ca.allanwang.kau.iitems.KauIItem +import ca.allanwang.kau.ui.createSimpleRippleDrawable +import ca.allanwang.kau.utils.bindView +import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.IAdapter +import com.mikepenz.fastadapter.IItem +import com.pitchedapps.frost.R +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.launchWebOverlay + +/** + * Created by Allan Wang on 30/12/17. + */ + +/** + * Base contract for anything with a url that may be launched in a new overlay + */ +interface ClickableIItemContract { + + val url: String? + + fun click(context: Context) { + val url = url ?: return + context.launchWebOverlay(url) + } + + companion object { + fun bindEvents(adapter: IAdapter<IItem<*, *>>) { + adapter.fastAdapter.withSelectable(false) + .withOnClickListener { v, _, item, _ -> + if (item is ClickableIItemContract) { + item.click(v.context) + true + } else + false + } + } + } + +} + +/** + * Generic header item + * Not clickable with an accent color + */ +open class HeaderIItem(val text: String?, + itemId: Int = R.layout.iitem_header) + : KauIItem<HeaderIItem, HeaderIItem.ViewHolder>(R.layout.iitem_header, ::ViewHolder, itemId) { + + class ViewHolder(itemView: View) : FastAdapter.ViewHolder<HeaderIItem>(itemView) { + + val text: TextView by bindView(R.id.item_header_text) + + override fun bindView(item: HeaderIItem, payloads: MutableList<Any>) { + text.setTextColor(Prefs.accentColor) + text.text = item.text + text.setBackgroundColor(Prefs.nativeBgColor) + } + + override fun unbindView(item: HeaderIItem) { + text.text = null + } + } + +} + +/** + * Generic text item + * Clickable with text color + */ +open class TextIItem(val text: String?, + override val url: String?, + itemId: Int = R.layout.iitem_text) + : KauIItem<TextIItem, TextIItem.ViewHolder>(R.layout.iitem_text, ::ViewHolder, itemId), + ClickableIItemContract { + + class ViewHolder(itemView: View) : FastAdapter.ViewHolder<TextIItem>(itemView) { + + val text: TextView by bindView(R.id.item_text_view) + + override fun bindView(item: TextIItem, payloads: MutableList<Any>) { + text.setTextColor(Prefs.textColor) + text.text = item.text + text.background = createSimpleRippleDrawable(Prefs.bgColor, Prefs.nativeBgColor) + } + + override fun unbindView(item: TextIItem) { + text.text = null + } + } + +}
\ No newline at end of file |