Auto-select if only one item in the list

If there is only one account and/or mailbox, automatically select it and
move onto the next step.

Change-Id: I716fbafb50ac6d59a17739a8d69c735d7733858b
This commit is contained in:
Todd Kennedy 2011-05-24 15:58:26 -07:00
parent 5675ea88d3
commit e2d227ffed

View File

@ -153,7 +153,6 @@ public abstract class ShortcutPickerFragment extends ListFragment
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
// Now, return the result to the launcher
myActivity.setResult(Activity.RESULT_OK, intent);
}
@ -172,17 +171,7 @@ public abstract class ShortcutPickerFragment extends ListFragment
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
Account account = new Account();
account.restore(cursor);
ShortcutPickerFragment fragment = new MailboxShortcutPickerFragment();
final Bundle args = new Bundle();
args.putParcelable(MailboxShortcutPickerFragment.ARG_ACCOUNT, account);
fragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.shortcut_list, fragment)
.addToBackStack(null)
.commit();
selectAccountCursor(cursor);
}
@Override
@ -193,10 +182,35 @@ public abstract class ShortcutPickerFragment extends ListFragment
context, Account.CONTENT_URI, Account.CONTENT_PROJECTION, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// if there is only one account, auto-select it
if (data.getCount() == 1 && data.moveToFirst()) {
selectAccountCursor(data);
return;
}
super.onLoadFinished(loader, data);
}
@Override
String[] getFromColumns() {
return ACCOUNT_FROM_COLUMNS;
}
/** Selects the account specified by the given cursor */
private void selectAccountCursor(Cursor cursor) {
Account account = new Account();
account.restore(cursor);
ShortcutPickerFragment fragment = new MailboxShortcutPickerFragment();
final Bundle args = new Bundle();
args.putParcelable(MailboxShortcutPickerFragment.ARG_ACCOUNT, account);
fragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.shortcut_list, fragment)
.addToBackStack(null)
.commit();
}
}
/** Mailbox picker */
@ -263,6 +277,18 @@ public abstract class ShortcutPickerFragment extends ListFragment
new String[] { Long.toString(mAccount.mId) }, orderBy);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// if there is only one mailbox, auto-select it
if (data.getCount() == 1 && data.moveToFirst()) {
long mailboxId = data.getLong(Mailbox.CONTENT_ID_COLUMN);
setupShortcut(mAccount, mailboxId);
getActivity().finish();
return;
}
super.onLoadFinished(loader, data);
}
@Override
String[] getFromColumns() {
return MAILBOX_FROM_COLUMNS;