aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-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
-rw-r--r--app/src/main/res/menu/menu_main.xml2
-rw-r--r--app/src/main/res/menu/menu_settings.xml2
-rw-r--r--app/src/main/res/menu/menu_web.xml5
-rw-r--r--app/src/main/res/values/ids.xml5
-rw-r--r--app/src/main/res/xml/frost_changelog.xml2
10 files changed, 90 insertions, 12 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 = {
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index 3063ffec..8c6d3b34 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
- tools:context="com.pitchedapps.myapplication.MainActivity">
+ tools:context="com.pitchedapps.frost.activities.MainActivity">
<item
android:id="@+id/action_search"
diff --git a/app/src/main/res/menu/menu_settings.xml b/app/src/main/res/menu/menu_settings.xml
index 7ae59ad2..d8348af4 100644
--- a/app/src/main/res/menu/menu_settings.xml
+++ b/app/src/main/res/menu/menu_settings.xml
@@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
- tools:context="com.pitchedapps.myapplication.MainActivity">
+ tools:context="com.pitchedapps.frost.activities.SettingsActivity">
<item
android:id="@+id/action_email"
diff --git a/app/src/main/res/menu/menu_web.xml b/app/src/main/res/menu/menu_web.xml
index 833e7c27..5baefa1b 100644
--- a/app/src/main/res/menu/menu_web.xml
+++ b/app/src/main/res/menu/menu_web.xml
@@ -1,8 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
- tools:context="com.pitchedapps.myapplication.MainActivity">
-
+ tools:context="com.pitchedapps.frost.activities.WebOverlayActivity">
<item
android:id="@+id/action_copy_link"
@@ -14,6 +13,6 @@
android:id="@+id/action_share"
android:orderInCategory="200"
android:title="@string/kau_share"
- app:showAsAction="always" />
+ app:showAsAction="ifRoom" />
</menu>
diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml
index d32a3b71..0aaeeab8 100644
--- a/app/src/main/res/values/ids.xml
+++ b/app/src/main/res/values/ids.xml
@@ -9,4 +9,9 @@
<item name="intro_title" type="id" />
<item name="intro_image" type="id" />
<item name="intro_desc" type="id" />
+
+ <!--Extra menu ids; see OverlayContext-->
+ <item name="action_notification" type="id" />
+ <item name="action_messages" type="id" />
+ <item name="action_frost" type="id" />
</resources> \ No newline at end of file
diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml
index 99e60483..0e6bb252 100644
--- a/app/src/main/res/xml/frost_changelog.xml
+++ b/app/src/main/res/xml/frost_changelog.xml
@@ -15,7 +15,7 @@
<item text="Add full support for messaging in overlays. We will dynamically launch new overlays when required to." />
<item text="Prevent bad messenger intent from launching" />
<item text="Add toggle for recents feed. Aggressive loading removes extra posts that are not really recent, whereas disabling it will show exactly what you get on Facebook" />
- <item text="" />
+ <item text="Add contextual menu items. Easily go to your full list of notifications or messages from the overlay." />
<item text="" />
<item text="" />