diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-14 20:48:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 20:48:39 -0700 |
commit | 5d9a3fd7fb8f2f9d0f592c89446824980c9841c6 (patch) | |
tree | a770b2564b67280fcc9fcc65144bd0b8bd8e2881 /app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt | |
parent | ab7ec131b62ac1567e983c846c921bd3ada11dd4 (diff) | |
download | frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.tar.gz frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.tar.bz2 frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.zip |
v1.4.5 (#174)v1.4.5
* Update/kau (#125)
* Update logger
* Clean imports and bring back reactive libs
* Update dependencies and make billing async
* Misc (#128)
* Update null
* Attempt to improve transparent theme backgrounds
* Update menu
* Move injections to visible method and reduce offset
* Update searchview and logging
* Clean temp strings and add network states
* Move console blacklist to web state
* Change some logs to info
* Move glide loader to onCreate (#135)
* Remove commit number increments (#139)
* Fix/misc (#140)
* Add canadian locale to toLowerCase
* Add try catch to JsAssets
* Disable error throwing for bad search subject
* Log more throwables quietly
* Check internet connection before fetching username
* Remove name check in frost notifications
* Add activity lifecycle logger
* Add rxjava to lib showcase
* Move network checker to io thread (#150)
* Update dependency
* Blank
* Feature/jsoup debugger (#152)
* Create debugger
* Update debugger content
* Create debugging logic
* Finalize and test debugger
* Add reload listener
* Fix/pro crash without play store (#155)
* Update changelog
* Check if iab service exists
* Add checker before launching play store request
* Separate strings
* Enhancement/message notifications (#157)
* Map message notifs to the headless html extractor
* Update strings
* Bring im notifs out of alpha
* Update changelog
* Remove confirmation dialog (#159)
* Separate message notifications and add click intents (#171)
* Separate message notifications and add click intent for group notifications
* Add comments and finalize
* Feature/scroll down on message thread (#172)
* Add hook for scroll
* Update changelog
* Add custom navdrawer layout (#173)
* Add faq for auto play
* Update changelog
* Fix page banner bg (#163)
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt | 76 |
1 files changed, 42 insertions, 34 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 2453d3b0..d3dfe79c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -21,7 +21,6 @@ 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.dbflow.fetchUsername import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.ARG_USER_ID import com.pitchedapps.frost.utils.L @@ -31,6 +30,12 @@ import org.jetbrains.anko.runOnUiThread /** * Created by Allan Wang on 2017-07-08. + * + * Logic for build notifications, scheduling notifications, and showing notifications + */ + +/** + * Wrap the default builder with our icon and accent color */ val Context.frostNotification: NotificationCompat.Builder get() = NotificationCompat.Builder(this, BuildConfig.APPLICATION_ID).apply { @@ -39,6 +44,9 @@ val Context.frostNotification: NotificationCompat.Builder color = color(R.color.frost_notification_accent) } +/** + * Assign global changes to the notification after it is built + */ @Suppress("DEPRECATION") //The update feature is for Android O and seems to still be in beta fun Notification.frostConfig() = apply { @@ -54,6 +62,7 @@ val NotificationCompat.Builder.withBigText: NotificationCompat.BigTextStyle * Created by Allan Wang on 2017-07-08. * * Custom target to set the content view and update a given notification + * 40dp is the size of the right avatar */ class FrostNotificationTarget(val context: Context, val notifId: Int, @@ -67,6 +76,9 @@ class FrostNotificationTarget(val context: Context, } } +internal const val FROST_NOTIFICATION_GROUP = "frost" +internal const val FROST_MESSAGE_NOTIFICATION_GROUP = "frost_im" + /** * Notification data holder */ @@ -77,39 +89,35 @@ data class NotificationContent(val data: CookieModel, val text: String, val timestamp: Long, val profileUrl: String) { - fun createNotification(context: Context, verifiedUser: Boolean = false) { - //in case we haven't found the name, we will try one more time before passing the notification - if (!verifiedUser && data.name?.isBlank() ?: true) { - data.fetchUsername { - data.name = it - createNotification(context, true) - } - } else { - val intent = Intent(context, FrostWebActivity::class.java) - 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.frost_name)) - .setContentText(text) - .setContentIntent(pendingIntent) - .setCategory(Notification.CATEGORY_SOCIAL) - .setSubText(data.name) - .setGroup(group) - - if (timestamp != -1L) notifBuilder.setWhen(timestamp * 1000) - L.v("Notif load $this") - NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.withBigText.build().frostConfig()) - - if (profileUrl.isNotBlank()) { - context.runOnUiThread { - Glide.with(context) - .asBitmap() - .load(profileUrl) - .withRoundIcon() - .into(FrostNotificationTarget(context, notifId, group, notifBuilder)) - } + fun createNotification(context: Context) = createNotification(context, FROST_NOTIFICATION_GROUP) + + fun createMessageNotification(context: Context) = createNotification(context, FROST_MESSAGE_NOTIFICATION_GROUP) + + private fun createNotification(context: Context, groupPrefix: String) { + val intent = Intent(context, FrostWebActivity::class.java) + intent.data = Uri.parse(href.formattedFbUrl) + intent.putExtra(ARG_USER_ID, data.id) + val group = "${groupPrefix}_${data.id}" + val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) + val notifBuilder = context.frostNotification + .setContentTitle(title ?: context.string(R.string.frost_name)) + .setContentText(text) + .setContentIntent(pendingIntent) + .setCategory(Notification.CATEGORY_SOCIAL) + .setSubText(data.name) + .setGroup(group) + + if (timestamp != -1L) notifBuilder.setWhen(timestamp * 1000) + L.v("Notif load", this.toString()) + NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.withBigText.build().frostConfig()) + + if (profileUrl.isNotBlank()) { + context.runOnUiThread { + Glide.with(context) + .asBitmap() + .load(profileUrl) + .withRoundIcon() + .into(FrostNotificationTarget(context, notifId, group, notifBuilder)) } } } |