1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-28 04:02:19 -05:00

Formatting of Accounts.java

This commit is contained in:
Sander Bogaert 2012-08-28 10:43:25 -04:00 committed by Andrew Chen
parent 0f51eb54c1
commit 416ac8b646

View File

@ -149,16 +149,16 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
class AccountsHandler extends Handler { class AccountsHandler extends Handler {
private void setViewTitle() { private void setViewTitle() {
mActionBarTitle.setText(" "+getString(R.string.accounts_title)); mActionBarTitle.setText(" " + getString(R.string.accounts_title));
mActionBarUnread.setText(String.valueOf(mUnreadMessageCount)); mActionBarUnread.setText(String.valueOf(mUnreadMessageCount));
String operation = mListener.getOperation(Accounts.this, getTimeFormat()); String operation = mListener.getOperation(Accounts.this, getTimeFormat());
operation.trim(); operation.trim();
if (operation.length() < 1) { if (operation.length() < 1) {
mActionBarSubTitle.setVisibility(View.GONE); mActionBarSubTitle.setVisibility(View.GONE);
} else { } else {
mActionBarSubTitle.setVisibility(View.VISIBLE); mActionBarSubTitle.setVisibility(View.VISIBLE);
mActionBarSubTitle.setText(operation); mActionBarSubTitle.setText(operation);
} }
} }
public void refreshTitle() { public void refreshTitle() {
@ -217,7 +217,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
if (progress) { if (progress) {
mRefreshMenuItem.setActionView(R.layout.actionbar_indeterminate_progress_actionview); mRefreshMenuItem.setActionView(R.layout.actionbar_indeterminate_progress_actionview);
} else { } else {
mRefreshMenuItem.setActionView(null); mRefreshMenuItem.setActionView(null);
@ -374,8 +374,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// see if we should show the welcome message // see if we should show the welcome message
if (accounts.length < 1) { if (accounts.length < 1) {
WelcomeMessage.showWelcomeMessage(this); WelcomeMessage.showWelcomeMessage(this);
finish(); finish();
} }
boolean startup = intent.getBooleanExtra(EXTRA_STARTUP, true); boolean startup = intent.getBooleanExtra(EXTRA_STARTUP, true);
@ -400,31 +400,31 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// Enable context action bar behaviour // Enable context action bar behaviour
getListView().setOnItemLongClickListener(new OnItemLongClickListener() { getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) { int position, long id) {
// is already in selection mode we ignore the next ones // is already in selection mode we ignore the next ones
if (mSelectedContextAccount != null) { if (mSelectedContextAccount != null) {
return false; return false;
} }
mSelectedContextAccount = mAdapter.getItem(position); mSelectedContextAccount = mAdapter.getItem(position);
// we only handle real accounts this way // we only handle real accounts this way
if (mSelectedContextAccount instanceof SearchAccount) { if (mSelectedContextAccount instanceof SearchAccount) {
mSelectedContextAccount = null; mSelectedContextAccount = null;
return false; return false;
} }
mSelectedContextAccount = mAdapter.getItem(position); mSelectedContextAccount = mAdapter.getItem(position);
mActionMode = Accounts.this.startActionMode(mActionModeCallback); mActionMode = Accounts.this.startActionMode(mActionModeCallback);
mActionMode.invalidate(); mActionMode.invalidate();
mActionMode.setTitle(String.format(getString(R.string.actionbar_string_selected), mActionMode.setTitle(String.format(getString(R.string.actionbar_string_selected),
mSelectedContextAccount.getDescription())); mSelectedContextAccount.getDescription()));
return true; return true;
} }
}); });
if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) { if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) {
String accountUuid = icicle.getString("selectedContextAccount"); String accountUuid = icicle.getString("selectedContextAccount");
@ -441,15 +441,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} }
private void initializeActionBar() { private void initializeActionBar() {
mActionBar.setDisplayShowCustomEnabled(true); mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setCustomView(R.layout.actionbar_custom); mActionBar.setCustomView(R.layout.actionbar_custom);
View customView = mActionBar.getCustomView(); View customView = mActionBar.getCustomView();
mActionBarTitle = (TextView) customView.findViewById(R.id.actionbar_title_first); mActionBarTitle = (TextView) customView.findViewById(R.id.actionbar_title_first);
mActionBarSubTitle = (TextView) customView.findViewById(R.id.actionbar_title_sub); mActionBarSubTitle = (TextView) customView.findViewById(R.id.actionbar_title_sub);
mActionBarUnread = (TextView) customView.findViewById(R.id.actionbar_unread_count); mActionBarUnread = (TextView) customView.findViewById(R.id.actionbar_unread_count);
mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setDisplayHomeAsUpEnabled(true);
} }
/** /**
@ -545,8 +545,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// see if we should show the welcome message // see if we should show the welcome message
if (accounts.length < 1) { if (accounts.length < 1) {
WelcomeMessage.showWelcomeMessage(this); WelcomeMessage.showWelcomeMessage(this);
finish(); finish();
} }
List<BaseAccount> newAccounts; List<BaseAccount> newAccounts;
@ -646,10 +646,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
* @return false if unsuccessfull * @return false if unsuccessfull
*/ */
private boolean onOpenAccount(BaseAccount account) { private boolean onOpenAccount(BaseAccount account) {
// if we are still in a selection finish it // if we are still in a selection finish it
if (mSelectedContextAccount != null) { if (mSelectedContextAccount != null) {
mActionMode.finish(); mActionMode.finish();
} }
if (account instanceof SearchAccount) { if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount)account; SearchAccount searchAccount = (SearchAccount)account;
@ -781,7 +781,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
String outgoingPassword = null; String outgoingPassword = null;
if (mOutgoingPasswordView != null) { if (mOutgoingPasswordView != null) {
outgoingPassword = (mUseIncomingView.isChecked()) ? outgoingPassword = (mUseIncomingView.isChecked()) ?
incomingPassword : mOutgoingPasswordView.getText().toString(); incomingPassword : mOutgoingPasswordView.getText().toString();
} }
dialog.dismiss(); dialog.dismiss();
@ -805,21 +805,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// Use the dialog's layout inflater so its theme is used (and not the activity's theme). // Use the dialog's layout inflater so its theme is used (and not the activity's theme).
View layout = mDialog.getLayoutInflater().inflate( View layout = mDialog.getLayoutInflater().inflate(
R.layout.accounts_password_prompt, null); R.layout.accounts_password_prompt, null);
// Set the intro text that tells the user what to do // Set the intro text that tells the user what to do
TextView intro = (TextView) layout.findViewById(R.id.password_prompt_intro); TextView intro = (TextView) layout.findViewById(R.id.password_prompt_intro);
String serverPasswords = activity.getResources().getQuantityString( String serverPasswords = activity.getResources().getQuantityString(
R.plurals.settings_import_server_passwords, R.plurals.settings_import_server_passwords,
(configureOutgoingServer) ? 2 : 1); (configureOutgoingServer) ? 2 : 1);
intro.setText(activity.getString(R.string.settings_import_activate_account_intro, intro.setText(activity.getString(R.string.settings_import_activate_account_intro,
mAccount.getDescription(), serverPasswords)); mAccount.getDescription(), serverPasswords));
// Display the hostname of the incoming server // Display the hostname of the incoming server
TextView incomingText = (TextView) layout.findViewById( TextView incomingText = (TextView) layout.findViewById(
R.id.password_prompt_incoming_server); R.id.password_prompt_incoming_server);
incomingText.setText(activity.getString(R.string.settings_import_incoming_server, incomingText.setText(activity.getString(R.string.settings_import_incoming_server,
incoming.host)); incoming.host));
mIncomingPasswordView = (EditText) layout.findViewById(R.id.incoming_server_password); mIncomingPasswordView = (EditText) layout.findViewById(R.id.incoming_server_password);
mIncomingPasswordView.addTextChangedListener(this); mIncomingPasswordView.addTextChangedListener(this);
@ -827,16 +827,16 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
if (configureOutgoingServer) { if (configureOutgoingServer) {
// Display the hostname of the outgoing server // Display the hostname of the outgoing server
TextView outgoingText = (TextView) layout.findViewById( TextView outgoingText = (TextView) layout.findViewById(
R.id.password_prompt_outgoing_server); R.id.password_prompt_outgoing_server);
outgoingText.setText(activity.getString(R.string.settings_import_outgoing_server, outgoingText.setText(activity.getString(R.string.settings_import_outgoing_server,
outgoing.host)); outgoing.host));
mOutgoingPasswordView = (EditText) layout.findViewById( mOutgoingPasswordView = (EditText) layout.findViewById(
R.id.outgoing_server_password); R.id.outgoing_server_password);
mOutgoingPasswordView.addTextChangedListener(this); mOutgoingPasswordView.addTextChangedListener(this);
mUseIncomingView = (CheckBox) layout.findViewById( mUseIncomingView = (CheckBox) layout.findViewById(
R.id.use_incoming_server_password); R.id.use_incoming_server_password);
mUseIncomingView.setChecked(true); mUseIncomingView.setChecked(true);
mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() { mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
@ -887,7 +887,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// If the checkbox to use the incoming server password is checked we need to make // If the checkbox to use the incoming server password is checked we need to make
// sure that the password box for the outgoing server isn't empty. // sure that the password box for the outgoing server isn't empty.
else if (mUseIncomingView.isChecked() || else if (mUseIncomingView.isChecked() ||
mOutgoingPasswordView.getText().length() > 0) { mOutgoingPasswordView.getText().length() > 0) {
enable = true; enable = true;
} }
} }
@ -918,8 +918,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
private Application mApplication; private Application mApplication;
protected SetPasswordsAsyncTask(Activity activity, Account account, protected SetPasswordsAsyncTask(Activity activity, Account account,
String incomingPassword, String outgoingPassword, String incomingPassword, String outgoingPassword,
List<Account> remainingAccounts) { List<Account> remainingAccounts) {
super(activity); super(activity);
mAccount = account; mAccount = account;
mIncomingPassword = incomingPassword; mIncomingPassword = incomingPassword;
@ -933,7 +933,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
String title = mActivity.getString(R.string.settings_import_activate_account_header); String title = mActivity.getString(R.string.settings_import_activate_account_header);
int passwordCount = (mOutgoingPassword == null) ? 1 : 2; int passwordCount = (mOutgoingPassword == null) ? 1 : 2;
String message = mActivity.getResources().getQuantityString( String message = mActivity.getResources().getQuantityString(
R.plurals.settings_import_setting_passwords, passwordCount); R.plurals.settings_import_setting_passwords, passwordCount);
mProgressDialog = ProgressDialog.show(mActivity, title, message, true); mProgressDialog = ProgressDialog.show(mActivity, title, message, true);
} }
@ -999,101 +999,101 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// Android recreates our dialogs on configuration changes even when they have been // Android recreates our dialogs on configuration changes even when they have been
// dismissed. Make sure we have all information necessary before creating a new dialog. // dismissed. Make sure we have all information necessary before creating a new dialog.
switch (id) { switch (id) {
case DIALOG_REMOVE_ACCOUNT: { case DIALOG_REMOVE_ACCOUNT: {
if (mSelectedContextAccount == null) { if (mSelectedContextAccount == null) {
return null; return null;
} }
return ConfirmationDialog.create(this, id, return ConfirmationDialog.create(this, id,
R.string.account_delete_dlg_title, R.string.account_delete_dlg_title,
getString(R.string.account_delete_dlg_instructions_fmt, getString(R.string.account_delete_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()), mSelectedContextAccount.getDescription()),
R.string.okay_action, R.string.okay_action,
R.string.cancel_action, R.string.cancel_action,
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
if (mSelectedContextAccount instanceof Account) { if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount; Account realAccount = (Account) mSelectedContextAccount;
try { try {
realAccount.getLocalStore().delete(); realAccount.getLocalStore().delete();
} catch (Exception e) { } catch (Exception e) {
// Ignore, this may lead to localStores on sd-cards that // Ignore, this may lead to localStores on sd-cards that
// are currently not inserted to be left // are currently not inserted to be left
} }
MessagingController.getInstance(getApplication()) MessagingController.getInstance(getApplication())
.notifyAccountCancel(Accounts.this, realAccount); .notifyAccountCancel(Accounts.this, realAccount);
Preferences.getPreferences(Accounts.this) Preferences.getPreferences(Accounts.this)
.deleteAccount(realAccount); .deleteAccount(realAccount);
K9.setServicesEnabled(Accounts.this); K9.setServicesEnabled(Accounts.this);
refresh(); refresh();
} }
}
});
}
case DIALOG_CLEAR_ACCOUNT: {
if (mSelectedContextAccount == null) {
return null;
} }
});
return ConfirmationDialog.create(this, id, }
R.string.account_clear_dlg_title, case DIALOG_CLEAR_ACCOUNT: {
getString(R.string.account_clear_dlg_instructions_fmt, if (mSelectedContextAccount == null) {
mSelectedContextAccount.getDescription()), return null;
R.string.okay_action,
R.string.cancel_action,
new Runnable() {
@Override
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount,
R.string.clearing_account);
MessagingController.getInstance(getApplication())
.clear(realAccount, null);
}
}
});
} }
case DIALOG_RECREATE_ACCOUNT: {
if (mSelectedContextAccount == null) { return ConfirmationDialog.create(this, id,
return null; R.string.account_clear_dlg_title,
getString(R.string.account_clear_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()),
R.string.okay_action,
R.string.cancel_action,
new Runnable() {
@Override
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount,
R.string.clearing_account);
MessagingController.getInstance(getApplication())
.clear(realAccount, null);
}
} }
});
}
case DIALOG_RECREATE_ACCOUNT: {
if (mSelectedContextAccount == null) {
return null;
}
return ConfirmationDialog.create(this, id, return ConfirmationDialog.create(this, id,
R.string.account_recreate_dlg_title, R.string.account_recreate_dlg_title,
getString(R.string.account_recreate_dlg_instructions_fmt, getString(R.string.account_recreate_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()), mSelectedContextAccount.getDescription()),
R.string.okay_action, R.string.okay_action,
R.string.cancel_action, R.string.cancel_action,
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
if (mSelectedContextAccount instanceof Account) { if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount; Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount, mHandler.workingAccount(realAccount,
R.string.recreating_account); R.string.recreating_account);
MessagingController.getInstance(getApplication()) MessagingController.getInstance(getApplication())
.recreate(realAccount, null); .recreate(realAccount, null);
} }
} }
}); });
} }
case DIALOG_NO_FILE_MANAGER: { case DIALOG_NO_FILE_MANAGER: {
return ConfirmationDialog.create(this, id, return ConfirmationDialog.create(this, id,
R.string.import_dialog_error_title, R.string.import_dialog_error_title,
getString(R.string.import_dialog_error_message), getString(R.string.import_dialog_error_message),
R.string.open_market, R.string.open_market,
R.string.close, R.string.close,
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
Uri uri = Uri.parse(ANDROID_MARKET_URL); Uri uri = Uri.parse(ANDROID_MARKET_URL);
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent); startActivity(intent);
} }
}); });
} }
} }
return super.onCreateDialog(id); return super.onCreateDialog(id);
@ -1103,21 +1103,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
public void onPrepareDialog(int id, Dialog d) { public void onPrepareDialog(int id, Dialog d) {
AlertDialog alert = (AlertDialog) d; AlertDialog alert = (AlertDialog) d;
switch (id) { switch (id) {
case DIALOG_REMOVE_ACCOUNT: { case DIALOG_REMOVE_ACCOUNT: {
alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt, alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
mSelectedContextAccount.getDescription())); mSelectedContextAccount.getDescription()));
break; break;
} }
case DIALOG_CLEAR_ACCOUNT: { case DIALOG_CLEAR_ACCOUNT: {
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt, alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
mSelectedContextAccount.getDescription())); mSelectedContextAccount.getDescription()));
break; break;
} }
case DIALOG_RECREATE_ACCOUNT: { case DIALOG_RECREATE_ACCOUNT: {
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt, alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
mSelectedContextAccount.getDescription())); mSelectedContextAccount.getDescription()));
break; break;
} }
} }
super.onPrepareDialog(id, d); super.onPrepareDialog(id, d);
@ -1280,7 +1280,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
if (infos.size() > 0) { if (infos.size() > 0) {
startActivityForResult(Intent.createChooser(i, null), startActivityForResult(Intent.createChooser(i, null),
ACTIVITY_REQUEST_PICK_SETTINGS_FILE); ACTIVITY_REQUEST_PICK_SETTINGS_FILE);
} else { } else {
showDialog(DIALOG_NO_FILE_MANAGER); showDialog(DIALOG_NO_FILE_MANAGER);
} }
@ -1418,7 +1418,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
int imported = mImportResults.importedAccounts.size(); int imported = mImportResults.importedAccounts.size();
String accounts = activity.getResources().getQuantityString( String accounts = activity.getResources().getQuantityString(
R.plurals.settings_import_success, imported, imported); R.plurals.settings_import_success, imported, imported);
return activity.getString(R.string.settings_import_success, accounts, mFilename); return activity.getString(R.string.settings_import_success, accounts, mFilename);
} }
@ -1532,46 +1532,46 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
builder.setTitle(activity.getString(R.string.settings_import_selection)); builder.setTitle(activity.getString(R.string.settings_import_selection));
builder.setInverseBackgroundForced(true); builder.setInverseBackgroundForced(true);
builder.setPositiveButton(R.string.okay_action, builder.setPositiveButton(R.string.okay_action,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
ListView listView = ((AlertDialog) dialog).getListView(); ListView listView = ((AlertDialog) dialog).getListView();
SparseBooleanArray pos = listView.getCheckedItemPositions(); SparseBooleanArray pos = listView.getCheckedItemPositions();
boolean includeGlobals = mImportContents.globalSettings ? pos.get(0) : false; boolean includeGlobals = mImportContents.globalSettings ? pos.get(0) : false;
List<String> accountUuids = new ArrayList<String>(); List<String> accountUuids = new ArrayList<String>();
int start = mImportContents.globalSettings ? 1 : 0; int start = mImportContents.globalSettings ? 1 : 0;
for (int i = start, end = listView.getCount(); i < end; i++) { for (int i = start, end = listView.getCount(); i < end; i++) {
if (pos.get(i)) { if (pos.get(i)) {
accountUuids.add(mImportContents.accounts.get(i-start).uuid); accountUuids.add(mImportContents.accounts.get(i - start).uuid);
}
} }
/*
* TODO: Think some more about this. Overwriting could change the store
* type. This requires some additional code in order to work smoothly
* while the app is running.
*/
boolean overwrite = false;
dialog.dismiss();
activity.setNonConfigurationInstance(null);
ImportAsyncTask importAsyncTask = new ImportAsyncTask(activity,
includeGlobals, accountUuids, overwrite, mUri);
activity.setNonConfigurationInstance(importAsyncTask);
importAsyncTask.execute();
} }
});
/*
* TODO: Think some more about this. Overwriting could change the store
* type. This requires some additional code in order to work smoothly
* while the app is running.
*/
boolean overwrite = false;
dialog.dismiss();
activity.setNonConfigurationInstance(null);
ImportAsyncTask importAsyncTask = new ImportAsyncTask(activity,
includeGlobals, accountUuids, overwrite, mUri);
activity.setNonConfigurationInstance(importAsyncTask);
importAsyncTask.execute();
}
});
builder.setNegativeButton(R.string.cancel_action, builder.setNegativeButton(R.string.cancel_action,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
activity.setNonConfigurationInstance(null); activity.setNonConfigurationInstance(null);
} }
}); });
mDialog = builder.show(); mDialog = builder.show();
} }
} }
@ -1791,83 +1791,81 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
*/ */
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override @Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(mSelectedContextAccount); EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(mSelectedContextAccount);
if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) { if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
menu.findItem(R.id.move_up).setVisible(false); menu.findItem(R.id.move_up).setVisible(false);
} } else {
else {
menu.findItem(R.id.move_up).setVisible(true); menu.findItem(R.id.move_up).setVisible(true);
} }
if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) { if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
menu.findItem(R.id.move_down).setVisible(false); menu.findItem(R.id.move_down).setVisible(false);
} } else {
else {
menu.findItem(R.id.move_down).setVisible(true); menu.findItem(R.id.move_down).setVisible(true);
} }
return true; return true;
} }
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
mSelectedContextAccount = null; mSelectedContextAccount = null;
mActionMode = null; mActionMode = null;
} }
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater(); MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.accounts_context, menu); inflater.inflate(R.menu.accounts_context, menu);
return true; return true;
} }
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Account realAccount = (Account)mSelectedContextAccount; Account realAccount = (Account)mSelectedContextAccount;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.delete_account: case R.id.delete_account:
onDeleteAccount(realAccount); onDeleteAccount(realAccount);
break; break;
case R.id.edit_account: case R.id.edit_account:
onEditAccount(realAccount); onEditAccount(realAccount);
break; break;
case R.id.activate: case R.id.activate:
onActivateAccount(realAccount); onActivateAccount(realAccount);
break; break;
case R.id.check_mail: case R.id.check_mail:
onCheckMail(realAccount); onCheckMail(realAccount);
break; break;
case R.id.clear_pending: case R.id.clear_pending:
onClearCommands(realAccount); onClearCommands(realAccount);
break; break;
case R.id.empty_trash: case R.id.empty_trash:
onEmptyTrash(realAccount); onEmptyTrash(realAccount);
break; break;
case R.id.compact: case R.id.compact:
onCompact(realAccount); onCompact(realAccount);
break; break;
case R.id.clear: case R.id.clear:
onClear(realAccount); onClear(realAccount);
break; break;
case R.id.recreate: case R.id.recreate:
onRecreate(realAccount); onRecreate(realAccount);
break; break;
case R.id.export: case R.id.export:
onExport(false, realAccount); onExport(false, realAccount);
break; break;
case R.id.move_up: case R.id.move_up:
onMove(realAccount, true); onMove(realAccount, true);
break; break;
case R.id.move_down: case R.id.move_down:
onMove(realAccount, false); onMove(realAccount, false);
break; break;
} }
return true; return true;
} }
}; };
public void onExport(final boolean includeGlobals, final Account account) { public void onExport(final boolean includeGlobals, final Account account) {
@ -1893,7 +1891,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
private ExportAsyncTask(Accounts activity, boolean includeGlobals, private ExportAsyncTask(Accounts activity, boolean includeGlobals,
Set<String> accountUuids) { Set<String> accountUuids) {
super(activity); super(activity);
mIncludeGlobals = includeGlobals; mIncludeGlobals = includeGlobals;
mAccountUuids = accountUuids; mAccountUuids = accountUuids;
@ -1910,7 +1908,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
try { try {
mFileName = SettingsExporter.exportToFile(mContext, mIncludeGlobals, mFileName = SettingsExporter.exportToFile(mContext, mIncludeGlobals,
mAccountUuids); mAccountUuids);
} catch (SettingsImportExportException e) { } catch (SettingsImportExportException e) {
Log.w(K9.LOG_TAG, "Exception during export", e); Log.w(K9.LOG_TAG, "Exception during export", e);
return false; return false;
@ -1929,11 +1927,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
if (success) { if (success) {
activity.showSimpleDialog(R.string.settings_export_success_header, activity.showSimpleDialog(R.string.settings_export_success_header,
R.string.settings_export_success, mFileName); R.string.settings_export_success, mFileName);
} else { } else {
//TODO: better error messages //TODO: better error messages
activity.showSimpleDialog(R.string.settings_export_failed_header, activity.showSimpleDialog(R.string.settings_export_failed_header,
R.string.settings_export_failure); R.string.settings_export_failure);
} }
} }
} }
@ -1949,7 +1947,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
private ImportResults mImportResults; private ImportResults mImportResults;
private ImportAsyncTask(Accounts activity, boolean includeGlobals, private ImportAsyncTask(Accounts activity, boolean includeGlobals,
List<String> accountUuids, boolean overwrite, Uri uri) { List<String> accountUuids, boolean overwrite, Uri uri) {
super(activity); super(activity);
mIncludeGlobals = includeGlobals; mIncludeGlobals = includeGlobals;
mAccountUuids = accountUuids; mAccountUuids = accountUuids;
@ -1970,11 +1968,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
InputStream is = mContext.getContentResolver().openInputStream(mUri); InputStream is = mContext.getContentResolver().openInputStream(mUri);
try { try {
mImportResults = SettingsImporter.importSettings(mContext, is, mImportResults = SettingsImporter.importSettings(mContext, is,
mIncludeGlobals, mAccountUuids, mOverwrite); mIncludeGlobals, mAccountUuids, mOverwrite);
} finally { } finally {
try { try {
is.close(); is.close();
} catch (IOException e) { /* Ignore */ } } catch (IOException e) {
/* Ignore */
}
} }
} catch (SettingsImportExportException e) { } catch (SettingsImportExportException e) {
Log.w(K9.LOG_TAG, "Exception during import", e); Log.w(K9.LOG_TAG, "Exception during import", e);
@ -2004,7 +2004,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
if (success && (globalSettings || imported > 0)) { if (success && (globalSettings || imported > 0)) {
if (imported == 0) { if (imported == 0) {
activity.showSimpleDialog(R.string.settings_import_success_header, activity.showSimpleDialog(R.string.settings_import_success_header,
R.string.settings_import_global_settings_success, filename); R.string.settings_import_global_settings_success, filename);
} else { } else {
activity.showAccountsImportedDialog(mImportResults, filename); activity.showAccountsImportedDialog(mImportResults, filename);
} }
@ -2013,7 +2013,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} else { } else {
//TODO: better error messages //TODO: better error messages
activity.showSimpleDialog(R.string.settings_import_failed_header, activity.showSimpleDialog(R.string.settings_import_failed_header,
R.string.settings_import_failure, filename); R.string.settings_import_failure, filename);
} }
} }
} }
@ -2045,13 +2045,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} finally { } finally {
try { try {
is.close(); is.close();
} catch (IOException e) { /* Ignore */ } } catch (IOException e) {
/* Ignore */
}
} }
} catch (SettingsImportExportException e) { } catch (SettingsImportExportException e) {
Log.w(K9.LOG_TAG, "Exception during export", e); Log.w(K9.LOG_TAG, "Exception during export", e);
return false; return false;
} } catch (FileNotFoundException e) {
catch (FileNotFoundException e) {
Log.w(K9.LOG_TAG, "Couldn't read content from URI " + mUri); Log.w(K9.LOG_TAG, "Couldn't read content from URI " + mUri);
return false; return false;
} }
@ -2073,7 +2074,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
String filename = mUri.getLastPathSegment(); String filename = mUri.getLastPathSegment();
//TODO: better error messages //TODO: better error messages
activity.showSimpleDialog(R.string.settings_import_failed_header, activity.showSimpleDialog(R.string.settings_import_failed_header,
R.string.settings_import_failure, filename); R.string.settings_import_failure, filename);
} }
} }
} }