Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Jul 10, 2014
1 parent d3afc83 commit d9b9a72
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void openDatabase() {
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();
Expand Down Expand Up @@ -180,6 +181,8 @@ public void openDatabase() {
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);
Expand Down Expand Up @@ -267,6 +270,35 @@ public void run() {
});
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,20 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
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());
} else {
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);
Expand Down Expand Up @@ -537,4 +538,8 @@ public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean
}
}
}

public void processLoadedUnreadMessages(HashMap<Long, Integer> dialogs, int totalCount) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ private void sendMessage(Message msg, int delay) {
}
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -650,7 +651,21 @@ private void handleIntent(Intent intent) {
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() {
Expand Down Expand Up @@ -957,5 +972,8 @@ protected void onFinish() {
if (wakeLock.isHeld()) {
wakeLock.release();
}
if (wakeLockRunnable != null) {
Utilities.stageQueue.cancelRunnable(wakeLockRunnable);
}
}
}

0 comments on commit d9b9a72

Please sign in to comment.