Don't show account dropdown when there's only 1 account.

Bug 3225851

Change-Id: I7b411f8047e3b26cfe53f17c46c3e2611fb8ae9d
This commit is contained in:
Makoto Onuki 2010-11-23 17:21:46 -08:00
parent 5b81690de1
commit 08e1f2f782
2 changed files with 66 additions and 2 deletions

View File

@ -154,7 +154,7 @@ public class AccountSelectorAdapter extends CursorAdapter {
* - # of unread messages in inbox
* - The "Combined view" row if there's more than one account.
*/
private static class AccountsLoader extends ThrottlingCursorLoader {
/* package */ static class AccountsLoader extends ThrottlingCursorLoader {
private final Context mContext;
public AccountsLoader(Context context) {
@ -192,7 +192,7 @@ public class AccountSelectorAdapter extends CursorAdapter {
}
// Add "combined view"
final int countAccounts = resultCursor.getCount();
if (countAccounts > 0) {
if (countAccounts > 1) {
RowBuilder rb = resultCursor.newRow();
// Add ID, display name, # of accounts, total unread count.

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.activity;
import com.android.email.DBTestHelper;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailProvider;
import com.android.email.provider.ProviderTestUtils;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.test.LoaderTestCase;
/**
* Tests for {@link AccountSelectorAdapter.AccountsLoader}.
*
* TODO add more tests.
*/
public class AccountSelectorAdapterAccountsLoaderTest extends LoaderTestCase {
private Context mProviderContext;
@Override
protected void setUp() throws Exception {
super.setUp();
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
mContext, EmailProvider.class);
}
/**
* Confirm that AccountsLoader adds the combined view row, iif there is more than 1 account.
*/
public void testCombinedViewRow() {
final Account a1 = ProviderTestUtils.setupAccount("a1", true, mProviderContext);
{
// Only 1 account -- no combined view row.
Loader<Cursor> l = new AccountSelectorAdapter.AccountsLoader(mProviderContext);
Cursor result = getLoaderResultSynchronously(l);
assertEquals(1, result.getCount());
}
final Account a2 = ProviderTestUtils.setupAccount("a2", true, mProviderContext);
{
// 2 accounts -- with combined view row, so returns 3 rows.
Loader<Cursor> l = new AccountSelectorAdapter.AccountsLoader(mProviderContext);
Cursor result = getLoaderResultSynchronously(l);
assertEquals(3, result.getCount());
}
}
}