mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Issue 3280: Add launcher shortcuts for special accounts/folders ("Unified Inbox" and "All messages")
This commit is contained in:
parent
700ba1d781
commit
02b07f34a1
@ -208,6 +208,10 @@
|
||||
android:launchMode="singleTask"
|
||||
android:configChanges="locale"
|
||||
>
|
||||
<intent-filter>
|
||||
<!-- This action is only to allow an entry point for launcher shortcuts -->
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.MessageView"
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.fsck.k9.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
@ -13,10 +17,14 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.BaseAccount;
|
||||
import com.fsck.k9.FontSizes;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.SearchAccount;
|
||||
import com.fsck.k9.SearchSpecification;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
|
||||
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
|
||||
private AccountsAdapter mAdapter;
|
||||
@ -41,14 +49,41 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
||||
List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
||||
|
||||
if (!K9.isHideSpecialAccounts()) {
|
||||
BaseAccount integratedInboxAccount = new SearchAccount(this, true, null, null);
|
||||
integratedInboxAccount.setDescription(
|
||||
getString(R.string.integrated_inbox_title));
|
||||
integratedInboxAccount.setEmail(
|
||||
getString(R.string.integrated_inbox_detail));
|
||||
|
||||
BaseAccount unreadAccount = new SearchAccount(this, false, null, null);
|
||||
unreadAccount.setDescription(
|
||||
getString(R.string.search_all_messages_title));
|
||||
unreadAccount.setEmail(
|
||||
getString(R.string.search_all_messages_detail));
|
||||
|
||||
accounts.add(integratedInboxAccount);
|
||||
accounts.add(unreadAccount);
|
||||
}
|
||||
|
||||
accounts.addAll(Arrays.asList(Preferences.getPreferences(this).getAccounts()));
|
||||
|
||||
mAdapter = new AccountsAdapter(accounts);
|
||||
getListView().setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private void setupShortcut(Account account) {
|
||||
final Intent shortcutIntent = FolderList.actionHandleAccountIntent(this, account, null, true);
|
||||
private void setupShortcut(BaseAccount account) {
|
||||
Intent shortcutIntent = null;
|
||||
|
||||
if (account instanceof SearchSpecification) {
|
||||
shortcutIntent = MessageList.actionHandleAccountIntent(
|
||||
this, account.getDescription(), (SearchSpecification) account);
|
||||
} else {
|
||||
shortcutIntent = FolderList.actionHandleAccountIntent(this,
|
||||
(Account) account, null, true);
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
@ -65,18 +100,18 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
||||
}
|
||||
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Account account = (Account) parent.getItemAtPosition(position);
|
||||
BaseAccount account = (BaseAccount) parent.getItemAtPosition(position);
|
||||
setupShortcut(account);
|
||||
}
|
||||
|
||||
class AccountsAdapter extends ArrayAdapter<Account> {
|
||||
public AccountsAdapter(Account[] accounts) {
|
||||
class AccountsAdapter extends ArrayAdapter<BaseAccount> {
|
||||
public AccountsAdapter(List<BaseAccount> accounts) {
|
||||
super(LauncherShortcuts.this, 0, accounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final Account account = getItem(position);
|
||||
final BaseAccount account = getItem(position);
|
||||
|
||||
final View view;
|
||||
if (convertView != null) {
|
||||
@ -110,7 +145,10 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
||||
|
||||
holder.description.setText(description);
|
||||
|
||||
holder.chip.setBackgroundColor(account.getChipColor());
|
||||
if (account instanceof Account) {
|
||||
holder.chip.setBackgroundColor(((Account) account).getChipColor());
|
||||
}
|
||||
|
||||
holder.chip.getBackground().setAlpha(255);
|
||||
|
||||
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountName());
|
||||
|
@ -52,10 +52,12 @@ import android.widget.Toast;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.AccountStats;
|
||||
import com.fsck.k9.BaseAccount;
|
||||
import com.fsck.k9.FontSizes;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.SearchAccount;
|
||||
import com.fsck.k9.SearchSpecification;
|
||||
import com.fsck.k9.activity.setup.AccountSettings;
|
||||
import com.fsck.k9.activity.setup.FolderSettings;
|
||||
@ -614,7 +616,11 @@ public class MessageList
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void actionHandle(Context context, String title, SearchSpecification searchSpecification) {
|
||||
/**
|
||||
* Creates and returns an intent that opens Unified Inbox or All Messages screen.
|
||||
*/
|
||||
public static Intent actionHandleAccountIntent(Context context, String title,
|
||||
SearchSpecification searchSpecification) {
|
||||
Intent intent = new Intent(context, MessageList.class);
|
||||
intent.putExtra(EXTRA_QUERY, searchSpecification.getQuery());
|
||||
if (searchSpecification.getRequiredFlags() != null) {
|
||||
@ -630,6 +636,13 @@ public class MessageList
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static void actionHandle(Context context, String title,
|
||||
SearchSpecification searchSpecification) {
|
||||
Intent intent = actionHandleAccountIntent(context, title, searchSpecification);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user