Remove Account.getFolderUnreadCount()

Make the only caller use the existing implementation in
MessagingController instead.
This commit is contained in:
cketti 2018-03-11 00:05:39 +01:00
parent 3328728076
commit abf3ba1e1e
3 changed files with 14 additions and 59 deletions

View file

@ -1,6 +1,7 @@
package com.fsck.k9;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@ -8,44 +9,39 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import timber.log.Timber;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.ssl.LocalKeyStore;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mail.store.StoreConfig;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.mailstore.StorageManager.StorageProvider;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.preferences.StorageEditor;
import com.fsck.k9.preferences.Storage;
import com.fsck.k9.provider.EmailProvider;
import com.fsck.k9.provider.EmailProvider.StatsColumns;
import com.fsck.k9.preferences.StorageEditor;
import com.fsck.k9.search.ConditionsTreeNode;
import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.search.SqlQueryBuilder;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.search.SearchSpecification.SearchField;
import com.fsck.k9.mail.ssl.LocalKeyStore;
import com.fsck.k9.view.ColorChip;
import com.larswerkman.colorpicker.ColorPicker;
import timber.log.Timber;
import static com.fsck.k9.Preferences.getEnumStringPref;
@ -766,51 +762,6 @@ public class Account implements BaseAccount, StoreConfig {
}
public int getFolderUnreadCount(Context context, String folderServerId) throws MessagingException {
if (!isAvailable(context)) {
return 0;
}
int unreadMessageCount = 0;
Cursor cursor = loadUnreadCountForFolder(context, folderServerId);
try {
if (cursor != null && cursor.moveToFirst()) {
unreadMessageCount = cursor.getInt(0);
}
} finally {
Utility.closeQuietly(cursor);
}
return unreadMessageCount;
}
private Cursor loadUnreadCountForFolder(Context context, String folderServerId) {
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI,
"account/" + getUuid() + "/stats");
String[] projection = {
StatsColumns.UNREAD_COUNT,
};
LocalSearch search = new LocalSearch();
search.addAllowedFolder(folderServerId);
// Use the LocalSearch instance to create a WHERE clause to query the content provider
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<>();
ConditionsTreeNode conditions = search.getConditions();
SqlQueryBuilder.buildWhereClause(this, conditions, query, queryArgs);
String selection = query.toString();
String[] selectionArgs = queryArgs.toArray(new String[queryArgs.size()]);
return cr.query(uri, projection, selection, selectionArgs, null);
}
public synchronized void setChipColor(int color) {
chipColor = color;
cacheChips();

View file

@ -2840,8 +2840,7 @@ public class MessagingController {
int unreadMessageCount = 0;
try {
Folder localFolder = account.getLocalStore().getFolder(folderServerId);
unreadMessageCount = localFolder.getUnreadMessageCount();
unreadMessageCount = getFolderUnreadMessageCount(account, folderServerId);
} catch (MessagingException me) {
Timber.e(me, "Count not get unread count for account %s", account.getDescription());
}
@ -2853,6 +2852,11 @@ public class MessagingController {
put("getFolderUnread:" + account.getDescription() + ":" + folderServerId, l, unreadRunnable);
}
public int getFolderUnreadMessageCount(Account account, String folderServerId) throws MessagingException {
LocalStore localStore = account.getLocalStore();
Folder localFolder = localStore.getFolder(folderServerId);
return localFolder.getUnreadMessageCount();
}
public boolean isMoveCapable(MessageReference messageReference) {
return !messageReference.getUid().startsWith(K9.LOCAL_UID_PREFIX);

View file

@ -56,7 +56,7 @@ public class UnreadWidgetProperties {
stats = controller.getAccountStats(account);
return stats.unreadMessageCount;
case FOLDER:
return ((Account) baseAccount).getFolderUnreadCount(context, folderServerId);
return controller.getFolderUnreadMessageCount((Account) baseAccount, folderServerId);
default:
return -1;
}