Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversation styling and shortcuts for Android 🤖 #47626

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
Expand All @@ -30,6 +31,8 @@
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.Person;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.versionedparcelable.ParcelUtils;

Expand All @@ -47,6 +50,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -210,39 +214,53 @@ private void applyMessageStyle(@NonNull Context context, NotificationCompat.Buil
// create the Person object who sent the latest report comment
Bitmap personIcon = fetchIcon(context, avatar);
builder.setLargeIcon(personIcon);
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("new-expensify://r/" + reportID));

Person person = createMessagePersonObject(IconCompat.createWithBitmap(personIcon), accountID, name);
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, accountID)
.setShortLabel(name)
.setLongLabel(name)
.setCategories(Collections.singleton(CATEGORY_MESSAGE))
.setIntent(intent)
.setLongLived(true)
.setPerson(person)
.setIcon(IconCompat.createWithBitmap(personIcon))
.build();

ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo);

// Create latest received message object
long createdTimeInMillis = getMessageTimeInMillis(messageData.get("created").getString(""));
NotificationCompat.MessagingStyle.Message newMessage = new NotificationCompat.MessagingStyle.Message(message, createdTimeInMillis, person);

// Conversational styling should be applied to groups chats, rooms, and any 1:1 chats with more than one notification (ensuring the large profile image is always shown)
if (!conversationName.isEmpty() || hasExistingNotification) {
// Create the messaging style notification builder for this notification, associating it with the person who sent the report comment
NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(person)
.setGroupConversation(true)
.setConversationTitle(conversationName);
NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(person);

// Add all conversation messages to the notification, including the last one we just received.
List<NotificationCompat.MessagingStyle.Message> messages;
if (hasExistingNotification) {
NotificationCompat.MessagingStyle previousStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(existingReportNotification.getNotification());
messages = previousStyle != null ? previousStyle.getMessages() : new ArrayList<>(List.of(recreatePreviousMessage(existingReportNotification)));
} else {
messages = new ArrayList<>();
}

// Add all conversation messages to the notification, including the last one we just received.
List<NotificationCompat.MessagingStyle.Message> messages;
if (hasExistingNotification) {
NotificationCompat.MessagingStyle previousStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(existingReportNotification.getNotification());
messages = previousStyle != null ? previousStyle.getMessages() : new ArrayList<>(List.of(recreatePreviousMessage(existingReportNotification)));
} else {
messages = new ArrayList<>();
}

// add the last one message we just received.
messages.add(newMessage);
// add the last one message we just received.
messages.add(newMessage);

for (NotificationCompat.MessagingStyle.Message activeMessage : messages) {
messagingStyle.addMessage(activeMessage);
}
for (NotificationCompat.MessagingStyle.Message activeMessage : messages) {
messagingStyle.addMessage(activeMessage);
}

builder.setStyle(messagingStyle);
// Conversational styling should be applied to groups chats, rooms, and any 1:1 chats with more than one notification (ensuring the large profile image is always shown)
if (!conversationName.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!conversationName.isEmpty()) {
if (!roomName.isEmpty()) {

Can you rename this variable to make it a little more clear?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed 🫡

// Create the messaging style notification builder for this notification, associating it with the person who sent the report comment
messagingStyle
.setGroupConversation(true)
.setConversationTitle(conversationName);
}
builder.setStyle(messagingStyle);
builder.setShortcutId(accountID);

// save reportID and person info for future merging
builder.addExtras(createMessageExtrasBundle(reportID, person));
Expand Down
Loading