Merge "Initial search bar implementation."
This commit is contained in:
committed by
Android (Google) Code Review
commit
fca1b78d94
@@ -22,9 +22,10 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
|||||||
LOCAL_STATIC_ANDROID_LIBRARIES := \
|
LOCAL_STATIC_ANDROID_LIBRARIES := \
|
||||||
android-support-v4 \
|
android-support-v4 \
|
||||||
android-support-v13 \
|
android-support-v13 \
|
||||||
android-support-v7-recyclerview \
|
|
||||||
android-support-v7-preference \
|
|
||||||
android-support-v7-appcompat \
|
android-support-v7-appcompat \
|
||||||
|
android-support-v7-cardview \
|
||||||
|
android-support-v7-preference \
|
||||||
|
android-support-v7-recyclerview \
|
||||||
android-support-v14-preference
|
android-support-v14-preference
|
||||||
|
|
||||||
LOCAL_JAVA_LIBRARIES := \
|
LOCAL_JAVA_LIBRARIES := \
|
||||||
|
25
res/layout/dashboard_header_spacer.xml
Normal file
25
res/layout/dashboard_header_spacer.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2017 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/search_bar_margin">
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?android:attr/actionBarSize"/>
|
||||||
|
</LinearLayout>
|
@@ -18,7 +18,31 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/main_content"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent">
|
||||||
/>
|
<FrameLayout
|
||||||
|
android:id="@+id/main_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_width="match_parent"/>
|
||||||
|
<android.support.v7.widget.CardView
|
||||||
|
android:id="@+id/search_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/search_bar_margin"
|
||||||
|
app:cardCornerRadius="2dp"
|
||||||
|
app:cardBackgroundColor="?android:attr/colorBackground"
|
||||||
|
app:cardElevation="2dp">
|
||||||
|
<Toolbar
|
||||||
|
android:id="@+id/search_action_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/search_bar_negative_margin"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:navigationIcon="@drawable/ic_search_24dp"
|
||||||
|
android:title="@string/search_menu"
|
||||||
|
android:titleTextAppearance="?android:attr/subtitleTextAppearance"
|
||||||
|
android:titleTextColor="?android:attr/textColorHint"
|
||||||
|
android:theme="?android:attr/actionBarTheme"/>
|
||||||
|
</android.support.v7.widget.CardView>
|
||||||
|
</FrameLayout>
|
||||||
|
@@ -139,6 +139,12 @@
|
|||||||
<dimen name="search_suggestion_item_image_margin_start">32dp</dimen>
|
<dimen name="search_suggestion_item_image_margin_start">32dp</dimen>
|
||||||
<dimen name="search_suggestion_item_image_margin_end">32dp</dimen>
|
<dimen name="search_suggestion_item_image_margin_end">32dp</dimen>
|
||||||
|
|
||||||
|
<!-- The following two margins need to match, with the caveat that
|
||||||
|
the second should be negative. The second one ensures that the icons and text
|
||||||
|
align despite the additional padding caused by the search bar's card background. -->
|
||||||
|
<dimen name="search_bar_margin">8dp</dimen>
|
||||||
|
<dimen name="search_bar_negative_margin">-8dp</dimen>
|
||||||
|
|
||||||
<!-- Dimensions for Wifi Assistant Card -->
|
<!-- Dimensions for Wifi Assistant Card -->
|
||||||
<dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
|
<dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
|
||||||
<dimen name="wifi_assistant_padding_start_end">16dp</dimen>
|
<dimen name="wifi_assistant_padding_start_end">16dp</dimen>
|
||||||
|
@@ -50,6 +50,7 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Toolbar;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.settings.Settings.WifiSettingsActivity;
|
import com.android.settings.Settings.WifiSettingsActivity;
|
||||||
@@ -62,6 +63,7 @@ import com.android.settings.dashboard.DashboardSummary;
|
|||||||
import com.android.settings.development.DevelopmentSettings;
|
import com.android.settings.development.DevelopmentSettings;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.DynamicIndexableContentMonitor;
|
import com.android.settings.search.DynamicIndexableContentMonitor;
|
||||||
|
import com.android.settings.search.SearchActivity;
|
||||||
import com.android.settings.search.SearchFeatureProvider;
|
import com.android.settings.search.SearchFeatureProvider;
|
||||||
import com.android.settings.wfd.WifiDisplaySettings;
|
import com.android.settings.wfd.WifiDisplaySettings;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
@@ -75,7 +77,7 @@ import java.util.Set;
|
|||||||
public class SettingsActivity extends SettingsDrawerActivity
|
public class SettingsActivity extends SettingsDrawerActivity
|
||||||
implements PreferenceManager.OnPreferenceTreeClickListener,
|
implements PreferenceManager.OnPreferenceTreeClickListener,
|
||||||
PreferenceFragment.OnPreferenceStartFragmentCallback,
|
PreferenceFragment.OnPreferenceStartFragmentCallback,
|
||||||
ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
|
ButtonBarHandler, FragmentManager.OnBackStackChangedListener, OnClickListener {
|
||||||
|
|
||||||
private static final String LOG_TAG = "Settings";
|
private static final String LOG_TAG = "Settings";
|
||||||
|
|
||||||
@@ -345,6 +347,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
launchSettingFragment(initialFragmentName, isSubSettings, intent);
|
launchSettingFragment(initialFragmentName, isSubSettings, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mIsShowingDashboard) {
|
||||||
|
findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
|
||||||
|
findViewById(R.id.action_bar).setVisibility(View.GONE);
|
||||||
|
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||||
|
toolbar.setOnClickListener(this);
|
||||||
|
setActionBar(toolbar);
|
||||||
|
}
|
||||||
|
|
||||||
mActionBar = getActionBar();
|
mActionBar = getActionBar();
|
||||||
if (mActionBar != null) {
|
if (mActionBar != null) {
|
||||||
mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
|
mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
|
||||||
@@ -432,10 +442,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
switchToFragment(initialFragmentName, initialArguments, true, false,
|
switchToFragment(initialFragmentName, initialArguments, true, false,
|
||||||
mInitialTitleResId, mInitialTitle, false);
|
mInitialTitleResId, mInitialTitle, false);
|
||||||
} else {
|
} else {
|
||||||
// No UP affordance if we are displaying the main Dashboard
|
// Show search icon as up affordance if we are displaying the main Dashboard
|
||||||
mDisplayHomeAsUpEnabled = false;
|
mDisplayHomeAsUpEnabled = true;
|
||||||
// Show Search affordance
|
// toolbar is search affordance so don't show search
|
||||||
mDisplaySearch = true;
|
mDisplaySearch = false;
|
||||||
mInitialTitleResId = R.string.dashboard_title;
|
mInitialTitleResId = R.string.dashboard_title;
|
||||||
|
|
||||||
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
|
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
|
||||||
@@ -939,4 +949,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.dashboard;
|
package com.android.settings.dashboard;
|
||||||
|
|
||||||
|
import android.annotation.AttrRes;
|
||||||
|
import android.annotation.ColorInt;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
@@ -54,6 +56,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
||||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||||
|
private static final int DONT_SET_BACKGROUND_ATTR = -1;
|
||||||
|
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -223,6 +226,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||||
final int type = mDashboardData.getItemTypeByPosition(position);
|
final int type = mDashboardData.getItemTypeByPosition(position);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case R.layout.dashboard_header_spacer:
|
||||||
|
onBindHeaderSpacer(holder, position);
|
||||||
|
break;
|
||||||
case R.layout.dashboard_category:
|
case R.layout.dashboard_category:
|
||||||
onBindCategory(holder,
|
onBindCategory(holder,
|
||||||
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
|
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
|
||||||
@@ -343,6 +349,33 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onBindHeaderSpacer(DashboardItemHolder holder, int position) {
|
||||||
|
if (mDashboardData.size() > (position + 1)) {
|
||||||
|
// The spacer that goes underneath the search bar needs to match the
|
||||||
|
// background of the first real view. That view is either a condition,
|
||||||
|
// a suggestion, or the dashboard item.
|
||||||
|
//
|
||||||
|
// If it's a dashboard item, set null background so it uses the parent's
|
||||||
|
// background like the other views. Otherwise, match the colors.
|
||||||
|
int nextType = mDashboardData.getItemTypeByPosition(position + 1);
|
||||||
|
int colorAttr = nextType == R.layout.suggestion_header
|
||||||
|
? android.R.attr.colorSecondary
|
||||||
|
: nextType == R.layout.condition_card
|
||||||
|
? android.R.attr.colorAccent
|
||||||
|
: DONT_SET_BACKGROUND_ATTR;
|
||||||
|
|
||||||
|
if (colorAttr != DONT_SET_BACKGROUND_ATTR) {
|
||||||
|
TypedArray array = holder.itemView.getContext()
|
||||||
|
.obtainStyledAttributes(new int[]{colorAttr});
|
||||||
|
@ColorInt int color = array.getColor(0, 0);
|
||||||
|
array.recycle();
|
||||||
|
holder.itemView.setBackgroundColor(color);
|
||||||
|
} else {
|
||||||
|
holder.itemView.setBackground(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
||||||
.SuggestionHeaderData data) {
|
.SuggestionHeaderData data) {
|
||||||
|
@@ -45,7 +45,8 @@ public class DashboardData {
|
|||||||
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
||||||
|
|
||||||
// id namespace for different type of items.
|
// id namespace for different type of items.
|
||||||
private static final int NS_SPACER = 0;
|
private static final int NS_HEADER_SPACER = 0;
|
||||||
|
private static final int NS_SPACER = 1000;
|
||||||
private static final int NS_ITEMS = 2000;
|
private static final int NS_ITEMS = 2000;
|
||||||
private static final int NS_CONDITION = 3000;
|
private static final int NS_CONDITION = 3000;
|
||||||
|
|
||||||
@@ -234,6 +235,9 @@ public class DashboardData {
|
|||||||
* and mIsShowingAll, mSuggestionMode flag.
|
* and mIsShowingAll, mSuggestionMode flag.
|
||||||
*/
|
*/
|
||||||
private void buildItemsData() {
|
private void buildItemsData() {
|
||||||
|
// add the view that goes under the search bar
|
||||||
|
countItem(null, R.layout.dashboard_header_spacer, true, NS_HEADER_SPACER);
|
||||||
|
resetCount();
|
||||||
boolean hasConditions = false;
|
boolean hasConditions = false;
|
||||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||||
boolean shouldShow = mConditions.get(i).shouldShow();
|
boolean shouldShow = mConditions.get(i).shouldShow();
|
||||||
|
@@ -51,13 +51,10 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
|||||||
String menuTitle = activity.getString(R.string.search_menu);
|
String menuTitle = activity.getString(R.string.search_menu);
|
||||||
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
|
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
|
||||||
.setIcon(R.drawable.ic_search_24dp)
|
.setIcon(R.drawable.ic_search_24dp)
|
||||||
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
.setOnMenuItemClickListener(item -> {
|
||||||
@Override
|
Intent intent = new Intent(activity, SearchActivity.class);
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
activity.startActivity(intent);
|
||||||
Intent intent = new Intent(activity, SearchActivity.class);
|
return true;
|
||||||
activity.startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
@@ -30,12 +30,14 @@ import android.app.Activity;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
|
||||||
|
import com.android.settings.search.SearchActivity;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -46,6 +48,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -140,4 +143,15 @@ public class SettingsActivityTest {
|
|||||||
|
|
||||||
assertThat(mActivity.mDisplaySearch).isTrue();
|
assertThat(mActivity.mDisplaySearch).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnClick() {
|
||||||
|
doReturn("com.android.settings").when(mActivity).getPackageName();
|
||||||
|
|
||||||
|
mActivity.onClick(null);
|
||||||
|
|
||||||
|
Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
|
||||||
|
assertThat(intent.getComponent()).isEqualTo(
|
||||||
|
new ComponentName("com.android.settings", SearchActivity.class.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,17 +24,19 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.robolectric.RuntimeEnvironment.application;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ import com.android.settings.dashboard.conditional.Condition;
|
|||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||||
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -58,6 +61,7 @@ import org.mockito.Captor;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -112,6 +116,53 @@ public class DashboardAdapterTest {
|
|||||||
when(mView.getTag()).thenReturn(mCondition);
|
when(mView.getTag()).thenReturn(mCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnBindViewHolder_spacer_noSuggestions_noConditions() {
|
||||||
|
makeCategory();
|
||||||
|
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
||||||
|
|
||||||
|
mDashboardAdapter.onBindViewHolder(holder, 0);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.getBackground()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnBindViewHolder_spacer_suggestion_noConditions() {
|
||||||
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
|
makeCategory();
|
||||||
|
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
||||||
|
|
||||||
|
mDashboardAdapter.onBindViewHolder(holder, 0);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.getBackground()).isNotNull();
|
||||||
|
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnBindViewHolder_spacer_noSuggestion_condition() {
|
||||||
|
makeCondition();
|
||||||
|
makeCategory();
|
||||||
|
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
||||||
|
|
||||||
|
mDashboardAdapter.onBindViewHolder(holder, 0);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.getBackground()).isNotNull();
|
||||||
|
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnBindViewHolder_spacer_suggestion_condition() {
|
||||||
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
|
makeCondition();
|
||||||
|
makeCategory();
|
||||||
|
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
||||||
|
|
||||||
|
mDashboardAdapter.onBindViewHolder(holder, 0);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.getBackground()).isNotNull();
|
||||||
|
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetConditions_AfterSetConditions_ExpandedConditionNull() {
|
public void testSetConditions_AfterSetConditions_ExpandedConditionNull() {
|
||||||
mDashboardAdapter.onExpandClick(mView);
|
mDashboardAdapter.onExpandClick(mView);
|
||||||
@@ -122,7 +173,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_NotExpanded() {
|
public void testSuggestionsLogs_NotExpanded() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
verify(mFactory.metricsFeatureProvider, times(2)).action(
|
verify(mFactory.metricsFeatureProvider, times(2)).action(
|
||||||
any(Context.class), mActionCategoryCaptor.capture(),
|
any(Context.class), mActionCategoryCaptor.capture(),
|
||||||
mActionPackageCaptor.capture());
|
mActionPackageCaptor.capture());
|
||||||
@@ -137,7 +188,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_NotExpandedAndPaused() {
|
public void testSuggestionsLogs_NotExpandedAndPaused() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
mDashboardAdapter.onPause();
|
mDashboardAdapter.onPause();
|
||||||
verify(mFactory.metricsFeatureProvider, times(4)).action(
|
verify(mFactory.metricsFeatureProvider, times(4)).action(
|
||||||
any(Context.class), mActionCategoryCaptor.capture(),
|
any(Context.class), mActionCategoryCaptor.capture(),
|
||||||
@@ -154,7 +205,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_Expanded() {
|
public void testSuggestionsLogs_Expanded() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
mSuggestionHolder.itemView.callOnClick();
|
mSuggestionHolder.itemView.callOnClick();
|
||||||
@@ -173,7 +224,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedAndPaused() {
|
public void testSuggestionsLogs_ExpandedAndPaused() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
mSuggestionHolder.itemView.callOnClick();
|
mSuggestionHolder.itemView.callOnClick();
|
||||||
@@ -196,7 +247,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedAfterPause() {
|
public void testSuggestionsLogs_ExpandedAfterPause() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
mDashboardAdapter.onPause();
|
mDashboardAdapter.onPause();
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
@@ -221,7 +272,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
|
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
mDashboardAdapter.onPause();
|
mDashboardAdapter.onPause();
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
@@ -250,7 +301,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
|
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1"));
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
mSuggestionHolder.itemView.callOnClick();
|
mSuggestionHolder.itemView.callOnClick();
|
||||||
@@ -267,7 +318,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
|
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1"));
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
mSuggestionHolder.itemView.callOnClick();
|
mSuggestionHolder.itemView.callOnClick();
|
||||||
@@ -286,7 +337,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
|
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1"));
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
mDashboardAdapter.onPause();
|
mDashboardAdapter.onPause();
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
@@ -306,7 +357,7 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPauseAndPausedAgain() {
|
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPauseAndPausedAgain() {
|
||||||
setUpSuggestions(makeSuggestions("pkg1"));
|
setupSuggestions(makeSuggestions("pkg1"));
|
||||||
mDashboardAdapter.onPause();
|
mDashboardAdapter.onPause();
|
||||||
mDashboardAdapter.onBindSuggestionHeader(
|
mDashboardAdapter.onBindSuggestionHeader(
|
||||||
mSuggestionHolder, mSuggestionHeaderData);
|
mSuggestionHolder, mSuggestionHeaderData);
|
||||||
@@ -330,15 +381,15 @@ public class DashboardAdapterTest {
|
|||||||
public void testBindViewHolder_inflateRemoteView() {
|
public void testBindViewHolder_inflateRemoteView() {
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
List<Tile> packages = makeSuggestions("pkg1");
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
RemoteViews remoteViews = mock(RemoteViews.class);
|
||||||
TextView textView = new TextView(application);
|
TextView textView = new TextView(RuntimeEnvironment.application);
|
||||||
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
||||||
packages.get(0).remoteViews = remoteViews;
|
packages.get(0).remoteViews = remoteViews;
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
||||||
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
|
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
|
||||||
new FrameLayout(application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
||||||
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
|
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
|
|
||||||
@@ -347,7 +398,8 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindViewHolder_primaryViewHandlesClick() {
|
public void testBindViewHolder_primaryViewHandlesClick() {
|
||||||
Context context = new ContextThemeWrapper(application, R.style.Theme_Settings);
|
Context context =
|
||||||
|
new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
|
||||||
|
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
List<Tile> packages = makeSuggestions("pkg1");
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
RemoteViews remoteViews = mock(RemoteViews.class);
|
||||||
@@ -362,7 +414,7 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(context),
|
new FrameLayout(context),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
||||||
|
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
|
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
|
||||||
@@ -375,7 +427,8 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindViewHolder_viewsClearedOnRebind() {
|
public void testBindViewHolder_viewsClearedOnRebind() {
|
||||||
Context context = new ContextThemeWrapper(application, R.style.Theme_Settings);
|
Context context =
|
||||||
|
new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
|
||||||
|
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
List<Tile> packages = makeSuggestions("pkg1");
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
RemoteViews remoteViews = mock(RemoteViews.class);
|
||||||
@@ -390,8 +443,8 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(context),
|
new FrameLayout(context),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
||||||
|
|
||||||
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
||||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
assertThat(itemView.getChildCount()).isEqualTo(1);
|
||||||
@@ -408,11 +461,31 @@ public class DashboardAdapterTest {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSuggestions(List<Tile> suggestions) {
|
private void setupSuggestions(List<Tile> suggestions) {
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||||
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
|
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
|
||||||
new FrameLayout(application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
mDashboardAdapter.getItemViewType(0));
|
mDashboardAdapter.getItemViewType(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void makeCondition() {
|
||||||
|
final List<Condition> conditions = new ArrayList<>();
|
||||||
|
Condition condition = mock(Condition.class);
|
||||||
|
when(condition.shouldShow()).thenReturn(true);
|
||||||
|
conditions.add(condition);
|
||||||
|
mDashboardAdapter.setConditions(conditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeCategory() {
|
||||||
|
List<DashboardCategory> categories = new ArrayList<>();
|
||||||
|
categories.add(new DashboardCategory());
|
||||||
|
mDashboardAdapter.setCategory(categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DashboardAdapter.DashboardItemHolder setupSpacer() {
|
||||||
|
Context context = RuntimeEnvironment.application;
|
||||||
|
final View view = LayoutInflater.from(context)
|
||||||
|
.inflate(R.layout.dashboard_header_spacer, new LinearLayout(context), false);
|
||||||
|
return new DashboardAdapter.DashboardItemHolder(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -112,7 +112,7 @@ public class DashboardDataTest {
|
|||||||
public void testBuildItemsData_containsAllData() {
|
public void testBuildItemsData_containsAllData() {
|
||||||
final DashboardData.SuggestionHeaderData data =
|
final DashboardData.SuggestionHeaderData data =
|
||||||
new DashboardData.SuggestionHeaderData(false, 1, 0);
|
new DashboardData.SuggestionHeaderData(false, 1, 0);
|
||||||
final Object[] expectedObjects = {mTestCondition, null, data, mTestSuggestion,
|
final Object[] expectedObjects = {null, mTestCondition, null, data, mTestSuggestion,
|
||||||
mDashboardCategory, mTestCategoryTile};
|
mDashboardCategory, mTestCategoryTile};
|
||||||
final int expectedSize = expectedObjects.length;
|
final int expectedSize = expectedObjects.length;
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ public class DashboardDataTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDiffUtil_DataEqual_noResultData() {
|
public void testDiffUtil_DataEqual_noResultData() {
|
||||||
List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||||
testDiffUtil(mDashboardDataWithOneConditions,
|
testDiffUtil(mDashboardDataWithOneConditions,
|
||||||
mDashboardDataWithOneConditions, testResultData);
|
mDashboardDataWithOneConditions, testResultData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ public class DashboardDataTest {
|
|||||||
//Build testResultData
|
//Build testResultData
|
||||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
testResultData.add(new ListUpdateResult.ResultData(
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_INSERT, 1, 1));
|
ListUpdateResult.ResultData.TYPE_OPERATION_INSERT, 2, 1));
|
||||||
|
|
||||||
testDiffUtil(mDashboardDataWithOneConditions,
|
testDiffUtil(mDashboardDataWithOneConditions,
|
||||||
mDashboardDataWithTwoConditions, testResultData);
|
mDashboardDataWithTwoConditions, testResultData);
|
||||||
@@ -191,7 +191,7 @@ public class DashboardDataTest {
|
|||||||
//Build testResultData
|
//Build testResultData
|
||||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
testResultData.add(new ListUpdateResult.ResultData(
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 6));
|
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 1, 6));
|
||||||
|
|
||||||
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
|
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
|
||||||
}
|
}
|
||||||
@@ -203,8 +203,8 @@ public class DashboardDataTest {
|
|||||||
mDashboardDataWithOneConditions.getItemList(),
|
mDashboardDataWithOneConditions.getItemList(),
|
||||||
mDashboardDataWithOneConditions.getItemList());
|
mDashboardDataWithOneConditions.getItemList());
|
||||||
|
|
||||||
// Item in position 0 is condition card, which payload should not be null
|
// Item in position 1 is condition card, which payload should not be null
|
||||||
assertThat(callback.getChangePayload(0, 0)).isNotEqualTo(null);
|
assertThat(callback.getChangePayload(1, 1)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -214,9 +214,9 @@ public class DashboardDataTest {
|
|||||||
mDashboardDataWithOneConditions.getItemList(),
|
mDashboardDataWithOneConditions.getItemList(),
|
||||||
mDashboardDataWithOneConditions.getItemList());
|
mDashboardDataWithOneConditions.getItemList());
|
||||||
|
|
||||||
// Only item in position 0 is condition card, so others' payload should be null
|
// Position 0 is spacer, 1 is condition card, so others' payload should be null
|
||||||
for (int i = 1; i < mDashboardDataWithOneConditions.getItemList().size(); i++) {
|
for (int i = 2; i < mDashboardDataWithOneConditions.getItemList().size(); i++) {
|
||||||
assertThat(callback.getChangePayload(i, i)).isEqualTo(null);
|
assertThat(callback.getChangePayload(i, i)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -356,6 +356,11 @@ public class DashboardDataTest {
|
|||||||
|
|
||||||
return arg2 - resultData.arg2;
|
return arg2 - resultData.arg2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "op:" + operation + ",arg1:" + arg1 + ",arg2:" + arg2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user