remove quiet hours
This commit is contained in:
parent
b7b4a78761
commit
ecf0e23144
|
@ -110,7 +110,8 @@ public class NotificationService {
|
||||||
public static final int ONGOING_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 10;
|
public static final int ONGOING_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 10;
|
||||||
public static final int MISSED_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 12;
|
public static final int MISSED_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 12;
|
||||||
private static final int DELIVERY_FAILED_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 13;
|
private static final int DELIVERY_FAILED_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 13;
|
||||||
public static final int ONGOING_VIDEO_TRANSCODING_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 14;
|
public static final int ONGOING_VIDEO_TRANSCODING_NOTIFICATION_ID =
|
||||||
|
NOTIFICATION_ID_MULTIPLIER * 14;
|
||||||
private final XmppConnectionService mXmppConnectionService;
|
private final XmppConnectionService mXmppConnectionService;
|
||||||
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
|
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
|
||||||
private final HashMap<Conversation, AtomicInteger> mBacklogMessageCounter = new HashMap<>();
|
private final HashMap<Conversation, AtomicInteger> mBacklogMessageCounter = new HashMap<>();
|
||||||
|
@ -282,20 +283,6 @@ public class NotificationService {
|
||||||
silentMessagesChannel.setGroup("chats");
|
silentMessagesChannel.setGroup("chats");
|
||||||
notificationManager.createNotificationChannel(silentMessagesChannel);
|
notificationManager.createNotificationChannel(silentMessagesChannel);
|
||||||
|
|
||||||
final NotificationChannel quietHoursChannel =
|
|
||||||
new NotificationChannel(
|
|
||||||
"quiet_hours",
|
|
||||||
c.getString(R.string.title_pref_quiet_hours),
|
|
||||||
NotificationManager.IMPORTANCE_LOW);
|
|
||||||
quietHoursChannel.setShowBadge(true);
|
|
||||||
quietHoursChannel.setLightColor(LED_COLOR);
|
|
||||||
quietHoursChannel.enableLights(true);
|
|
||||||
quietHoursChannel.setGroup("chats");
|
|
||||||
quietHoursChannel.enableVibration(false);
|
|
||||||
quietHoursChannel.setSound(null, null);
|
|
||||||
|
|
||||||
notificationManager.createNotificationChannel(quietHoursChannel);
|
|
||||||
|
|
||||||
final NotificationChannel deliveryFailedChannel =
|
final NotificationChannel deliveryFailedChannel =
|
||||||
new NotificationChannel(
|
new NotificationChannel(
|
||||||
"delivery_failed",
|
"delivery_failed",
|
||||||
|
@ -331,28 +318,6 @@ public class NotificationService {
|
||||||
"notifications_from_strangers", R.bool.notifications_from_strangers);
|
"notifications_from_strangers", R.bool.notifications_from_strangers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isQuietHours() {
|
|
||||||
if (!mXmppConnectionService.getBooleanPreference(
|
|
||||||
"enable_quiet_hours", R.bool.enable_quiet_hours)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final SharedPreferences preferences =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
|
|
||||||
final long startTime =
|
|
||||||
TimePreference.minutesToTimestamp(
|
|
||||||
preferences.getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE));
|
|
||||||
final long endTime =
|
|
||||||
TimePreference.minutesToTimestamp(
|
|
||||||
preferences.getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE));
|
|
||||||
final long nowTime = Calendar.getInstance().getTimeInMillis();
|
|
||||||
|
|
||||||
if (endTime < startTime) {
|
|
||||||
return nowTime > startTime || nowTime < endTime;
|
|
||||||
} else {
|
|
||||||
return nowTime > startTime && nowTime < endTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushFromBacklog(final Message message) {
|
public void pushFromBacklog(final Message message) {
|
||||||
if (notifyMessage(message)) {
|
if (notifyMessage(message)) {
|
||||||
synchronized (notifications) {
|
synchronized (notifications) {
|
||||||
|
@ -508,7 +473,8 @@ public class NotificationService {
|
||||||
public synchronized void startRinging(
|
public synchronized void startRinging(
|
||||||
final AbstractJingleConnection.Id id, final Set<Media> media) {
|
final AbstractJingleConnection.Id id, final Set<Media> media) {
|
||||||
showIncomingCallNotification(id, media);
|
showIncomingCallNotification(id, media);
|
||||||
final NotificationManager notificationManager = mXmppConnectionService.getSystemService(NotificationManager.class);
|
final NotificationManager notificationManager =
|
||||||
|
mXmppConnectionService.getSystemService(NotificationManager.class);
|
||||||
final int currentInterruptionFilter;
|
final int currentInterruptionFilter;
|
||||||
if (notificationManager != null) {
|
if (notificationManager != null) {
|
||||||
currentInterruptionFilter = notificationManager.getCurrentInterruptionFilter();
|
currentInterruptionFilter = notificationManager.getCurrentInterruptionFilter();
|
||||||
|
@ -786,7 +752,8 @@ public class NotificationService {
|
||||||
|
|
||||||
public void clearMissedCall(final Message message) {
|
public void clearMissedCall(final Message message) {
|
||||||
synchronized (mMissedCalls) {
|
synchronized (mMissedCalls) {
|
||||||
final Iterator<Map.Entry<Conversational,MissedCallsInfo>> iterator = mMissedCalls.entrySet().iterator();
|
final Iterator<Map.Entry<Conversational, MissedCallsInfo>> iterator =
|
||||||
|
mMissedCalls.entrySet().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Map.Entry<Conversational, MissedCallsInfo> entry = iterator.next();
|
final Map.Entry<Conversational, MissedCallsInfo> entry = iterator.next();
|
||||||
final Conversational conversational = entry.getKey();
|
final Conversational conversational = entry.getKey();
|
||||||
|
@ -794,7 +761,10 @@ public class NotificationService {
|
||||||
if (conversational.getUuid().equals(message.getConversation().getUuid())) {
|
if (conversational.getUuid().equals(message.getConversation().getUuid())) {
|
||||||
if (missedCallsInfo.removeMissedCall()) {
|
if (missedCallsInfo.removeMissedCall()) {
|
||||||
cancel(conversational.getUuid(), MISSED_CALL_NOTIFICATION_ID);
|
cancel(conversational.getUuid(), MISSED_CALL_NOTIFICATION_ID);
|
||||||
Log.d(Config.LOGTAG,conversational.getAccount().getJid().asBareJid()+": dismissed missed call because call was picked up on other device");
|
Log.d(
|
||||||
|
Config.LOGTAG,
|
||||||
|
conversational.getAccount().getJid().asBareJid()
|
||||||
|
+ ": dismissed missed call because call was picked up on other device");
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -860,8 +830,6 @@ public class NotificationService {
|
||||||
final SharedPreferences preferences =
|
final SharedPreferences preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
|
PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
|
||||||
|
|
||||||
final boolean quiteHours = isQuietHours();
|
|
||||||
|
|
||||||
final boolean notifyOnlyOneChild =
|
final boolean notifyOnlyOneChild =
|
||||||
notify
|
notify
|
||||||
&& conversations != null
|
&& conversations != null
|
||||||
|
@ -869,7 +837,7 @@ public class NotificationService {
|
||||||
== 1; // if this check is changed to > 0 catchup messages will
|
== 1; // if this check is changed to > 0 catchup messages will
|
||||||
// create one notification per conversation
|
// create one notification per conversation
|
||||||
|
|
||||||
if (notifications.size() == 0) {
|
if (notifications.isEmpty()) {
|
||||||
cancel(NOTIFICATION_ID);
|
cancel(NOTIFICATION_ID);
|
||||||
} else {
|
} else {
|
||||||
if (notify) {
|
if (notify) {
|
||||||
|
@ -878,29 +846,27 @@ public class NotificationService {
|
||||||
final Builder mBuilder;
|
final Builder mBuilder;
|
||||||
if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
mBuilder =
|
mBuilder =
|
||||||
buildSingleConversations(
|
buildSingleConversations(notifications.values().iterator().next(), notify);
|
||||||
notifications.values().iterator().next(), notify, quiteHours);
|
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
|
||||||
modifyForSoundVibrationAndLight(mBuilder, notify, quiteHours, preferences);
|
|
||||||
notify(NOTIFICATION_ID, mBuilder.build());
|
notify(NOTIFICATION_ID, mBuilder.build());
|
||||||
} else {
|
} else {
|
||||||
mBuilder = buildMultipleConversation(notify, quiteHours);
|
mBuilder = buildMultipleConversation(notify);
|
||||||
if (notifyOnlyOneChild) {
|
if (notifyOnlyOneChild) {
|
||||||
mBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
mBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
||||||
}
|
}
|
||||||
modifyForSoundVibrationAndLight(mBuilder, notify, quiteHours, preferences);
|
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
|
||||||
if (!summaryOnly) {
|
if (!summaryOnly) {
|
||||||
for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
|
for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
|
||||||
String uuid = entry.getKey();
|
String uuid = entry.getKey();
|
||||||
final boolean notifyThis =
|
final boolean notifyThis =
|
||||||
notifyOnlyOneChild ? conversations.contains(uuid) : notify;
|
notifyOnlyOneChild ? conversations.contains(uuid) : notify;
|
||||||
Builder singleBuilder =
|
Builder singleBuilder =
|
||||||
buildSingleConversations(entry.getValue(), notifyThis, quiteHours);
|
buildSingleConversations(entry.getValue(), notifyThis);
|
||||||
if (!notifyOnlyOneChild) {
|
if (!notifyOnlyOneChild) {
|
||||||
singleBuilder.setGroupAlertBehavior(
|
singleBuilder.setGroupAlertBehavior(
|
||||||
NotificationCompat.GROUP_ALERT_SUMMARY);
|
NotificationCompat.GROUP_ALERT_SUMMARY);
|
||||||
}
|
}
|
||||||
modifyForSoundVibrationAndLight(
|
modifyForSoundVibrationAndLight(singleBuilder, notifyThis, preferences);
|
||||||
singleBuilder, notifyThis, quiteHours, preferences);
|
|
||||||
singleBuilder.setGroup(MESSAGES_GROUP);
|
singleBuilder.setGroup(MESSAGES_GROUP);
|
||||||
setNotificationColor(singleBuilder);
|
setNotificationColor(singleBuilder);
|
||||||
notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
|
notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
|
||||||
|
@ -937,7 +903,7 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForSoundVibrationAndLight(
|
private void modifyForSoundVibrationAndLight(
|
||||||
Builder mBuilder, boolean notify, boolean quietHours, SharedPreferences preferences) {
|
final Builder mBuilder, final boolean notify, final SharedPreferences preferences) {
|
||||||
final Resources resources = mXmppConnectionService.getResources();
|
final Resources resources = mXmppConnectionService.getResources();
|
||||||
final String ringtone =
|
final String ringtone =
|
||||||
preferences.getString(
|
preferences.getString(
|
||||||
|
@ -947,10 +913,14 @@ public class NotificationService {
|
||||||
preferences.getBoolean(
|
preferences.getBoolean(
|
||||||
AppSettings.NOTIFICATION_VIBRATE,
|
AppSettings.NOTIFICATION_VIBRATE,
|
||||||
resources.getBoolean(R.bool.vibrate_on_notification));
|
resources.getBoolean(R.bool.vibrate_on_notification));
|
||||||
final boolean led = preferences.getBoolean(AppSettings.NOTIFICATION_LED, resources.getBoolean(R.bool.led));
|
final boolean led =
|
||||||
|
preferences.getBoolean(
|
||||||
|
AppSettings.NOTIFICATION_LED, resources.getBoolean(R.bool.led));
|
||||||
final boolean headsup =
|
final boolean headsup =
|
||||||
preferences.getBoolean(AppSettings.NOTIFICATION_HEADS_UP, resources.getBoolean(R.bool.headsup_notifications));
|
preferences.getBoolean(
|
||||||
if (notify && !quietHours) {
|
AppSettings.NOTIFICATION_HEADS_UP,
|
||||||
|
resources.getBoolean(R.bool.headsup_notifications));
|
||||||
|
if (notify) {
|
||||||
if (vibrate) {
|
if (vibrate) {
|
||||||
final int dat = 70;
|
final int dat = 70;
|
||||||
final long[] pattern = {0, 3 * dat, dat, dat};
|
final long[] pattern = {0, 3 * dat, dat, dat};
|
||||||
|
@ -1116,11 +1086,11 @@ public class NotificationService {
|
||||||
setNotificationColor(builder);
|
setNotificationColor(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Builder buildMultipleConversation(final boolean notify, final boolean quietHours) {
|
private Builder buildMultipleConversation(final boolean notify) {
|
||||||
final Builder mBuilder =
|
final Builder mBuilder =
|
||||||
new NotificationCompat.Builder(
|
new NotificationCompat.Builder(
|
||||||
mXmppConnectionService,
|
mXmppConnectionService,
|
||||||
quietHours ? "quiet_hours" : (notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages"));
|
notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages");
|
||||||
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
||||||
style.setBigContentTitle(
|
style.setBigContentTitle(
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
|
@ -1185,8 +1155,8 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Builder buildSingleConversations(
|
private Builder buildSingleConversations(
|
||||||
final ArrayList<Message> messages, final boolean notify, final boolean quietHours) {
|
final ArrayList<Message> messages, final boolean notify) {
|
||||||
final var channel = quietHours ? "quiet_hours" : (notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages");
|
final var channel = notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages";
|
||||||
final Builder notificationBuilder =
|
final Builder notificationBuilder =
|
||||||
new NotificationCompat.Builder(mXmppConnectionService, channel);
|
new NotificationCompat.Builder(mXmppConnectionService, channel);
|
||||||
if (messages.isEmpty()) {
|
if (messages.isEmpty()) {
|
||||||
|
@ -1672,21 +1642,34 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createCallAction(String sessionId, final String action, int requestCode) {
|
private PendingIntent createCallAction(String sessionId, final String action, int requestCode) {
|
||||||
return pendingServiceIntent(mXmppConnectionService, action, requestCode, ImmutableMap.of(RtpSessionActivity.EXTRA_SESSION_ID, sessionId));
|
return pendingServiceIntent(
|
||||||
|
mXmppConnectionService,
|
||||||
|
action,
|
||||||
|
requestCode,
|
||||||
|
ImmutableMap.of(RtpSessionActivity.EXTRA_SESSION_ID, sessionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createSnoozeIntent(final Conversation conversation) {
|
private PendingIntent createSnoozeIntent(final Conversation conversation) {
|
||||||
return pendingServiceIntent(mXmppConnectionService, XmppConnectionService.ACTION_SNOOZE, generateRequestCode(conversation,22),ImmutableMap.of("uuid",conversation.getUuid()));
|
return pendingServiceIntent(
|
||||||
|
mXmppConnectionService,
|
||||||
|
XmppConnectionService.ACTION_SNOOZE,
|
||||||
|
generateRequestCode(conversation, 22),
|
||||||
|
ImmutableMap.of("uuid", conversation.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PendingIntent pendingServiceIntent(final Context context, final String action, final int requestCode) {
|
private static PendingIntent pendingServiceIntent(
|
||||||
|
final Context context, final String action, final int requestCode) {
|
||||||
return pendingServiceIntent(context, action, requestCode, ImmutableMap.of());
|
return pendingServiceIntent(context, action, requestCode, ImmutableMap.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PendingIntent pendingServiceIntent(final Context context, final String action, final int requestCode, final Map<String,String> extras) {
|
private static PendingIntent pendingServiceIntent(
|
||||||
|
final Context context,
|
||||||
|
final String action,
|
||||||
|
final int requestCode,
|
||||||
|
final Map<String, String> extras) {
|
||||||
final Intent intent = new Intent(context, XmppConnectionService.class);
|
final Intent intent = new Intent(context, XmppConnectionService.class);
|
||||||
intent.setAction(action);
|
intent.setAction(action);
|
||||||
for(final Map.Entry<String,String> entry : extras.entrySet()) {
|
for (final Map.Entry<String, String> entry : extras.entrySet()) {
|
||||||
intent.putExtra(entry.getKey(), entry.getValue());
|
intent.putExtra(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return PendingIntent.getService(
|
return PendingIntent.getService(
|
||||||
|
@ -1748,8 +1731,7 @@ public class NotificationService {
|
||||||
connected = 0;
|
connected = 0;
|
||||||
} else {
|
} else {
|
||||||
enabled = Iterables.size(Iterables.filter(accounts, Account::isEnabled));
|
enabled = Iterables.size(Iterables.filter(accounts, Account::isEnabled));
|
||||||
connected =
|
connected = Iterables.size(Iterables.filter(accounts, Account::isOnlineAndConnected));
|
||||||
Iterables.size(Iterables.filter(accounts, Account::isOnlineAndConnected));
|
|
||||||
}
|
}
|
||||||
mBuilder.setContentText(
|
mBuilder.setContentText(
|
||||||
mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
|
mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
|
||||||
|
@ -1759,10 +1741,7 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
mBuilder.setWhen(0)
|
mBuilder.setWhen(0)
|
||||||
.setPriority(Notification.PRIORITY_MIN)
|
.setPriority(Notification.PRIORITY_MIN)
|
||||||
.setSmallIcon(
|
.setSmallIcon(connected > 0 ? R.drawable.ic_link_24dp : R.drawable.ic_link_off_24dp)
|
||||||
connected > 0
|
|
||||||
? R.drawable.ic_link_24dp
|
|
||||||
: R.drawable.ic_link_off_24dp)
|
|
||||||
.setLocalOnly(true);
|
.setLocalOnly(true);
|
||||||
|
|
||||||
if (Compatibility.runsTwentySix()) {
|
if (Compatibility.runsTwentySix()) {
|
||||||
|
|
Loading…
Reference in a new issue