Improved contact notification channel management

pull/156/head
M66B 6 years ago
parent 84a27c7d7a
commit 2dabc63476

@ -1128,7 +1128,6 @@ but even Google's Chrome cannot handle this.
* Did you know that you can retry sending messages by using pull-down-to-refresh in the outbox? * Did you know that you can retry sending messages by using pull-down-to-refresh in the outbox?
* Did you know that you can swipe a conversation left or right to go to the next or previous conversation? * Did you know that you can swipe a conversation left or right to go to the next or previous conversation?
* Did you know that you can tap on an image to see where it will be downloaded from? * Did you know that you can tap on an image to see where it will be downloaded from?
* Did you know that you can long press the bell icon to delete the notification channel for the email address?
* Did you know that you can long press the folder icon in the action bar to select an account? * Did you know that you can long press the folder icon in the action bar to select an account?
<br /> <br />

@ -176,7 +176,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
)); ));
public class ViewHolder extends RecyclerView.ViewHolder implements public class ViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener, View.OnLongClickListener, View.OnClickListener,
CompoundButton.OnCheckedChangeListener, CompoundButton.OnCheckedChangeListener,
BottomNavigationView.OnNavigationItemSelectedListener { BottomNavigationView.OnNavigationItemSelectedListener {
private View view; private View view;
@ -392,7 +392,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivExpanderAddress.setOnClickListener(this); ivExpanderAddress.setOnClickListener(this);
ibSearchContact.setOnClickListener(this); ibSearchContact.setOnClickListener(this);
ibNotifyContact.setOnClickListener(this); ibNotifyContact.setOnClickListener(this);
ibNotifyContact.setOnLongClickListener(this);
ibAddContact.setOnClickListener(this); ibAddContact.setOnClickListener(this);
btnDownloadAttachments.setOnClickListener(this); btnDownloadAttachments.setOnClickListener(this);
@ -416,7 +415,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivExpanderAddress.setOnClickListener(null); ivExpanderAddress.setOnClickListener(null);
ibSearchContact.setOnClickListener(null); ibSearchContact.setOnClickListener(null);
ibNotifyContact.setOnClickListener(null); ibNotifyContact.setOnClickListener(null);
ibNotifyContact.setOnLongClickListener(null);
ibAddContact.setOnClickListener(null); ibAddContact.setOnClickListener(null);
btnDownloadAttachments.setOnClickListener(null); btnDownloadAttachments.setOnClickListener(null);
btnSaveAttachments.setOnClickListener(null); btnSaveAttachments.setOnClickListener(null);
@ -1098,16 +1096,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
} }
@Override
public boolean onLongClick(View v) {
TupleMessageEx message = getMessage();
if (message == null)
return false;
onNotifyContactDelete(message);
return true;
}
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
TupleMessageEx message = getMessage(); TupleMessageEx message = getMessage();
@ -1224,35 +1212,67 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
private void onNotifyContact(TupleMessageEx message) { private void onNotifyContact(final TupleMessageEx message) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final InternetAddress from = (InternetAddress) message.from[0];
final String channelId = "notification." + from.getAddress().toLowerCase();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibAddContact);
NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel == null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 1, R.string.title_create_channel);
else {
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 2, R.string.title_edit_channel);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 3, R.string.title_delete_channel);
}
InternetAddress from = (InternetAddress) message.from[0]; popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
String channelId = "notification." + from.getAddress().toLowerCase(); @Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.string.title_create_channel:
onActionCreateChannel();
return true;
NotificationChannel channel = new NotificationChannel( case R.string.title_edit_channel:
channelId, from.getAddress(), onActionEditChannel();
NotificationManager.IMPORTANCE_HIGH); return true;
channel.setGroup("contacts");
channel.setDescription(from.getPersonal());
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
nm.createNotificationChannel(channel);
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) case R.string.title_delete_channel:
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()) onActionDeleteChannel();
.putExtra(Settings.EXTRA_CHANNEL_ID, channelId); return true;
context.startActivity(intent);
}
@TargetApi(Build.VERSION_CODES.O) default:
private void onNotifyContactDelete(TupleMessageEx message) { return false;
if (message.from != null && message.from.length > 0) { }
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }
InternetAddress from = (InternetAddress) message.from[0]; @TargetApi(Build.VERSION_CODES.O)
String channelName = "notification." + from.getAddress().toLowerCase(); private void onActionCreateChannel() {
nm.deleteNotificationChannel(channelName); NotificationChannel channel = new NotificationChannel(
} channelId, from.getAddress(),
NotificationManager.IMPORTANCE_HIGH);
channel.setGroup("contacts");
channel.setDescription(from.getPersonal());
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
nm.createNotificationChannel(channel);
onActionEditChannel();
}
private void onActionEditChannel() {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
context.startActivity(intent);
}
private void onActionDeleteChannel() {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.deleteNotificationChannel(channelId);
}
});
popupMenu.show();
} }
private void onAddContact(TupleMessageEx message) { private void onAddContact(TupleMessageEx message) {

Loading…
Cancel
Save