aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-12-01 17:15:36 +0100
committerDaniel Gultsch <daniel@gultsch.de>2015-12-01 17:15:36 +0100
commit65b5504e68e36116234bd69126304d6d764b678b (patch)
treed3cf85c055c519d1b16b1cdb5ccc65a27965e167 /src/main
parent2cd43f704215f963200249c0771362ce2bcf4768 (diff)
introduce config.java variable to optionally show number of connected accounts in notification
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java2
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java92
-rw-r--r--src/main/res/values/strings.xml1
3 files changed, 58 insertions, 37 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 8c0528455..a53074687 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -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 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 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;
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 125b1c268..abd42f4c4 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -60,12 +60,12 @@ public class NotificationService {
public boolean notify(final Message message) {
return (message.getStatus() == Message.STATUS_RECEIVED)
- && notificationsEnabled()
- && !message.getConversation().isMuted()
- && (message.getConversation().isPnNA()
- || conferenceNotificationsEnabled()
- || wasHighlightedOrPrivate(message)
- );
+ && notificationsEnabled()
+ && !message.getConversation().isMuted()
+ && (message.getConversation().isPnNA()
+ || conferenceNotificationsEnabled()
+ || wasHighlightedOrPrivate(message)
+ );
}
public void notifyPebble(final Message message) {
@@ -179,7 +179,7 @@ public class NotificationService {
public void updateNotification(final boolean notify) {
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ .getSystemService(Context.NOTIFICATION_SERVICE);
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
final String ringtone = preferences.getString("notification_ringtone", null);
@@ -235,7 +235,7 @@ public class NotificationService {
conversation = messages.get(0).getConversation();
final String name = conversation.getName();
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(", ");
}
@@ -275,9 +275,9 @@ public class NotificationService {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
mXmppConnectionService.getResources().getString(R.string.download_x_file,
- UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
+ UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
createDownloadIntent(message)
- );
+ );
}
if ((message = getFirstLocationMessage(messages)) != null) {
mBuilder.addAction(R.drawable.ic_room_white_24dp,
@@ -290,26 +290,26 @@ public class NotificationService {
}
private void modifyForImage(final Builder builder, final Message message,
- final ArrayList<Message> messages, final boolean notify) {
+ final ArrayList<Message> messages, final boolean notify) {
try {
final Bitmap bitmap = mXmppConnectionService.getFileBackend()
- .getThumbnail(message, getPixel(288), false);
+ .getThumbnail(message, getPixel(288), false);
final ArrayList<Message> tmp = new ArrayList<>();
for (final Message msg : messages) {
if (msg.getType() == Message.TYPE_TEXT
&& msg.getTransferable() == null) {
tmp.add(msg);
- }
+ }
}
final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.bigPicture(bitmap);
if (tmp.size() > 0) {
bigPictureStyle.setSummaryText(getMergedBodies(tmp));
- builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService,tmp.get(0)).first);
+ builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, tmp.get(0)).first);
} else {
builder.setContentText(mXmppConnectionService.getString(
R.string.received_x_file,
- UIHelper.getFileDescriptionString(mXmppConnectionService,message)));
+ UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
}
builder.setStyle(bigPictureStyle);
} catch (final FileNotFoundException e) {
@@ -318,11 +318,11 @@ public class NotificationService {
}
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.setContentText(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first);
+ builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
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.getFileParams().height > 0) {
return message;
- }
+ }
}
return null;
}
@@ -349,7 +349,7 @@ public class NotificationService {
}
private Message getFirstLocationMessage(final Iterable<Message> messages) {
- for(final Message message : messages) {
+ for (final Message message : messages) {
if (GeoHelper.isGeoUri(message.getBody())) {
return message;
}
@@ -360,7 +360,7 @@ public class NotificationService {
private CharSequence getMergedBodies(final ArrayList<Message> messages) {
final StringBuilder text = new StringBuilder();
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) {
text.append("\n");
}
@@ -370,9 +370,9 @@ public class NotificationService {
private PendingIntent createShowLocationIntent(final Message message) {
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
- for(Intent intent : intents) {
+ for (Intent intent : intents) {
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();
@@ -380,7 +380,7 @@ public class NotificationService {
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
final TaskStackBuilder stackBuilder = TaskStackBuilder
- .create(mXmppConnectionService);
+ .create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class);
final Intent viewConversationIntent = new Intent(mXmppConnectionService,
@@ -432,10 +432,10 @@ public class NotificationService {
}
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.putExtra("account",account.getJid().toBareJid().toString());
- return PendingIntent.getService(mXmppConnectionService,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
+ intent.putExtra("account", account.getJid().toBareJid().toString());
+ return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
private boolean wasHighlightedOrPrivate(final Message message) {
@@ -468,7 +468,7 @@ public class NotificationService {
private int getPixel(final int dp) {
final DisplayMetrics metrics = mXmppConnectionService.getResources()
- .getDisplayMetrics();
+ .getDisplayMetrics();
return ((int) (dp * metrics.density));
}
@@ -478,7 +478,7 @@ public class NotificationService {
private boolean inMiniGracePeriod(final Account account) {
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);
}
@@ -486,10 +486,25 @@ public class NotificationService {
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
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.setWhen(0);
- mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
+ mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
final int cancelIcon;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setCategory(Notification.CATEGORY_SERVICE);
@@ -505,20 +520,23 @@ public class NotificationService {
}
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() {
- final NotificationManager mNotificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
+ final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
final List<Account> errors = new ArrayList<>();
for (final Account account : mXmppConnectionService.getAccounts()) {
if (account.hasErrorStatus()) {
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);
if (errors.size() == 0) {
- mNotificationManager.cancel(ERROR_NOTIFICATION_ID);
+ notificationManager.cancel(ERROR_NOTIFICATION_ID);
return;
} else if (errors.size() == 1) {
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
@@ -545,12 +563,12 @@ public class NotificationService {
final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class);
- final Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);
+ final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
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);
- mNotificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
+ notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
}
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 9f2573637..e312bd59d 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -548,4 +548,5 @@
<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_valid_hostname">This is not a valid hostname</string>
+ <string name="connected_accounts">%1$d of %2$d accounts connected</string>
</resources>