Bug fixes

This commit is contained in:
DrKLO 2014-07-10 15:30:55 +04:00
parent d3afc8362e
commit d9b9a721a6
4 changed files with 80 additions and 7 deletions

View file

@ -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<Long, Integer> pushDialogs = new HashMap<Long, Integer>();
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<TLRPC.WallPaper> wallPapers) {
storageQueue.postRunnable(new Runnable() {
@Override

View file

@ -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<Long, Integer> dialogs, int totalCount) {
}
}

View file

@ -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);
}

View file

@ -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);
}
}
}