mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Use the new AccountList activity when creating launcher shortcuts
This commit is contained in:
parent
f36d2a6b23
commit
64f4f7e4a3
@ -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.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@ -12,17 +16,19 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity displaying the list of accounts.
|
* Activity displaying the list of accounts.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Classes extending this abstract class have to provide an {@link #onAccountSelected(Account)}
|
* Classes extending this abstract class have to provide an {@link #onAccountSelected(BaseAccount)}
|
||||||
* method to perform an action when an account is selected.
|
* method to perform an action when an account is selected.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@ -51,47 +57,64 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
|
|||||||
new LoadAccounts().execute();
|
new LoadAccounts().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
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);
|
||||||
onAccountSelected(account);
|
onAccountSelected(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link AccountsAdapter} instance and assign it to the {@link ListView}.
|
* Create a new {@link AccountsAdapter} instance and assign it to the {@link ListView}.
|
||||||
*
|
*
|
||||||
* @param accounts
|
* @param realAccounts
|
||||||
* An array of accounts to display.
|
* An array of accounts to display.
|
||||||
*/
|
*/
|
||||||
public void populateListView(Account[] accounts) {
|
public void populateListView(Account[] realAccounts) {
|
||||||
|
List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
||||||
|
|
||||||
|
if (displaySpecialAccounts() && !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(realAccounts));
|
||||||
AccountsAdapter adapter = new AccountsAdapter(accounts);
|
AccountsAdapter adapter = new AccountsAdapter(accounts);
|
||||||
ListView listView = getListView();
|
ListView listView = getListView();
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
listView.invalidate();
|
listView.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementing decide whether or not to display special accounts in the list.
|
||||||
|
*
|
||||||
|
* @return {@code true}, if special accounts should be listed. {@code false}, otherwise.
|
||||||
|
*/
|
||||||
|
protected abstract boolean displaySpecialAccounts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be called when an account was selected.
|
* This method will be called when an account was selected.
|
||||||
*
|
*
|
||||||
* @param account
|
* @param account
|
||||||
* The account the user selected.
|
* The account the user selected.
|
||||||
*/
|
*/
|
||||||
protected abstract void onAccountSelected(Account account);
|
protected abstract void onAccountSelected(BaseAccount account);
|
||||||
|
|
||||||
class AccountsAdapter extends ArrayAdapter<Account> {
|
class AccountsAdapter extends ArrayAdapter<BaseAccount> {
|
||||||
private Account[] mAccounts;
|
public AccountsAdapter(List<BaseAccount> accounts) {
|
||||||
|
|
||||||
public AccountsAdapter(Account[] accounts) {
|
|
||||||
super(AccountList.this, 0, accounts);
|
super(AccountList.this, 0, accounts);
|
||||||
mAccounts = accounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Account[] getAccounts() {
|
|
||||||
return mAccounts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
@ -127,7 +150,13 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
|
|||||||
|
|
||||||
holder.description.setText(description);
|
holder.description.setText(description);
|
||||||
|
|
||||||
holder.chip.setBackgroundColor(account.getChipColor());
|
if (account instanceof Account) {
|
||||||
|
Account realAccount = (Account) account;
|
||||||
|
holder.chip.setBackgroundColor(realAccount.getChipColor());
|
||||||
|
} else {
|
||||||
|
holder.chip.setBackgroundColor(0xff999999);
|
||||||
|
}
|
||||||
|
|
||||||
holder.chip.getBackground().setAlpha(255);
|
holder.chip.getBackground().setAlpha(255);
|
||||||
|
|
||||||
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP,
|
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP,
|
||||||
|
@ -1,90 +1,44 @@
|
|||||||
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;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
import com.fsck.k9.BaseAccount;
|
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.R;
|
||||||
import com.fsck.k9.SearchAccount;
|
|
||||||
import com.fsck.k9.SearchSpecification;
|
import com.fsck.k9.SearchSpecification;
|
||||||
import com.fsck.k9.helper.Utility;
|
|
||||||
|
|
||||||
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
|
|
||||||
private AccountsAdapter mAdapter;
|
|
||||||
private FontSizes mFontSizes = K9.getFontSizes();
|
|
||||||
|
|
||||||
|
public class LauncherShortcuts extends AccountList {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
// finish() immediately if we aren't supposed to be here
|
// finish() immediately if we aren't supposed to be here
|
||||||
if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
|
if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.account_list);
|
super.onCreate(icicle);
|
||||||
ListView listView = getListView();
|
|
||||||
listView.setOnItemClickListener(this);
|
|
||||||
listView.setItemsCanFocus(false);
|
|
||||||
|
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh() {
|
@Override
|
||||||
List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
protected boolean displaySpecialAccounts() {
|
||||||
|
return true;
|
||||||
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(BaseAccount account) {
|
@Override
|
||||||
|
protected void onAccountSelected(BaseAccount account) {
|
||||||
Intent shortcutIntent = null;
|
Intent shortcutIntent = null;
|
||||||
|
|
||||||
if (account instanceof SearchSpecification) {
|
if (account instanceof SearchSpecification) {
|
||||||
shortcutIntent = MessageList.actionHandleAccountIntent(
|
shortcutIntent = MessageList.actionHandleAccountIntent(this, account.getDescription(),
|
||||||
this, account.getDescription(), (SearchSpecification) account);
|
(SearchSpecification) account);
|
||||||
} else {
|
} else {
|
||||||
shortcutIntent = FolderList.actionHandleAccountIntent(this,
|
shortcutIntent = FolderList.actionHandleAccountIntent(this, (Account) account, null,
|
||||||
(Account) account, null, true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||||
String description = account.getDescription();
|
String description = account.getDescription();
|
||||||
@ -98,69 +52,4 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
|
|||||||
setResult(RESULT_OK, intent);
|
setResult(RESULT_OK, intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
BaseAccount account = (BaseAccount) parent.getItemAtPosition(position);
|
|
||||||
setupShortcut(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 BaseAccount account = getItem(position);
|
|
||||||
|
|
||||||
final View view;
|
|
||||||
if (convertView != null) {
|
|
||||||
view = convertView;
|
|
||||||
} else {
|
|
||||||
view = getLayoutInflater().inflate(R.layout.accounts_item, parent, false);
|
|
||||||
view.findViewById(R.id.active_icons).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountViewHolder holder = (AccountViewHolder) view.getTag();
|
|
||||||
if (holder == null) {
|
|
||||||
holder = new AccountViewHolder();
|
|
||||||
holder.description = (TextView) view.findViewById(R.id.description);
|
|
||||||
holder.email = (TextView) view.findViewById(R.id.email);
|
|
||||||
holder.chip = view.findViewById(R.id.chip);
|
|
||||||
|
|
||||||
view.setTag(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
String description = account.getDescription();
|
|
||||||
if (account.getEmail().equals(description)) {
|
|
||||||
holder.email.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
holder.email.setVisibility(View.VISIBLE);
|
|
||||||
holder.email.setText(account.getEmail());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (description == null || description.length() == 0) {
|
|
||||||
description = account.getEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.description.setText(description);
|
|
||||||
|
|
||||||
if (account instanceof Account) {
|
|
||||||
holder.chip.setBackgroundColor(((Account) account).getChipColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.chip.getBackground().setAlpha(255);
|
|
||||||
|
|
||||||
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountName());
|
|
||||||
holder.email.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountDescription());
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccountViewHolder {
|
|
||||||
public TextView description;
|
|
||||||
public TextView email;
|
|
||||||
public View chip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import android.content.SharedPreferences.Editor;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
|
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;
|
||||||
|
|
||||||
@ -55,7 +56,19 @@ public class UnreadWidgetConfiguration extends AccountList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAccountSelected(Account account) {
|
protected boolean displaySpecialAccounts() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAccountSelected(BaseAccount baseAccount) {
|
||||||
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user