Use conversation notifications
Allows for per-conversation priority and sound
This commit is contained in:
parent
04b5744a2a
commit
11e6cb9693
|
@ -10,6 +10,7 @@ import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ShortcutManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
@ -34,6 +35,7 @@ import androidx.core.app.NotificationManagerCompat;
|
||||||
import androidx.core.app.Person;
|
import androidx.core.app.Person;
|
||||||
import androidx.core.app.RemoteInput;
|
import androidx.core.app.RemoteInput;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.core.content.pm.ShortcutInfoCompat;
|
||||||
import androidx.core.graphics.drawable.IconCompat;
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
|
@ -1283,8 +1285,8 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
Contact contact = conversation.getContact();
|
final Contact contact = conversation.getContact();
|
||||||
Uri systemAccount = contact.getSystemAccount();
|
final Uri systemAccount = contact.getSystemAccount();
|
||||||
if (systemAccount != null) {
|
if (systemAccount != null) {
|
||||||
mBuilder.addPerson(systemAccount.toString());
|
mBuilder.addPerson(systemAccount.toString());
|
||||||
}
|
}
|
||||||
|
@ -1293,6 +1295,16 @@ public class NotificationService {
|
||||||
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);
|
||||||
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
|
mXmppConnectionService
|
||||||
|
.getSystemService(ShortcutManager.class)
|
||||||
|
.pushDynamicShortcut(info.toShortcutInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mBuilder;
|
return mBuilder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -88,13 +91,27 @@ public class ShortcutService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N_MR1)
|
public ShortcutInfoCompat getShortcutInfoCompat(final Contact contact) {
|
||||||
private ShortcutInfo getShortcutInfo(Contact contact) {
|
final ShortcutInfoCompat.Builder builder =
|
||||||
return new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact))
|
new ShortcutInfoCompat.Builder(xmppConnectionService, getShortcutId(contact))
|
||||||
.setShortLabel(contact.getDisplayName())
|
.setShortLabel(contact.getDisplayName())
|
||||||
.setIntent(getShortcutIntent(contact))
|
.setIntent(getShortcutIntent(contact))
|
||||||
.setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact)))
|
.setIsConversation();
|
||||||
.build();
|
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) {
|
private static boolean contactsChanged(List<Contact> needles, List<ShortcutInfo> haystack) {
|
||||||
|
|
Loading…
Reference in a new issue