From d9b9a721a6c5620381d87e27f982e146587afeb0 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Thu, 10 Jul 2014 15:30:55 +0400 Subject: [PATCH] Bug fixes --- .../org/telegram/android/MessagesStorage.java | 32 +++++++++++++++++++ .../android/NotificationsController.java | 17 ++++++---- .../org/telegram/messenger/DispatchQueue.java | 18 +++++++++++ .../ui/PopupNotificationActivity.java | 20 +++++++++++- 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index ab10e432..244dc47a 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -116,6 +116,7 @@ public class MessagesStorage { database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_dialogs ON dialogs(date);").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks ON enc_tasks(date);").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_idx_dialogs ON dialogs(last_mid);").stepThis().dispose(); + database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_idx_media ON media(uid, mid);").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media(mid);").stepThis().dispose(); @@ -180,6 +181,8 @@ public class MessagesStorage { database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose(); database.executeFast("CREATE TABLE IF NOT EXISTS sent_files_v2(uid TEXT, type INTEGER, data BLOB, PRIMARY KEY (uid, type))").stepThis().dispose(); + + database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose(); } } catch (Exception e) { FileLog.e("tmessages", e); @@ -267,6 +270,35 @@ public class MessagesStorage { }); } + public void loadUnreadMessages() { + storageQueue.postRunnable(new Runnable() { + @Override + public void run() { + try { + final HashMap pushDialogs = new HashMap(); + int totalCount = 0; + SQLiteCursor cursor = database.queryFinalized("SELECT did, unread_count FROM dialogs WHERE unread_count != 0"); + while (cursor.next()) { + long did = cursor.longValue(0); + int count = cursor.intValue(1); + pushDialogs.put(did, count); + totalCount += count; + } + cursor.dispose(); + final int totalCountFinal = totalCount; + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + NotificationsController.getInstance().processLoadedUnreadMessages(pushDialogs, totalCountFinal); + } + }); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + }); + } + public void putWallpapers(final ArrayList wallPapers) { storageQueue.postRunnable(new Runnable() { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java index 499ec428..b65c3e2b 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java @@ -318,12 +318,6 @@ public class NotificationsController { name = Utilities.formatName(user.first_name, user.last_name); } - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext) - .setContentTitle(name) - .setSmallIcon(R.drawable.notification) - .setAutoCancel(true) - .setContentIntent(contentIntent); - String detailText = null; if (pushDialogs.size() == 1) { detailText = LocaleController.formatPluralString("NewMessages", pushMessages.size()); @@ -331,6 +325,13 @@ public class NotificationsController { detailText = String.format("%s %s", LocaleController.formatPluralString("NewMessages", pushMessages.size()), LocaleController.formatPluralString("FromContacts", pushDialogs.size())); } + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext) + .setContentTitle(name) + .setSmallIcon(R.drawable.notification) + .setAutoCancel(true) + .setContentText(detailText) + .setContentIntent(contentIntent); + String lastMessage = null; NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); @@ -537,4 +538,8 @@ public class NotificationsController { } } } + + public void processLoadedUnreadMessages(HashMap dialogs, int totalCount) { + + } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java b/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java index bb260020..15a573a9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java @@ -41,6 +41,24 @@ public class DispatchQueue extends Thread { } } + public void cancelRunnable(Runnable runnable) { + if (handler == null) { + synchronized (handlerSyncObject) { + if (handler == null) { + try { + handlerSyncObject.wait(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + } + + if (handler != null) { + handler.removeCallbacks(runnable); + } + } + public void postRunnable(Runnable runnable) { postRunnable(runnable, 0); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java index a18cb7fe..6aa0bbd9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java @@ -85,6 +85,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC private float moveStartX = -1; private boolean startedMoving = false; private Runnable onAnimationEndRunnable = null; + private Runnable wakeLockRunnable = null; private class FrameLayoutTouch extends FrameLayout { public FrameLayoutTouch(Context context) { @@ -650,7 +651,21 @@ public class PopupNotificationActivity extends Activity implements NotificationC currentMessageNum = 0; } getNewMessage(); - wakeLock.acquire(7000); + wakeLock.acquire(); + Utilities.stageQueue.postRunnable(wakeLockRunnable = new Runnable() { + @Override + public void run() { + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + wakeLockRunnable = null; + if (wakeLock.isHeld()) { + wakeLock.release(); + } + } + }); + } + }, 7000); } private void getNewMessage() { @@ -957,5 +972,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC if (wakeLock.isHeld()) { wakeLock.release(); } + if (wakeLockRunnable != null) { + Utilities.stageQueue.cancelRunnable(wakeLockRunnable); + } } }