diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-19 22:02:24 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-19 22:02:24 -0700 |
commit | 2d7fa0f6d0c152bb9f3fd30370ef510a0d452d00 (patch) | |
tree | 20b9d28ed89ec1d17a42127066a513db33ecb7e3 /app/src/main/kotlin/com/pitchedapps/frost/services | |
parent | 7b90fa9819c9b4765f107ea04dd7ac687dc572ad (diff) | |
download | frost-2d7fa0f6d0c152bb9f3fd30370ef510a0d452d00.tar.gz frost-2d7fa0f6d0c152bb9f3fd30370ef510a0d452d00.tar.bz2 frost-2d7fa0f6d0c152bb9f3fd30370ef510a0d452d00.zip |
Check for username if not found on login
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt | 41 |
1 files changed, 24 insertions, 17 deletions
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 d357ff68..813bdce2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -7,7 +7,6 @@ import android.app.job.JobService import android.content.Context import android.content.Intent import android.net.Uri -import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationManagerCompat import ca.allanwang.kau.utils.string import com.pitchedapps.frost.BuildConfig @@ -42,8 +41,7 @@ class NotificationService : JobService() { debugNotification("Load notifs") loadFbCookiesSync().forEach { data -> - L.i("Handling notifications for ${data.id}") - L.v("Using data $data") + L.i("Handle notifications for $data") val doc = Jsoup.connect(FbTab.NOTIFICATIONS.url).cookie(FACEBOOK_COM, data.cookie).get() val unreadNotifications = doc.getElementById("notifications_list").getElementsByClass("aclb") var notifCount = 0 @@ -64,6 +62,7 @@ class NotificationService : JobService() { } L.d("Finished notifications") jobFinished(params, false) + future = null } return true } @@ -100,22 +99,30 @@ class NotificationService : JobService() { } data class NotificationContent(val data: CookieModel, val notifId: Int, val href: String, val text: String, val timestamp: Long) { - fun createNotification(context: Context) { - val intent = Intent(context, FrostWebActivity::class.java) - intent.data = Uri.parse("$FB_URL_BASE$href") - val group = "frost_${data.id}" - val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) - val notifBuilder = context.frostNotification - .setContentTitle(context.string(R.string.app_name)) - .setContentText(text) - .setContentIntent(pendingIntent) - .setCategory(Notification.CATEGORY_SOCIAL) - .setSubText(data.name) - .setGroup(group) + 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("$FB_URL_BASE$href") + val group = "frost_${data.id}" + val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) + val notifBuilder = context.frostNotification + .setContentTitle(context.string(R.string.app_name)) + .setContentText(text) + .setContentIntent(pendingIntent) + .setCategory(Notification.CATEGORY_SOCIAL) + .setSubText(data.name) + .setGroup(group) - if (timestamp != -1L) notifBuilder.setWhen(timestamp * 1000) + if (timestamp != -1L) notifBuilder.setWhen(timestamp * 1000) - NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.build()) + NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.build()) + } } } |