fix group chat shortcuts

This commit is contained in:
Daniel Gultsch 2023-09-11 16:38:57 +02:00
parent c6501a3ad4
commit 00ae1ca762
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 70 additions and 9 deletions

View file

@ -124,6 +124,17 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
return avatar; return avatar;
} }
public Bitmap getRoundedShortcut(final MucOptions mucOptions) {
final DisplayMetrics metrics = mXmppConnectionService.getResources().getDisplayMetrics();
final int size = Math.round(metrics.density * 48);
final Bitmap bitmap = get(mucOptions, size, false);
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
drawAvatar(bitmap, canvas, paint);
return output;
}
public Bitmap getRoundedShortcut(final Contact contact) { public Bitmap getRoundedShortcut(final Contact contact) {
return getRoundedShortcut(contact, false); return getRoundedShortcut(contact, false);
} }
@ -147,7 +158,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
return output; return output;
} }
private void drawAvatar(Bitmap bitmap, Canvas canvas, Paint paint) { private static void drawAvatar(Bitmap bitmap, Canvas canvas, Paint paint) {
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true); paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0); canvas.drawARGB(0, 0, 0, 0);

View file

@ -1284,21 +1284,24 @@ public class NotificationService {
} }
} }
} }
final ShortcutInfoCompat info;
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE) {
final Contact contact = conversation.getContact(); final Contact contact = conversation.getContact();
final Uri systemAccount = contact.getSystemAccount(); final Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) { if (systemAccount != null) {
mBuilder.addPerson(systemAccount.toString()); mBuilder.addPerson(systemAccount.toString());
} }
info = mXmppConnectionService.getShortcutService().getShortcutInfoCompat(contact);
} else {
info =
mXmppConnectionService
.getShortcutService()
.getShortcutInfoCompat(conversation.getMucOptions());
} }
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent()); mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
mBuilder.setSmallIcon(R.drawable.ic_notification); mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent(conversation)); mBuilder.setDeleteIntent(createDeleteIntent(conversation));
mBuilder.setContentIntent(createContentIntent(conversation)); mBuilder.setContentIntent(createContentIntent(conversation));
final ShortcutInfoCompat info =
mXmppConnectionService
.getShortcutService()
.getShortcutInfoCompat(conversation.getContact());
mBuilder.setShortcutInfo(info); mBuilder.setShortcutInfo(info);
if (Build.VERSION.SDK_INT >= 30) { if (Build.VERSION.SDK_INT >= 30) {
mXmppConnectionService mXmppConnectionService

View file

@ -22,6 +22,7 @@ import java.util.List;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.ui.StartConversationActivity; import eu.siacs.conversations.ui.StartConversationActivity;
import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor; import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
@ -109,6 +110,24 @@ public class ShortcutService {
return builder.build(); return builder.build();
} }
public ShortcutInfoCompat getShortcutInfoCompat(final MucOptions mucOptions) {
final ShortcutInfoCompat.Builder builder =
new ShortcutInfoCompat.Builder(xmppConnectionService, getShortcutId(mucOptions))
.setShortLabel(mucOptions.getConversation().getName())
.setIntent(getShortcutIntent(mucOptions))
.setIsConversation();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
builder.setIcon(
IconCompat.createFromIcon(
xmppConnectionService,
Icon.createWithBitmap(
xmppConnectionService
.getAvatarService()
.getRoundedShortcut(mucOptions))));
}
return builder.build();
}
@TargetApi(Build.VERSION_CODES.N_MR1) @TargetApi(Build.VERSION_CODES.N_MR1)
private ShortcutInfo getShortcutInfo(final Contact contact) { private ShortcutInfo getShortcutInfo(final Contact contact) {
return getShortcutInfoCompat(contact).toShortcutInfo(); return getShortcutInfoCompat(contact).toShortcutInfo();
@ -137,12 +156,40 @@ public class ShortcutService {
return contact.getAccount().getJid().asBareJid().toEscapedString()+"#"+contact.getJid().asBareJid().toEscapedString(); return contact.getAccount().getJid().asBareJid().toEscapedString()+"#"+contact.getJid().asBareJid().toEscapedString();
} }
private Intent getShortcutIntent(Contact contact) { private static String getShortcutId(final MucOptions mucOptions) {
final Account account = mucOptions.getAccount();
final Jid jid = mucOptions.getConversation().getJid();
return account.getJid().asBareJid().toEscapedString()
+ "#"
+ jid.asBareJid().toEscapedString();
}
private Intent getShortcutIntent(final MucOptions mucOptions) {
final Account account = mucOptions.getAccount();
return getShortcutIntent(
account,
Uri.parse(
String.format(
"xmpp:%s?join",
mucOptions
.getConversation()
.getJid()
.asBareJid()
.toEscapedString())));
}
private Intent getShortcutIntent(final Contact contact) {
return getShortcutIntent(
contact.getAccount(),
Uri.parse("xmpp:" + contact.getJid().asBareJid().toEscapedString()));
}
private Intent getShortcutIntent(final Account account, final Uri uri) {
Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class); Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("xmpp:"+contact.getJid().asBareJid().toEscapedString())); intent.setData(uri);
intent.putExtra("account",contact.getAccount().getJid().asBareJid().toString()); intent.putExtra("account", account.getJid().asBareJid().toString());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
return intent; return intent;
} }