public void SetTitle(bool useConversation) { if (!useConversation) { SetTitle(Resource.String.title_select_conversation); } else { Title = AtlasUtil.GetConversationTitle(GetLayerClient(), GetParticipantProvider(), mConversation); } }
private void Update(Context context, Conversation conversation, IMessage message) { string messagesString = mMessages.GetString(conversation.Id.ToString(), null); if (messagesString == null) { return; } // Get current notification texts IDictionary <long, string> positionText = new Dictionary <long, string>(); try { JSONObject messagesJson = new JSONObject(messagesString); IIterator iterator = messagesJson.Keys(); while (iterator.HasNext) { string messageId = (string)iterator.Next(); JSONObject messageJson = messagesJson.GetJSONObject(messageId); long position = messageJson.GetLong(KEY_POSITION); string text = messageJson.GetString(KEY_TEXT); positionText[position] = text; } } catch (JSONException e) { if (Util.Log.IsLoggable(Util.Log.ERROR)) { Util.Log.e(e.Message, e); } return; } // Sort by message position List <long> positions = new List <long>(positionText.Keys); positions.Sort(); // Construct notification string conversationTitle = AtlasUtil.GetConversationTitle(App.GetLayerClient(), App.GetParticipantProvider(), conversation); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle().SetBigContentTitle(conversationTitle); int i; if (positions.Count <= MAX_MESSAGES) { i = 0; inboxStyle.SetSummaryText((string)null); } else { i = positions.Count - MAX_MESSAGES; inboxStyle.SetSummaryText(context.GetString(Resource.String.notifications_num_more, i)); } while (i < positions.Count) { inboxStyle.AddLine(positionText[positions[i++]]); } string collapsedSummary = positions.Count == 1 ? positionText[positions[0]] : context.GetString(Resource.String.notifications_new_messages, positions.Count); // Construct notification // TODO: use large icon based on avatars var mBuilder = new NotificationCompat.Builder(context) .SetSmallIcon(Resource.Drawable.notification) .SetContentTitle(conversationTitle) .SetContentText(collapsedSummary) .SetAutoCancel(true) .SetLights(ContextCompat.GetColor(context, Resource.Color.atlas_action_bar_background), 100, 1900) .SetPriority(NotificationCompat.PriorityHigh) .SetDefaults(NotificationCompat.DefaultSound | NotificationCompat.DefaultVibrate) .SetStyle(inboxStyle); // Intent to launch when clicked Intent clickIntent = new Intent(context, typeof(MessagesListActivity)) .SetPackage(context.ApplicationContext.PackageName) .PutExtra(LAYER_CONVERSATION_KEY, conversation.Id) .PutExtra(LAYER_MESSAGE_KEY, message.Id) .SetFlags(ActivityFlags.ClearTop); PendingIntent clickPendingIntent = PendingIntent.GetActivity( context, Interlocked.Increment(ref sPendingIntentCounterFlag), clickIntent, PendingIntentFlags.OneShot); mBuilder.SetContentIntent(clickPendingIntent); // Intent to launch when swiped out Intent cancelIntent = new Intent(ACTION_CANCEL) .SetPackage(context.ApplicationContext.PackageName) .PutExtra(LAYER_CONVERSATION_KEY, conversation.Id) .PutExtra(LAYER_MESSAGE_KEY, message.Id); PendingIntent cancelPendingIntent = PendingIntent.GetBroadcast( context, Interlocked.Increment(ref sPendingIntentCounterFlag), cancelIntent, PendingIntentFlags.OneShot); mBuilder.SetDeleteIntent(cancelPendingIntent); // Show the notification mManager.Notify(conversation.Id.ToString(), MESSAGE_ID, mBuilder.Build()); }