Use conversation notifications

Allows for per-conversation priority and sound
This commit is contained in:
Stephen Paul Weber 2023-09-07 13:08:18 +02:00 committed by Daniel Gultsch
parent 04b5744a2a
commit 11e6cb9693
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 36 additions and 7 deletions

View file

@ -10,6 +10,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Typeface;
@ -34,6 +35,7 @@ import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.Person;
import androidx.core.app.RemoteInput;
import androidx.core.content.ContextCompat;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.graphics.drawable.IconCompat;
import com.google.common.base.Joiner;
@ -1283,8 +1285,8 @@ public class NotificationService {
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
Contact contact = conversation.getContact();
Uri systemAccount = contact.getSystemAccount();
final Contact contact = conversation.getContact();
final Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) {
mBuilder.addPerson(systemAccount.toString());
}
@ -1293,6 +1295,16 @@ public class NotificationService {
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
.getSystemService(ShortcutManager.class)
.pushDynamicShortcut(info.toShortcutInfo());
}
}
return mBuilder;
}

View file

@ -11,6 +11,9 @@ import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.graphics.drawable.IconCompat;
import java.util.ArrayList;
import java.util.HashMap;
@ -88,13 +91,27 @@ public class ShortcutService {
}
}
@TargetApi(Build.VERSION_CODES.N_MR1)
private ShortcutInfo getShortcutInfo(Contact contact) {
return new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact))
public ShortcutInfoCompat getShortcutInfoCompat(final Contact contact) {
final ShortcutInfoCompat.Builder builder =
new ShortcutInfoCompat.Builder(xmppConnectionService, getShortcutId(contact))
.setShortLabel(contact.getDisplayName())
.setIntent(getShortcutIntent(contact))
.setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact)))
.build();
.setIsConversation();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
builder.setIcon(
IconCompat.createFromIcon(
xmppConnectionService,
Icon.createWithBitmap(
xmppConnectionService
.getAvatarService()
.getRoundedShortcut(contact))));
}
return builder.build();
}
@TargetApi(Build.VERSION_CODES.N_MR1)
private ShortcutInfo getShortcutInfo(final Contact contact) {
return getShortcutInfoCompat(contact).toShortcutInfo();
}
private static boolean contactsChanged(List<Contact> needles, List<ShortcutInfo> haystack) {