Merge "Auto-select if only one item in the list"

This commit is contained in:
Todd Kennedy 2011-05-25 08:43:04 -07:00 committed by Android (Google) Code Review
commit d7db0a5f6b

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;