aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/services
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-04-24 19:12:25 -0700
committerAllan Wang <me@allanwang.ca>2019-04-24 19:12:25 -0700
commit7e227078373adf0ef8c243b7e1e05804524cd3ea (patch)
treebd6585c85a7641555e4bd9c10fa919145a5ba6df /app/src/main/kotlin/com/pitchedapps/frost/services
parent9df2a878226fb5f7adcf1af61a1ce87dff826fbc (diff)
downloadfrost-7e227078373adf0ef8c243b7e1e05804524cd3ea.tar.gz
frost-7e227078373adf0ef8c243b7e1e05804524cd3ea.tar.bz2
frost-7e227078373adf0ef8c243b7e1e05804524cd3ea.zip
Add click events to notifications
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt36
1 files changed, 26 insertions, 10 deletions
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 68ed859c..1c37bc29 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -61,7 +61,7 @@ private val _40_DP = 40.dpToPx
* Enum to handle notification creations
*/
enum class NotificationType(
- private val channelId: String,
+ val channelId: String,
private val overlayContext: OverlayContext,
private val fbItem: FbItem,
private val parser: FrostParser<ParseNotification>,
@@ -95,8 +95,8 @@ enum class NotificationType(
*/
internal open fun bindRequest(content: NotificationContent, cookie: String): (BaseBundle.() -> Unit)? = null
- private fun bindRequest(intent: Intent, content: NotificationContent, cookie: String?) {
- cookie ?: return
+ private fun bindRequest(intent: Intent, content: NotificationContent) {
+ val cookie = content.data.cookie ?: return
val binder = bindRequest(content, cookie) ?: return
val bundle = Bundle()
bundle.binder()
@@ -188,17 +188,33 @@ enum class NotificationType(
}
/**
+ * Attach content related data to an intent
+ */
+ fun putContentExtra(intent: Intent, content: NotificationContent): Intent {
+ // We will show the notification page for dependent urls. We can trigger a click next time
+ intent.data = Uri.parse(if (content.href.isIndependent) content.href else FbItem.NOTIFICATIONS.url)
+ bindRequest(intent, content)
+ return intent
+ }
+
+ /**
+ * Create a generic content for the provided type and user id.
+ * No content related data is added
+ */
+ fun createCommonIntent(context: Context, userId: Long): Intent {
+ val intent = Intent(context, FrostWebActivity::class.java)
+ intent.putExtra(ARG_USER_ID, userId)
+ overlayContext.put(intent)
+ return intent
+ }
+
+ /**
* Create and submit a new notification with the given [content]
*/
private fun createNotification(context: Context, content: NotificationContent): FrostNotification =
with(content) {
- val intent = Intent(context, FrostWebActivity::class.java)
- // TODO temp fix; we will show notification page for dependent urls. We can trigger a click next time
- intent.data = Uri.parse(if (href.isIndependent) href else FbItem.NOTIFICATIONS.url)
- intent.putExtra(ARG_USER_ID, data.id)
- overlayContext.put(intent)
- bindRequest(intent, content, data.cookie)
-
+ val intent = createCommonIntent(context, content.data.id)
+ putContentExtra(intent, content)
val group = "${groupPrefix}_${data.id}"
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val notifBuilder = context.frostNotification(channelId)