aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java64
2 files changed, 67 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 63d9ba7a..81f7c136 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -77,6 +77,7 @@ import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener;
import eu.siacs.conversations.utils.PRNGFixes;
import eu.siacs.conversations.utils.PhoneHelper;
+import eu.siacs.conversations.utils.UnreadCountBadgeHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnBindListener;
@@ -1033,7 +1034,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) {
- Log.d(Config.LOGTAG,"load more messages for "+conversation.getName() + " prior to "+MessageGenerator.getTimestamp(timestamp));
+ Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp));
if (XmppConnectionService.this.getMessageArchiveService().queryInProgress(conversation,callback)) {
return;
}
@@ -2205,6 +2206,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void updateConversationUi() {
+ UnreadCountBadgeHelper.update(this,unreadCount());
if (mOnConversationUpdate != null) {
mOnConversationUpdate.onConversationUpdate();
}
diff --git a/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java
new file mode 100644
index 00000000..3e194c05
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java
@@ -0,0 +1,64 @@
+package eu.siacs.conversations.utils;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.util.Log;
+
+import eu.siacs.conversations.Config;
+
+public class UnreadCountBadgeHelper {
+
+ private static int count = 0;
+
+ public static void update(final Context context,
+ final int count) {
+ if (UnreadCountBadgeHelper.count != count) {
+ UnreadCountBadgeHelper.count = count;
+ Log.d(Config.LOGTAG, "updating read count to: " + count);
+ final String packageName = context.getPackageName();
+ final String activity = context.getPackageManager().getLaunchIntentForPackage(packageName).getComponent().getClassName();
+ updateTeslaUnreadApi(context, packageName, activity, count);
+ updateApexNotificationApi(context, packageName, activity, count);
+ }
+ }
+
+ /*
+ TeslaUnread API primarily used by Nova Launcher
+ documented here: http://novalauncher.com/teslaunread-api/
+ */
+ private static void updateTeslaUnreadApi(final Context context,
+ final String packageName,
+ final String activity,
+ final int count) {
+ try {
+ ContentValues contentValues = new ContentValues();
+ contentValues.put("tag",packageName+"/"+activity);
+ contentValues.put("count",count);
+ context.getContentResolver().insert(
+ Uri.parse("content://com.teslacoilsw.notifier/unread_count"),
+ contentValues
+ );
+ } catch (IllegalArgumentException e) {
+ return;
+ } catch (Exception e) {
+ return;
+ }
+ }
+
+ /*
+ Apex Launcher Notifications API used by Apex Launcher Pro and others (Smart Launcher 2)
+ */
+ private static void updateApexNotificationApi(final Context context,
+ final String packageName,
+ final String activity,
+ final int count) {
+ Intent intent = new Intent("com.anddoes.launcher.COUNTER_CHANGED");
+ intent.putExtra("package",packageName);
+ //intent.putExtra("class",packageName+"."+activity);
+ intent.putExtra("class",activity);
+ intent.putExtra("count",count);
+ context.sendBroadcast(intent);
+ }
+}