aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt65
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt1
5 files changed, 80 insertions, 6 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index dd8ed558..32f7c793 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -48,6 +48,7 @@ import com.pitchedapps.frost.contracts.FileChooserContract
import com.pitchedapps.frost.contracts.FileChooserDelegate
import com.pitchedapps.frost.dbflow.loadFbCookie
import com.pitchedapps.frost.dbflow.loadFbTabs
+import com.pitchedapps.frost.enums.OverlayContext
import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbCookie.switchUser
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
index e5452655..de806779 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
@@ -20,6 +20,7 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.contracts.ActivityWebContract
import com.pitchedapps.frost.contracts.FileChooserContract
import com.pitchedapps.frost.contracts.FileChooserDelegate
+import com.pitchedapps.frost.enums.OverlayContext
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.facebook.formattedFbUrl
@@ -53,7 +54,7 @@ class WebOverlayBasicActivity : WebOverlayActivityBase(true)
*/
class WebOverlayActivity : WebOverlayActivityBase(false)
-open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivity(),
+open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : KauBaseActivity(),
ActivityWebContract, FileChooserContract by FileChooserDelegate() {
val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
@@ -69,6 +70,9 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
val userId: Long
get() = intent.extras?.getLong(ARG_USER_ID, Prefs.userId) ?: Prefs.userId
+ val overlayContext: OverlayContext?
+ get() = intent.extras?.getSerializable(ARG_OVERLAY_CONTEXT) as OverlayContext?
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (urlTest == null) {
@@ -157,6 +161,7 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_web, menu)
+ overlayContext?.onMenuCreate(this, menu)
toolbar.tint(Prefs.iconColor)
setMenuIcons(menu, Prefs.iconColor,
R.id.action_share to CommunityMaterial.Icon.cmd_share,
@@ -168,7 +173,8 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
when (item.itemId) {
R.id.action_copy_link -> copyToClipboard(frostWeb.web.url)
R.id.action_share -> shareText(frostWeb.web.url)
- else -> return super.onOptionsItemSelected(item)
+ else -> if (!OverlayContext.onOptionsItemSelected(frostWeb.web, item.itemId))
+ return super.onOptionsItemSelected(item)
}
return true
}
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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
index 810e5f97..800fe492 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -21,11 +21,9 @@ import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.FrostWebActivity
import com.pitchedapps.frost.dbflow.CookieModel
+import com.pitchedapps.frost.enums.OverlayContext
import com.pitchedapps.frost.facebook.formattedFbUrl
-import com.pitchedapps.frost.utils.ARG_USER_ID
-import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.Prefs
-import com.pitchedapps.frost.utils.withRoundIcon
+import com.pitchedapps.frost.utils.*
import org.jetbrains.anko.runOnUiThread
/**
@@ -96,6 +94,7 @@ data class NotificationContent(val data: CookieModel,
val text: String,
val timestamp: Long,
val profileUrl: String) {
+
fun createNotification(context: Context) = createNotification(context, FROST_NOTIFICATION_GROUP)
fun createMessageNotification(context: Context) = createNotification(context, FROST_MESSAGE_NOTIFICATION_GROUP)
@@ -104,6 +103,8 @@ data class NotificationContent(val data: CookieModel,
val intent = Intent(context, FrostWebActivity::class.java)
intent.data = Uri.parse(href.formattedFbUrl)
intent.putExtra(ARG_USER_ID, data.id)
+ val overlayContext = if (groupPrefix == FROST_MESSAGE_NOTIFICATION_GROUP) OverlayContext.MESSAGE else OverlayContext.NOTIFICATION
+ intent.putExtra(ARG_OVERLAY_CONTEXT, overlayContext)
val group = "${groupPrefix}_${data.id}"
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
val ringtone = if (groupPrefix == FROST_MESSAGE_NOTIFICATION_GROUP) Prefs.messageRingtone else Prefs.notificationRingtone
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index bcda6a43..e5e1a706 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -41,6 +41,7 @@ const val ARG_URL = "arg_url"
const val ARG_USER_ID = "arg_user_id"
const val ARG_IMAGE_URL = "arg_image_url"
const val ARG_TEXT = "arg_text"
+const val ARG_OVERLAY_CONTEXT = "arg_overlay_context"
fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf(), clearStack: Boolean = false) {
startActivity(clazz, clearStack, intentBuilder = {