aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/enums
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-09-16 20:53:49 -0400
committerGitHub <noreply@github.com>2017-09-16 20:53:49 -0400
commit2fe3422895c19d93fdb515b72ae497f4263e77bc (patch)
tree08a71aeccddd371d67e9797999a6560d541e54ed /app/src/main/kotlin/com/pitchedapps/frost/enums
parent9c4ff0063812e373cd5730ff77840ff7227a3300 (diff)
downloadfrost-2fe3422895c19d93fdb515b72ae497f4263e77bc.tar.gz
frost-2fe3422895c19d93fdb515b72ae497f4263e77bc.tar.bz2
frost-2fe3422895c19d93fdb515b72ae497f4263e77bc.zip
Feature/contextual overlays (#295)
* Update theme * Update theme * Compile compacts * Update changelog * Update theme * Add overlay context items and their bindings * Replace default with null and add changelog
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/enums')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt
new file mode 100644
index 00000000..cc71b19e
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt
@@ -0,0 +1,65 @@
+package com.pitchedapps.frost.enums
+
+import android.content.Context
+import android.view.Menu
+import android.view.MenuItem
+import ca.allanwang.kau.utils.toDrawable
+import com.mikepenz.iconics.typeface.IIcon
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.facebook.FbItem
+import com.pitchedapps.frost.web.FrostWebViewCore
+
+/**
+ * Created by Allan Wang on 2017-09-16.
+ *
+ * Options for [WebOverlayActivityBase] to give more info as to what kind of
+ * overlay is present.
+ *
+ * For now, this is able to add new menu options upon first load
+ */
+enum class OverlayContext(private val menuItem: FrostMenuItem?) {
+
+ NOTIFICATION(FrostMenuItem(R.id.action_notification, FbItem.NOTIFICATIONS.icon, R.string.notifications) { webview ->
+ webview.loadUrl(FbItem.NOTIFICATIONS.url, true)
+ }),
+ MESSAGE(FrostMenuItem(R.id.action_messages, FbItem.MESSAGES.icon, R.string.messages) { webview ->
+ webview.loadUrl(FbItem.MESSAGES.url, true)
+ });
+
+ /**
+ * Inject the [menuItem] in the order that they are given at the front of the menu
+ */
+ fun onMenuCreate(context: Context, menu: Menu) {
+ menuItem?.addToMenu(context, menu, 0)
+ }
+
+ companion object {
+
+ val values = OverlayContext.values() //save one instance
+ /**
+ * Execute selection call for an item by id
+ * Returns [true] if selection was consumed, [false] otherwise
+ */
+ fun onOptionsItemSelected(webview: FrostWebViewCore, id: Int): Boolean {
+ val consumer = values.firstOrNull { id == it.menuItem?.id } ?: return false
+ consumer.menuItem!!.onClick(webview)
+ return true
+ }
+ }
+}
+
+/**
+ * Frame for an injectable menu item
+ */
+class FrostMenuItem(
+ val id: Int,
+ val iicon: IIcon,
+ val stringRes: Int,
+ val showAsAction: Int = MenuItem.SHOW_AS_ACTION_ALWAYS,
+ val onClick: (webview: FrostWebViewCore) -> Unit) {
+ fun addToMenu(context: Context, menu: Menu, index: Int) {
+ val item = menu.add(Menu.NONE, id, index, stringRes)
+ item.icon = iicon.toDrawable(context, 18)
+ item.setShowAsAction(showAsAction)
+ }
+} \ No newline at end of file