aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/iitems
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-31 00:42:49 -0500
committerGitHub <noreply@github.com>2017-12-31 00:42:49 -0500
commit3076d9a97c203497aec1415d8ac6037d10eebb46 (patch)
treecdeb914fa95f2b230f6327be3e1527d15b41dc94 /app/src/main/kotlin/com/pitchedapps/frost/iitems
parent041bafcceadbd5203e95f2692899ac903dd2e883 (diff)
downloadfrost-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')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt97
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt67
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt3
3 files changed, 165 insertions, 2 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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt
new file mode 100644
index 00000000..690d1be8
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt
@@ -0,0 +1,67 @@
+package com.pitchedapps.frost.iitems
+
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
+import ca.allanwang.kau.iitems.KauIItem
+import ca.allanwang.kau.ui.createSimpleRippleDrawable
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.gone
+import ca.allanwang.kau.utils.visible
+import com.bumptech.glide.Glide
+import com.mikepenz.fastadapter.FastAdapter
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.facebook.requests.MenuFooterItem
+import com.pitchedapps.frost.facebook.requests.MenuHeader
+import com.pitchedapps.frost.facebook.requests.MenuItem
+import com.pitchedapps.frost.glide.FrostGlide
+import com.pitchedapps.frost.glide.transform
+import com.pitchedapps.frost.utils.Prefs
+
+/**
+ * Created by Allan Wang on 30/12/17.
+ */
+class MenuContentIItem(val data: MenuItem)
+ : KauIItem<MenuContentIItem, MenuContentIItem.ViewHolder>(R.layout.iitem_menu, ::ViewHolder),
+ ClickableIItemContract {
+
+ override val url: String?
+ get() = data.url
+
+ class ViewHolder(itemView: View) : FastAdapter.ViewHolder<MenuContentIItem>(itemView) {
+
+ val frame: ViewGroup by bindView(R.id.item_frame)
+ val icon: ImageView by bindView(R.id.item_icon)
+ val content: TextView by bindView(R.id.item_content)
+ val badge: TextView by bindView(R.id.item_badge)
+
+ override fun bindView(item: MenuContentIItem, payloads: MutableList<Any>) {
+ frame.background = createSimpleRippleDrawable(Prefs.textColor, Prefs.nativeBgColor)
+ content.setTextColor(Prefs.textColor)
+ badge.setTextColor(Prefs.textColor)
+ val iconUrl = item.data.pic
+ if (iconUrl != null)
+ Glide.with(itemView).load(iconUrl)
+ .transform(FrostGlide.roundCorner)
+ .into(icon.visible())
+ else
+ icon.gone()
+ content.text = item.data.name
+ }
+
+ override fun unbindView(item: MenuContentIItem) {
+ badge.gone()
+ }
+ }
+}
+
+class MenuHeaderIItem(val data: MenuHeader) : HeaderIItem(data.header,
+ itemId = R.id.item_menu_header)
+
+class MenuFooterIItem(val data: MenuFooterItem)
+ : TextIItem(data.name, data.url, R.id.item_menu_footer)
+
+class MenuFooterSmallIItem(val data: MenuFooterItem)
+ : TextIItem(data.name, data.url, R.id.item_menu_footer_small)
+
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
index c7f61351..a16b0224 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
@@ -54,8 +54,7 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : KauI
override fun bindView(item: NotificationIItem, payloads: MutableList<Any>) {
val notif = item.notification
frame.background = createSimpleRippleDrawable(Prefs.textColor,
- Prefs.bgColor.colorToForeground(if (notif.unread) 0.7f else 0.0f)
- .withAlpha(30))
+ Prefs.nativeBgColor(notif.unread))
content.setTextColor(Prefs.textColor)
date.setTextColor(Prefs.textColor.withAlpha(150))