diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services')
3 files changed, 40 insertions, 6 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 d9b91225..2453d3b0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -22,7 +22,7 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.FrostWebActivity import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.dbflow.fetchUsername -import com.pitchedapps.frost.facebook.FB_URL_BASE +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 @@ -40,7 +40,7 @@ val Context.frostNotification: NotificationCompat.Builder } @Suppress("DEPRECATION") -//The update feature is for Android O and seems to still be in beta + //The update feature is for Android O and seems to still be in beta fun Notification.frostConfig() = apply { if (Prefs.notificationVibrate) defaults = defaults or Notification.DEFAULT_VIBRATE if (Prefs.notificationSound) defaults = defaults or Notification.DEFAULT_SOUND @@ -86,12 +86,12 @@ data class NotificationContent(val data: CookieModel, } } else { val intent = Intent(context, FrostWebActivity::class.java) - intent.data = Uri.parse("${FB_URL_BASE}$href") + intent.data = Uri.parse(href.formattedFbUrl) intent.putExtra(ARG_USER_ID, data.id) val group = "frost_${data.id}" val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) val notifBuilder = context.frostNotification - .setContentTitle(title ?: context.string(R.string.app_name)) + .setContentTitle(title ?: context.string(R.string.frost_name)) .setContentText(text) .setContentIntent(pendingIntent) .setCategory(Notification.CATEGORY_SOCIAL) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt new file mode 100644 index 00000000..c903ff72 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt @@ -0,0 +1,34 @@ +package com.pitchedapps.frost.services + +import android.app.PendingIntent +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.support.v4.app.NotificationManagerCompat +import com.pitchedapps.frost.utils.L + +/** + * Created by Allan Wang on 2017-08-04. + * + * Cancels a notification + */ +private const val NOTIF_TAG_TO_CANCEL = "notif_tag_to_cancel" +private const val NOTIF_ID_TO_CANCEL = "notif_id_to_cancel" + +class NotificationReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + L.d("NotificationReceiver triggered") + val notifTag = intent.getStringExtra(NOTIF_TAG_TO_CANCEL) + val notifId = intent.getIntExtra(NOTIF_ID_TO_CANCEL, -1) + if (notifId != -1) { + L.d("NotificationReceiver: Cancelling $notifTag $notifId") + NotificationManagerCompat.from(context).cancel(notifTag, notifId) + } + } +} + +fun Context.getNotificationPendingCancelIntent(tag: String?, notifId: Int): PendingIntent { + val cancelIntent = Intent(this, NotificationReceiver::class.java) + .putExtra(NOTIF_TAG_TO_CANCEL, tag).putExtra(NOTIF_ID_TO_CANCEL, notifId) + return PendingIntent.getBroadcast(this, 0, cancelIntent, 0) +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index 3ddad869..fe7758cc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -182,7 +182,7 @@ class NotificationService : JobService() { private fun Context.debugNotification(text: String) { if (!BuildConfig.DEBUG) return val notifBuilder = frostNotification - .setContentTitle(string(R.string.app_name)) + .setContentTitle(string(R.string.frost_name)) .setContentText(text) NotificationManagerCompat.from(this).notify(999, notifBuilder.build().frostConfig()) } @@ -190,7 +190,7 @@ class NotificationService : JobService() { fun summaryNotification(userId: Long, count: Int) { if (count <= 1) return val notifBuilder = frostNotification - .setContentTitle(string(R.string.app_name)) + .setContentTitle(string(R.string.frost_name)) .setContentText("$count notifications") .setGroup("frost_$userId") .setGroupSummary(true) |