fix group chat shortcuts
This commit is contained in:
parent
c6501a3ad4
commit
00ae1ca762
|
@ -124,6 +124,17 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
|||
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) {
|
||||
return getRoundedShortcut(contact, false);
|
||||
}
|
||||
|
@ -147,7 +158,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
|||
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());
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
|
|
|
@ -1284,21 +1284,24 @@ public class NotificationService {
|
|||
}
|
||||
}
|
||||
}
|
||||
final ShortcutInfoCompat info;
|
||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||
final Contact contact = conversation.getContact();
|
||||
final Uri systemAccount = contact.getSystemAccount();
|
||||
if (systemAccount != null) {
|
||||
mBuilder.addPerson(systemAccount.toString());
|
||||
}
|
||||
info = mXmppConnectionService.getShortcutService().getShortcutInfoCompat(contact);
|
||||
} else {
|
||||
info =
|
||||
mXmppConnectionService
|
||||
.getShortcutService()
|
||||
.getShortcutInfoCompat(conversation.getMucOptions());
|
||||
}
|
||||
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
|
||||
mBuilder.setSmallIcon(R.drawable.ic_notification);
|
||||
mBuilder.setDeleteIntent(createDeleteIntent(conversation));
|
||||
mBuilder.setContentIntent(createContentIntent(conversation));
|
||||
final ShortcutInfoCompat info =
|
||||
mXmppConnectionService
|
||||
.getShortcutService()
|
||||
.getShortcutInfoCompat(conversation.getContact());
|
||||
mBuilder.setShortcutInfo(info);
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
mXmppConnectionService
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.MucOptions;
|
||||
import eu.siacs.conversations.ui.StartConversationActivity;
|
||||
import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
|
@ -109,6 +110,24 @@ public class ShortcutService {
|
|||
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)
|
||||
private ShortcutInfo getShortcutInfo(final Contact contact) {
|
||||
return getShortcutInfoCompat(contact).toShortcutInfo();
|
||||
|
@ -137,11 +156,39 @@ public class ShortcutService {
|
|||
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.setAction(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("xmpp:"+contact.getJid().asBareJid().toEscapedString()));
|
||||
intent.putExtra("account",contact.getAccount().getJid().asBareJid().toString());
|
||||
intent.setData(uri);
|
||||
intent.putExtra("account", account.getJid().asBareJid().toString());
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return intent;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue