introduce config.java variable to optionally show number of connected accounts in notification
This commit is contained in:
parent
2cd43f7042
commit
65b5504e68
|
@ -16,6 +16,8 @@ public final class Config {
|
||||||
public static final String DOMAIN_LOCK = null; //only allow account creation for this domain
|
public static final String DOMAIN_LOCK = null; //only allow account creation for this domain
|
||||||
public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox
|
public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox
|
||||||
public static final boolean HIDE_PGP_IN_UI = false; //some more consumer focused clients might want to disable OpenPGP
|
public static final boolean HIDE_PGP_IN_UI = false; //some more consumer focused clients might want to disable OpenPGP
|
||||||
|
public static final boolean PARANOID_MODE = false; //disables ability to send unencrypted 1-on-1 chats and forces TOR
|
||||||
|
public static final boolean SHOW_CONNECTED_ACCOUNTS = true; //show number of connected accounts in foreground notification
|
||||||
|
|
||||||
public static final boolean LEGACY_NAMESPACE_HTTP_UPLOAD = false;
|
public static final boolean LEGACY_NAMESPACE_HTTP_UPLOAD = false;
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,12 @@ public class NotificationService {
|
||||||
|
|
||||||
public boolean notify(final Message message) {
|
public boolean notify(final Message message) {
|
||||||
return (message.getStatus() == Message.STATUS_RECEIVED)
|
return (message.getStatus() == Message.STATUS_RECEIVED)
|
||||||
&& notificationsEnabled()
|
&& notificationsEnabled()
|
||||||
&& !message.getConversation().isMuted()
|
&& !message.getConversation().isMuted()
|
||||||
&& (message.getConversation().isPnNA()
|
&& (message.getConversation().isPnNA()
|
||||||
|| conferenceNotificationsEnabled()
|
|| conferenceNotificationsEnabled()
|
||||||
|| wasHighlightedOrPrivate(message)
|
|| wasHighlightedOrPrivate(message)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyPebble(final Message message) {
|
public void notifyPebble(final Message message) {
|
||||||
|
@ -179,7 +179,7 @@ public class NotificationService {
|
||||||
|
|
||||||
public void updateNotification(final boolean notify) {
|
public void updateNotification(final boolean notify) {
|
||||||
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
|
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
|
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
|
||||||
|
|
||||||
final String ringtone = preferences.getString("notification_ringtone", null);
|
final String ringtone = preferences.getString("notification_ringtone", null);
|
||||||
|
@ -235,7 +235,7 @@ public class NotificationService {
|
||||||
conversation = messages.get(0).getConversation();
|
conversation = messages.get(0).getConversation();
|
||||||
final String name = conversation.getName();
|
final String name = conversation.getName();
|
||||||
style.addLine(Html.fromHtml("<b>" + name + "</b> "
|
style.addLine(Html.fromHtml("<b>" + name + "</b> "
|
||||||
+ UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first));
|
+ UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first));
|
||||||
names.append(name);
|
names.append(name);
|
||||||
names.append(", ");
|
names.append(", ");
|
||||||
}
|
}
|
||||||
|
@ -275,9 +275,9 @@ public class NotificationService {
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
|
||||||
R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
|
R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
|
||||||
mXmppConnectionService.getResources().getString(R.string.download_x_file,
|
mXmppConnectionService.getResources().getString(R.string.download_x_file,
|
||||||
UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
|
UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
|
||||||
createDownloadIntent(message)
|
createDownloadIntent(message)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ((message = getFirstLocationMessage(messages)) != null) {
|
if ((message = getFirstLocationMessage(messages)) != null) {
|
||||||
mBuilder.addAction(R.drawable.ic_room_white_24dp,
|
mBuilder.addAction(R.drawable.ic_room_white_24dp,
|
||||||
|
@ -290,26 +290,26 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForImage(final Builder builder, final Message message,
|
private void modifyForImage(final Builder builder, final Message message,
|
||||||
final ArrayList<Message> messages, final boolean notify) {
|
final ArrayList<Message> messages, final boolean notify) {
|
||||||
try {
|
try {
|
||||||
final Bitmap bitmap = mXmppConnectionService.getFileBackend()
|
final Bitmap bitmap = mXmppConnectionService.getFileBackend()
|
||||||
.getThumbnail(message, getPixel(288), false);
|
.getThumbnail(message, getPixel(288), false);
|
||||||
final ArrayList<Message> tmp = new ArrayList<>();
|
final ArrayList<Message> tmp = new ArrayList<>();
|
||||||
for (final Message msg : messages) {
|
for (final Message msg : messages) {
|
||||||
if (msg.getType() == Message.TYPE_TEXT
|
if (msg.getType() == Message.TYPE_TEXT
|
||||||
&& msg.getTransferable() == null) {
|
&& msg.getTransferable() == null) {
|
||||||
tmp.add(msg);
|
tmp.add(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
|
final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
|
||||||
bigPictureStyle.bigPicture(bitmap);
|
bigPictureStyle.bigPicture(bitmap);
|
||||||
if (tmp.size() > 0) {
|
if (tmp.size() > 0) {
|
||||||
bigPictureStyle.setSummaryText(getMergedBodies(tmp));
|
bigPictureStyle.setSummaryText(getMergedBodies(tmp));
|
||||||
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService,tmp.get(0)).first);
|
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, tmp.get(0)).first);
|
||||||
} else {
|
} else {
|
||||||
builder.setContentText(mXmppConnectionService.getString(
|
builder.setContentText(mXmppConnectionService.getString(
|
||||||
R.string.received_x_file,
|
R.string.received_x_file,
|
||||||
UIHelper.getFileDescriptionString(mXmppConnectionService,message)));
|
UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
|
||||||
}
|
}
|
||||||
builder.setStyle(bigPictureStyle);
|
builder.setStyle(bigPictureStyle);
|
||||||
} catch (final FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
|
@ -318,11 +318,11 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForTextOnly(final Builder builder,
|
private void modifyForTextOnly(final Builder builder,
|
||||||
final ArrayList<Message> messages, final boolean notify) {
|
final ArrayList<Message> messages, final boolean notify) {
|
||||||
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
|
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
|
||||||
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first);
|
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
builder.setTicker(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(messages.size() - 1)).first);
|
builder.setTicker(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size() - 1)).first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ public class NotificationService {
|
||||||
&& message.getEncryption() != Message.ENCRYPTION_PGP
|
&& message.getEncryption() != Message.ENCRYPTION_PGP
|
||||||
&& message.getFileParams().height > 0) {
|
&& message.getFileParams().height > 0) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message getFirstLocationMessage(final Iterable<Message> messages) {
|
private Message getFirstLocationMessage(final Iterable<Message> messages) {
|
||||||
for(final Message message : messages) {
|
for (final Message message : messages) {
|
||||||
if (GeoHelper.isGeoUri(message.getBody())) {
|
if (GeoHelper.isGeoUri(message.getBody())) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ public class NotificationService {
|
||||||
private CharSequence getMergedBodies(final ArrayList<Message> messages) {
|
private CharSequence getMergedBodies(final ArrayList<Message> messages) {
|
||||||
final StringBuilder text = new StringBuilder();
|
final StringBuilder text = new StringBuilder();
|
||||||
for (int i = 0; i < messages.size(); ++i) {
|
for (int i = 0; i < messages.size(); ++i) {
|
||||||
text.append(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(i)).first);
|
text.append(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(i)).first);
|
||||||
if (i != messages.size() - 1) {
|
if (i != messages.size() - 1) {
|
||||||
text.append("\n");
|
text.append("\n");
|
||||||
}
|
}
|
||||||
|
@ -370,9 +370,9 @@ public class NotificationService {
|
||||||
|
|
||||||
private PendingIntent createShowLocationIntent(final Message message) {
|
private PendingIntent createShowLocationIntent(final Message message) {
|
||||||
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
|
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
|
||||||
for(Intent intent : intents) {
|
for (Intent intent : intents) {
|
||||||
if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
|
if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
|
||||||
return PendingIntent.getActivity(mXmppConnectionService,18,intent,PendingIntent.FLAG_UPDATE_CURRENT);
|
return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createOpenConversationsIntent();
|
return createOpenConversationsIntent();
|
||||||
|
@ -380,7 +380,7 @@ public class NotificationService {
|
||||||
|
|
||||||
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
|
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
|
||||||
final TaskStackBuilder stackBuilder = TaskStackBuilder
|
final TaskStackBuilder stackBuilder = TaskStackBuilder
|
||||||
.create(mXmppConnectionService);
|
.create(mXmppConnectionService);
|
||||||
stackBuilder.addParentStack(ConversationActivity.class);
|
stackBuilder.addParentStack(ConversationActivity.class);
|
||||||
|
|
||||||
final Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
final Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
||||||
|
@ -432,10 +432,10 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createDisableAccountIntent(final Account account) {
|
private PendingIntent createDisableAccountIntent(final Account account) {
|
||||||
final Intent intent = new Intent(mXmppConnectionService,XmppConnectionService.class);
|
final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
|
||||||
intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
|
intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
|
||||||
intent.putExtra("account",account.getJid().toBareJid().toString());
|
intent.putExtra("account", account.getJid().toBareJid().toString());
|
||||||
return PendingIntent.getService(mXmppConnectionService,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
|
return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean wasHighlightedOrPrivate(final Message message) {
|
private boolean wasHighlightedOrPrivate(final Message message) {
|
||||||
|
@ -468,7 +468,7 @@ public class NotificationService {
|
||||||
|
|
||||||
private int getPixel(final int dp) {
|
private int getPixel(final int dp) {
|
||||||
final DisplayMetrics metrics = mXmppConnectionService.getResources()
|
final DisplayMetrics metrics = mXmppConnectionService.getResources()
|
||||||
.getDisplayMetrics();
|
.getDisplayMetrics();
|
||||||
return ((int) (dp * metrics.density));
|
return ((int) (dp * metrics.density));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,7 +478,7 @@ public class NotificationService {
|
||||||
|
|
||||||
private boolean inMiniGracePeriod(final Account account) {
|
private boolean inMiniGracePeriod(final Account account) {
|
||||||
final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
|
final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
|
||||||
: Config.MINI_GRACE_PERIOD * 2;
|
: Config.MINI_GRACE_PERIOD * 2;
|
||||||
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
|
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,10 +486,25 @@ public class NotificationService {
|
||||||
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||||
|
|
||||||
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
|
||||||
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
|
if (Config.SHOW_CONNECTED_ACCOUNTS) {
|
||||||
|
List<Account> accounts = mXmppConnectionService.getAccounts();
|
||||||
|
int enabled = 0;
|
||||||
|
int connected = 0;
|
||||||
|
for (Account account : accounts) {
|
||||||
|
if (account.isOnlineAndConnected()) {
|
||||||
|
connected++;
|
||||||
|
enabled++;
|
||||||
|
} else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
enabled++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
|
||||||
|
} else {
|
||||||
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
|
||||||
|
}
|
||||||
mBuilder.setContentIntent(createOpenConversationsIntent());
|
mBuilder.setContentIntent(createOpenConversationsIntent());
|
||||||
mBuilder.setWhen(0);
|
mBuilder.setWhen(0);
|
||||||
mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
|
mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
|
||||||
final int cancelIcon;
|
final int cancelIcon;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
mBuilder.setCategory(Notification.CATEGORY_SERVICE);
|
mBuilder.setCategory(Notification.CATEGORY_SERVICE);
|
||||||
|
@ -505,20 +520,23 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createOpenConversationsIntent() {
|
private PendingIntent createOpenConversationsIntent() {
|
||||||
return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService,ConversationActivity.class),0);
|
return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationActivity.class), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateErrorNotification() {
|
public void updateErrorNotification() {
|
||||||
final NotificationManager mNotificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
|
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
final List<Account> errors = new ArrayList<>();
|
final List<Account> errors = new ArrayList<>();
|
||||||
for (final Account account : mXmppConnectionService.getAccounts()) {
|
for (final Account account : mXmppConnectionService.getAccounts()) {
|
||||||
if (account.hasErrorStatus()) {
|
if (account.hasErrorStatus()) {
|
||||||
errors.add(account);
|
errors.add(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mXmppConnectionService.getPreferences().getBoolean("keep_foreground_service", false)) {
|
||||||
|
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
|
||||||
|
}
|
||||||
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||||
if (errors.size() == 0) {
|
if (errors.size() == 0) {
|
||||||
mNotificationManager.cancel(ERROR_NOTIFICATION_ID);
|
notificationManager.cancel(ERROR_NOTIFICATION_ID);
|
||||||
return;
|
return;
|
||||||
} else if (errors.size() == 1) {
|
} else if (errors.size() == 1) {
|
||||||
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
|
||||||
|
@ -545,12 +563,12 @@ public class NotificationService {
|
||||||
final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
|
final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
|
||||||
stackBuilder.addParentStack(ConversationActivity.class);
|
stackBuilder.addParentStack(ConversationActivity.class);
|
||||||
|
|
||||||
final Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);
|
final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
|
||||||
stackBuilder.addNextIntent(manageAccountsIntent);
|
stackBuilder.addNextIntent(manageAccountsIntent);
|
||||||
|
|
||||||
final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
|
final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
mBuilder.setContentIntent(resultPendingIntent);
|
mBuilder.setContentIntent(resultPendingIntent);
|
||||||
mNotificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
|
notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -548,4 +548,5 @@
|
||||||
<string name="hostname_or_onion">Server- or .onion-Address</string>
|
<string name="hostname_or_onion">Server- or .onion-Address</string>
|
||||||
<string name="not_a_valid_port">This is not a valid port number</string>
|
<string name="not_a_valid_port">This is not a valid port number</string>
|
||||||
<string name="not_valid_hostname">This is not a valid hostname</string>
|
<string name="not_valid_hostname">This is not a valid hostname</string>
|
||||||
|
<string name="connected_accounts">%1$d of %2$d accounts connected</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue