mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Add support for "Unified Inbox" and "All messages" to unread widget
This commit is contained in:
parent
cc3580c675
commit
ba691612dd
@ -7,7 +7,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.BaseAccount;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.provider.UnreadWidgetProvider;
|
||||
@ -57,18 +56,11 @@ public class UnreadWidgetConfiguration extends AccountList {
|
||||
|
||||
@Override
|
||||
protected boolean displaySpecialAccounts() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAccountSelected(BaseAccount baseAccount) {
|
||||
if (!(baseAccount instanceof Account)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Account account = (Account) baseAccount;
|
||||
|
||||
protected void onAccountSelected(BaseAccount account) {
|
||||
// Save widget configuration
|
||||
String accountUuid = account.getUuid();
|
||||
saveAccountUuid(this, mAppWidgetId, accountUuid);
|
||||
|
@ -3391,6 +3391,14 @@ public class MessagingController implements Runnable {
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getSearchAccountStatsSynchronous(searchAccount, listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount,
|
||||
final MessagingListener listener) {
|
||||
|
||||
Preferences preferences = Preferences.getPreferences(mApplication);
|
||||
LocalSearch search = searchAccount.getRelatedSearch();
|
||||
|
||||
@ -3447,9 +3455,11 @@ public class MessagingController implements Runnable {
|
||||
stats.flaggedMessageCount = flaggedMessageCount;
|
||||
|
||||
// ...and notify the listener
|
||||
if (listener != null) {
|
||||
listener.accountStatusChanged(searchAccount, stats);
|
||||
}
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
public void getFolderUnreadMessageCount(final Account account, final String folderName,
|
||||
|
@ -2,13 +2,16 @@ package com.fsck.k9.provider;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.AccountStats;
|
||||
import com.fsck.k9.BaseAccount;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.activity.UnreadWidgetConfiguration;
|
||||
import com.fsck.k9.activity.FolderList;
|
||||
import com.fsck.k9.activity.MessageList;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.search.LocalSearch;
|
||||
import com.fsck.k9.search.SearchAccount;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
@ -53,23 +56,49 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
|
||||
String accountName = context.getString(R.string.app_name);
|
||||
Intent clickIntent = null;
|
||||
try {
|
||||
Account account = Preferences.getPreferences(context).getAccount(accountUuid);
|
||||
if (account != null) {
|
||||
AccountStats stats = account.getStats(context);
|
||||
unreadCount = stats.unreadMessageCount;
|
||||
accountName = account.getDescription();
|
||||
if (K9.FOLDER_NONE.equals(account.getAutoExpandFolderName())) {
|
||||
clickIntent = FolderList.actionHandleAccountIntent(context, account, null,
|
||||
false);
|
||||
BaseAccount account = null;
|
||||
AccountStats stats = null;
|
||||
|
||||
SearchAccount searchAccount = null;
|
||||
if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
|
||||
searchAccount = SearchAccount.createUnifiedInboxAccount(context);
|
||||
} else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
|
||||
searchAccount = SearchAccount.createAllMessagesAccount(context);
|
||||
}
|
||||
|
||||
if (searchAccount != null) {
|
||||
account = searchAccount;
|
||||
MessagingController controller = MessagingController.getInstance(K9.app);
|
||||
stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
|
||||
clickIntent = MessageList.intentDisplaySearch(context,
|
||||
searchAccount.getRelatedSearch(), false, true, true);
|
||||
} else {
|
||||
LocalSearch search = new LocalSearch(account.getAutoExpandFolderName());
|
||||
search.addAllowedFolder(account.getAutoExpandFolderName());
|
||||
Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
|
||||
if (realAccount != null) {
|
||||
account = realAccount;
|
||||
stats = realAccount.getStats(context);
|
||||
|
||||
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
|
||||
clickIntent = FolderList.actionHandleAccountIntent(context, realAccount,
|
||||
null, false);
|
||||
} else {
|
||||
LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
|
||||
search.addAllowedFolder(realAccount.getAutoExpandFolderName());
|
||||
search.addAccountUuid(account.getUuid());
|
||||
clickIntent = MessageList.intentDisplaySearch(context, search, false, true,
|
||||
true);
|
||||
}
|
||||
clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
}
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
accountName = account.getDescription();
|
||||
}
|
||||
|
||||
if (stats != null) {
|
||||
unreadCount = stats.unreadMessageCount;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (K9.DEBUG) {
|
||||
Log.e(K9.LOG_TAG, "Error getting widget configuration", e);
|
||||
|
Loading…
Reference in New Issue
Block a user