Use local unread/flagged count in folder list and message list

This commit is contained in:
cketti 2012-12-07 15:04:53 +01:00
parent 41d608f3be
commit 04ec2abd2c
2 changed files with 19 additions and 8 deletions

View File

@ -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<String, List<String>> folderMap;
try {
@ -2615,6 +2610,17 @@ public class MessagingController implements Runnable {
for (Entry<String, List<String>> 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)) {

View File

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