~singpolyma/cheogram-android

4504953d3656851366c3b1d65a05532a20506de4 — Daniel Gultsch 7 months ago 9b56682
fix group chat shortcuts
M src/main/java/eu/siacs/conversations/services/AvatarService.java => src/main/java/eu/siacs/conversations/services/AvatarService.java +12 -1
@@ 125,6 125,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);
		Bitmap bitmap = FileBackend.drawDrawable(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);
	}


@@ 148,7 159,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);

M src/main/java/eu/siacs/conversations/services/NotificationService.java => src/main/java/eu/siacs/conversations/services/NotificationService.java +7 -1
@@ 1373,12 1373,19 @@ public class NotificationService {
                    }
                }
            }
            final ShortcutInfoCompat info;
            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                Contact contact = conversation.getContact();
                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);


@@ 1388,7 1395,6 @@ public class NotificationService {
                mBuilder.setSubText(conversation.getAccount().getJid().asBareJid().toString());
            }

            ShortcutInfoCompat info = mXmppConnectionService.getShortcutService().getShortcutInfoCompat(conversation.getContact());
            mBuilder.setShortcutInfo(info);
            if (Build.VERSION.SDK_INT >= 30) {
                mXmppConnectionService.getSystemService(ShortcutManager.class).pushDynamicShortcut(info.toShortcutInfo());

M src/main/java/eu/siacs/conversations/services/ShortcutService.java => src/main/java/eu/siacs/conversations/services/ShortcutService.java +49 -13
@@ 21,7 21,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.Conversation;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.ui.StartConversationActivity;
import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;


@@ 101,6 101,24 @@ public class ShortcutService {
                        .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(Contact contact) {
        return getShortcutInfoCompat(contact).toShortcutInfo();


@@ 129,22 147,40 @@ public class ShortcutService {
        return contact.getAccount().getJid().asBareJid().toEscapedString()+"#"+contact.getJid().asBareJid().toEscapedString();
    }

    private Intent getShortcutIntent(Contact contact) {
        final Conversation conversation = xmppConnectionService.find(contact.getAccount(), contact.getJid());
    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())));
    }

        if (conversation != null) {
            Intent intent = new Intent(xmppConnectionService, ConversationsActivity.class);
            intent.setAction(ConversationsActivity.ACTION_VIEW_CONVERSATION);
            intent.putExtra(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
            return intent;
        }
    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.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setData(uri);
        intent.putExtra("account", account.getJid().asBareJid().toString());
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return intent;
    }


M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +7 -1
@@ 5042,8 5042,14 @@ public class XmppConnectionService extends Service {
    }

    public Conversation findFirstMuc(Jid jid) {
        return findFirstMuc(jid, null);
    }

    public Conversation findFirstMuc(Jid jid, String accountJid) {
        for (Conversation conversation : getConversations()) {
            if (conversation.getAccount().isEnabled() && conversation.getJid().asBareJid().equals(jid.asBareJid()) && conversation.getMode() == Conversation.MODE_MULTI) {
            if ((conversation.getAccount().isEnabled() || accountJid != null)
                    && (accountJid == null || accountJid.equals(conversation.getAccount().getJid().asBareJid().toString()))
                    && conversation.getJid().asBareJid().equals(jid.asBareJid()) && conversation.getMode() == Conversation.MODE_MULTI) {
                return conversation;
            }
        }

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +6 -1
@@ 1999,7 1999,12 @@ public class ConversationFragment extends XmppFragment
    }

    private void addShortcut() {
        ShortcutInfoCompat info = activity.xmppConnectionService.getShortcutService().getShortcutInfoCompat(conversation.getContact());
        ShortcutInfoCompat info;
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            info = activity.xmppConnectionService.getShortcutService().getShortcutInfoCompat(conversation.getMucOptions());
        } else {
            info = activity.xmppConnectionService.getShortcutService().getShortcutInfoCompat(conversation.getContact());
        }
        ShortcutManagerCompat.requestPinShortcut(activity, info, null);
    }


M src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java => src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +3 -3
@@ 1018,9 1018,9 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
    }

    private boolean handleJid(Invite invite) {
        List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
        if (invite.isAction(XmppUri.ACTION_JOIN)) {
            Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
        final List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
        final Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid(), invite.account);
        if (invite.isAction(XmppUri.ACTION_JOIN) || (contacts.isEmpty() && muc != null)) {
            if (muc != null && !invite.forceDialog) {
                switchToConversationDoNotAppend(muc, invite.getBody());
                return true;