Merge "Add new method to preference controller base for dynamic index."
This commit is contained in:
@@ -274,6 +274,14 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
|||||||
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates dynamic raw data for search provider.
|
||||||
|
*
|
||||||
|
* Called by SearchIndexProvider#getDynamicRawDataToIndex
|
||||||
|
*/
|
||||||
|
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set {@link UiBlockListener}
|
* Set {@link UiBlockListener}
|
||||||
*
|
*
|
||||||
@@ -308,4 +316,4 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
|||||||
*/
|
*/
|
||||||
public interface UiBlocker {
|
public interface UiBlocker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,8 @@ package com.android.settings.core;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -62,4 +62,12 @@ public interface PreferenceControllerMixin {
|
|||||||
*/
|
*/
|
||||||
default void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
default void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates dynamic raw data for search provider.
|
||||||
|
*
|
||||||
|
* Called by SearchIndexProvider#getDynamicRawDataToIndex
|
||||||
|
*/
|
||||||
|
default void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -77,8 +77,25 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@CallSuper
|
||||||
public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context, boolean enabled) {
|
public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context, boolean enabled) {
|
||||||
return null;
|
final List<SearchIndexableRaw> dynamicRaws = new ArrayList<>();
|
||||||
|
final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
||||||
|
if (controllers == null || controllers.isEmpty()) {
|
||||||
|
return dynamicRaws;
|
||||||
|
}
|
||||||
|
for (AbstractPreferenceController controller : controllers) {
|
||||||
|
if (controller instanceof PreferenceControllerMixin) {
|
||||||
|
((PreferenceControllerMixin) controller).updateDynamicRawDataToIndex(dynamicRaws);
|
||||||
|
} else if (controller instanceof BasePreferenceController) {
|
||||||
|
((BasePreferenceController) controller).updateDynamicRawDataToIndex(dynamicRaws);
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, controller.getClass().getName()
|
||||||
|
+ " must implement " + PreferenceControllerMixin.class.getName()
|
||||||
|
+ " treating the dynamic indexable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dynamicRaws;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -28,6 +28,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -77,6 +78,12 @@ public class BaseSearchIndexProviderTest {
|
|||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return TEST_PREF_KEY;
|
return TEST_PREF_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
final SearchIndexableRaw raw = new SearchIndexableRaw(this.mContext);
|
||||||
|
rawData.add(raw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -190,4 +197,18 @@ public class BaseSearchIndexProviderTest {
|
|||||||
|
|
||||||
assertThat(nonIndexableKeys).contains("pref_key_5");
|
assertThat(nonIndexableKeys).contains("pref_key_5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDynamicRawDataToIndex_noPreferenceController_shouldReturnEmptyList() {
|
||||||
|
assertThat(mIndexProvider.getDynamicRawDataToIndex(mContext, true)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDynamicRawDataToIndex_hasDynamicRaw_shouldNotEmpty() {
|
||||||
|
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new AvailablePreferenceController(mContext));
|
||||||
|
doReturn(controllers).when(mIndexProvider).createPreferenceControllers(mContext);
|
||||||
|
|
||||||
|
assertThat(mIndexProvider.getDynamicRawDataToIndex(mContext, true)).isNotEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user