mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-17 07:30: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:launchMode="singleTask"
|
||||||
android:configChanges="locale"
|
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>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.fsck.k9.activity.MessageView"
|
android:name="com.fsck.k9.activity.MessageView"
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.fsck.k9.activity;
|
package com.fsck.k9.activity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@ -13,10 +17,14 @@ import android.widget.ListView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
|
import com.fsck.k9.BaseAccount;
|
||||||
import com.fsck.k9.FontSizes;
|
import com.fsck.k9.FontSizes;
|
||||||
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.SearchAccount;
|
||||||
|
import com.fsck.k9.SearchSpecification;
|
||||||
|
import com.fsck.k9.helper.Utility;
|
||||||
|
|
||||||
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
|
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
|
||||||
private AccountsAdapter mAdapter;
|
private AccountsAdapter mAdapter;
|
||||||
@ -41,14 +49,41 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh() {
|
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);
|
mAdapter = new AccountsAdapter(accounts);
|
||||||
getListView().setAdapter(mAdapter);
|
getListView().setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupShortcut(Account account) {
|
private void setupShortcut(BaseAccount account) {
|
||||||
final Intent shortcutIntent = FolderList.actionHandleAccountIntent(this, account, null, true);
|
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 intent = new Intent();
|
||||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
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) {
|
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);
|
setupShortcut(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccountsAdapter extends ArrayAdapter<Account> {
|
class AccountsAdapter extends ArrayAdapter<BaseAccount> {
|
||||||
public AccountsAdapter(Account[] accounts) {
|
public AccountsAdapter(List<BaseAccount> accounts) {
|
||||||
super(LauncherShortcuts.this, 0, accounts);
|
super(LauncherShortcuts.this, 0, accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
final Account account = getItem(position);
|
final BaseAccount account = getItem(position);
|
||||||
|
|
||||||
final View view;
|
final View view;
|
||||||
if (convertView != null) {
|
if (convertView != null) {
|
||||||
@ -110,7 +145,10 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
|||||||
|
|
||||||
holder.description.setText(description);
|
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.chip.getBackground().setAlpha(255);
|
||||||
|
|
||||||
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountName());
|
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.Account;
|
||||||
import com.fsck.k9.AccountStats;
|
import com.fsck.k9.AccountStats;
|
||||||
|
import com.fsck.k9.BaseAccount;
|
||||||
import com.fsck.k9.FontSizes;
|
import com.fsck.k9.FontSizes;
|
||||||
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.SearchAccount;
|
||||||
import com.fsck.k9.SearchSpecification;
|
import com.fsck.k9.SearchSpecification;
|
||||||
import com.fsck.k9.activity.setup.AccountSettings;
|
import com.fsck.k9.activity.setup.AccountSettings;
|
||||||
import com.fsck.k9.activity.setup.FolderSettings;
|
import com.fsck.k9.activity.setup.FolderSettings;
|
||||||
@ -614,7 +616,11 @@ public class MessageList
|
|||||||
context.startActivity(intent);
|
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 intent = new Intent(context, MessageList.class);
|
||||||
intent.putExtra(EXTRA_QUERY, searchSpecification.getQuery());
|
intent.putExtra(EXTRA_QUERY, searchSpecification.getQuery());
|
||||||
if (searchSpecification.getRequiredFlags() != null) {
|
if (searchSpecification.getRequiredFlags() != null) {
|
||||||
@ -630,6 +636,13 @@ public class MessageList
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_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);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user