From 04ec2abd2c96470b170540200c1ddd161cca210d Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 7 Dec 2012 15:04:53 +0100 Subject: [PATCH] Use local unread/flagged count in folder list and message list --- .../fsck/k9/controller/MessagingController.java | 16 +++++++++++----- src/com/fsck/k9/mail/store/LocalStore.java | 11 ++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 49214c970..960378779 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -2597,11 +2597,6 @@ public class MessagingController implements Runnable { Log.e(K9.LOG_TAG, "Couldn't set flags in local database", e); } - // Notify listeners of changed folder status -// for (MessagingListener l : getListeners()) { -// l.folderStatusChanged(account, folderName, localFolder.getUnreadMessageCount()); -// } - // Read folder name and UID of messages from the database Map> folderMap; try { @@ -2615,6 +2610,17 @@ public class MessagingController implements Runnable { for (Entry> entry : folderMap.entrySet()) { String folderName = entry.getKey(); + // Notify listeners of changed folder status + LocalFolder localFolder = localStore.getFolder(folderName); + try { + int unreadMessageCount = localFolder.getUnreadMessageCount(); + for (MessagingListener l : getListeners()) { + l.folderStatusChanged(account, folderName, unreadMessageCount); + } + } catch (MessagingException e) { + Log.w(K9.LOG_TAG, "Couldn't get unread count for folder: " + folderName, e); + } + // The error folder is always a local folder // TODO: Skip the remote part for all local-only folders if (account.getErrorFolderName().equals(folderName)) { diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index cde4941ac..1466936c4 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -100,7 +100,7 @@ public class LocalStore extends Store implements Serializable { "subject, sender_list, date, uid, flags, messages.id, to_list, cc_list, " + "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview, thread_root, thread_parent, deleted, read, flagged, answered, forwarded "; - static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class"; + static private String GET_FOLDER_COLS = "folders.id, name, SUM(read=0), visible_limit, last_updated, status, push_state, last_pushed, SUM(flagged), integrate, top_group, poll_class, push_class, display_class"; private static final String[] UID_CHECK_PROJECTION = { "uid" }; @@ -830,7 +830,10 @@ public class LocalStore extends Store implements Serializable { Cursor cursor = null; try { - cursor = db.rawQuery("SELECT " + GET_FOLDER_COLS + " FROM folders ORDER BY name ASC", null); + cursor = db.rawQuery("SELECT " + GET_FOLDER_COLS + " FROM folders " + + "LEFT JOIN messages ON (folder_id = folders.id AND" + + " (empty IS NULL OR empty != 1) AND deleted = 0) " + + "GROUP BY folders.id ORDER BY name ASC", null); while (cursor.moveToNext()) { LocalFolder folder = new LocalFolder(cursor.getString(1)); folder.open(cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7), cursor.getInt(8), cursor.getInt(9), cursor.getInt(10), cursor.getString(11), cursor.getString(12), cursor.getString(13)); @@ -1336,7 +1339,9 @@ public class LocalStore extends Store implements Serializable { public Void doDbWork(final SQLiteDatabase db) throws WrappedException { Cursor cursor = null; try { - String baseQuery = "SELECT " + GET_FOLDER_COLS + " FROM folders "; + String baseQuery = "SELECT " + GET_FOLDER_COLS + " FROM folders " + + "LEFT JOIN messages ON (folder_id = folders.id AND" + + " (empty IS NULL OR empty != 1) AND deleted = 0) "; if (mName != null) { cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { mName });