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.content.SharedPreferences.Editor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
|
||||||
import com.fsck.k9.BaseAccount;
|
import com.fsck.k9.BaseAccount;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.provider.UnreadWidgetProvider;
|
import com.fsck.k9.provider.UnreadWidgetProvider;
|
||||||
@ -57,18 +56,11 @@ public class UnreadWidgetConfiguration extends AccountList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean displaySpecialAccounts() {
|
protected boolean displaySpecialAccounts() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAccountSelected(BaseAccount baseAccount) {
|
protected void onAccountSelected(BaseAccount account) {
|
||||||
if (!(baseAccount instanceof Account)) {
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Account account = (Account) baseAccount;
|
|
||||||
|
|
||||||
// Save widget configuration
|
// Save widget configuration
|
||||||
String accountUuid = account.getUuid();
|
String accountUuid = account.getUuid();
|
||||||
saveAccountUuid(this, mAppWidgetId, accountUuid);
|
saveAccountUuid(this, mAppWidgetId, accountUuid);
|
||||||
|
@ -3391,6 +3391,14 @@ public class MessagingController implements Runnable {
|
|||||||
threadPool.execute(new Runnable() {
|
threadPool.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
getSearchAccountStatsSynchronous(searchAccount, listener);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount,
|
||||||
|
final MessagingListener listener) {
|
||||||
|
|
||||||
Preferences preferences = Preferences.getPreferences(mApplication);
|
Preferences preferences = Preferences.getPreferences(mApplication);
|
||||||
LocalSearch search = searchAccount.getRelatedSearch();
|
LocalSearch search = searchAccount.getRelatedSearch();
|
||||||
|
|
||||||
@ -3447,9 +3455,11 @@ public class MessagingController implements Runnable {
|
|||||||
stats.flaggedMessageCount = flaggedMessageCount;
|
stats.flaggedMessageCount = flaggedMessageCount;
|
||||||
|
|
||||||
// ...and notify the listener
|
// ...and notify the listener
|
||||||
|
if (listener != null) {
|
||||||
listener.accountStatusChanged(searchAccount, stats);
|
listener.accountStatusChanged(searchAccount, stats);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getFolderUnreadMessageCount(final Account account, final String folderName,
|
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.Account;
|
||||||
import com.fsck.k9.AccountStats;
|
import com.fsck.k9.AccountStats;
|
||||||
|
import com.fsck.k9.BaseAccount;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.activity.UnreadWidgetConfiguration;
|
import com.fsck.k9.activity.UnreadWidgetConfiguration;
|
||||||
import com.fsck.k9.activity.FolderList;
|
import com.fsck.k9.activity.FolderList;
|
||||||
import com.fsck.k9.activity.MessageList;
|
import com.fsck.k9.activity.MessageList;
|
||||||
|
import com.fsck.k9.controller.MessagingController;
|
||||||
import com.fsck.k9.search.LocalSearch;
|
import com.fsck.k9.search.LocalSearch;
|
||||||
|
import com.fsck.k9.search.SearchAccount;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
@ -53,23 +56,49 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
|
|||||||
String accountName = context.getString(R.string.app_name);
|
String accountName = context.getString(R.string.app_name);
|
||||||
Intent clickIntent = null;
|
Intent clickIntent = null;
|
||||||
try {
|
try {
|
||||||
Account account = Preferences.getPreferences(context).getAccount(accountUuid);
|
BaseAccount account = null;
|
||||||
if (account != null) {
|
AccountStats stats = null;
|
||||||
AccountStats stats = account.getStats(context);
|
|
||||||
unreadCount = stats.unreadMessageCount;
|
SearchAccount searchAccount = null;
|
||||||
accountName = account.getDescription();
|
if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
|
||||||
if (K9.FOLDER_NONE.equals(account.getAutoExpandFolderName())) {
|
searchAccount = SearchAccount.createUnifiedInboxAccount(context);
|
||||||
clickIntent = FolderList.actionHandleAccountIntent(context, account, null,
|
} else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
|
||||||
false);
|
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 {
|
} else {
|
||||||
LocalSearch search = new LocalSearch(account.getAutoExpandFolderName());
|
Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
|
||||||
search.addAllowedFolder(account.getAutoExpandFolderName());
|
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());
|
search.addAccountUuid(account.getUuid());
|
||||||
clickIntent = MessageList.intentDisplaySearch(context, search, false, true,
|
clickIntent = MessageList.intentDisplaySearch(context, search, false, true,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account != null) {
|
||||||
|
accountName = account.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats != null) {
|
||||||
|
unreadCount = stats.unreadMessageCount;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (K9.DEBUG) {
|
if (K9.DEBUG) {
|
||||||
Log.e(K9.LOG_TAG, "Error getting widget configuration", e);
|
Log.e(K9.LOG_TAG, "Error getting widget configuration", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user