Convert xml based API allowDynamicSummaryInSlice to java

- Add boolean useDynamicSliceSummary() in Sliceable interface. This is
  the switch equivalent to android:allowDynamicSummaryInSlice in xml. It
  moves the setter closer to regular Sliceable APIs, thus less easily to
  miss.
- Coverted all android:allowDynamicSummaryInSlice to use the java API.
  - Except 2 prefs in my_device_info. They incorrectly set this to true
  previously (controller is not sliceable, no point setting
  dynamicSliceSummary to true. They just won't do anything)

Fixes: 128446156
Test: robolectric
Change-Id: Ic57acd590dec3e87dcf4592df137321d14b854d9
This commit is contained in:
Fan Zhang
2019-03-29 15:43:46 -07:00
parent 961f038c4d
commit b1b07e2030
38 changed files with 108 additions and 224 deletions

View File

@@ -188,8 +188,8 @@ public class SliceBuilderUtils {
* @return the summary text for a {@link Slice} built for {@param sliceData}.
*/
public static CharSequence getSubtitleText(Context context,
AbstractPreferenceController controller, SliceData sliceData) {
final boolean isDynamicSummaryAllowed = sliceData.isDynamicSummaryAllowed();
BasePreferenceController controller, SliceData sliceData) {
final boolean isDynamicSummaryAllowed = controller.useDynamicSliceSummary();
CharSequence summaryText = controller.getSummary();
// Priority 1 : User prefers showing the dynamic summary in slice view rather than static

View File

@@ -73,8 +73,6 @@ public class SliceData {
private final boolean mIsPlatformDefined;
private final boolean mIsDynamicSummaryAllowed;
private final String mUnavailableSliceSubtitle;
public String getKey() {
@@ -121,10 +119,6 @@ public class SliceData {
return mIsPlatformDefined;
}
public boolean isDynamicSummaryAllowed() {
return mIsDynamicSummaryAllowed;
}
public String getUnavailableSliceSubtitle() {
return mUnavailableSliceSubtitle;
}
@@ -141,7 +135,6 @@ public class SliceData {
mPreferenceController = builder.mPrefControllerClassName;
mSliceType = builder.mSliceType;
mIsPlatformDefined = builder.mIsPlatformDefined;
mIsDynamicSummaryAllowed = builder.mIsDynamicSummaryAllowed;
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
}
@@ -182,8 +175,6 @@ public class SliceData {
private boolean mIsPlatformDefined;
private boolean mIsDynamicSummaryAllowed;
private String mUnavailableSliceSubtitle;
public Builder setKey(String key) {
@@ -241,11 +232,6 @@ public class SliceData {
return this;
}
public Builder setDynamicSummaryAllowed(boolean isDynamicSummaryAllowed) {
mIsDynamicSummaryAllowed = isDynamicSummaryAllowed;
return this;
}
public Builder setUnavailableSliceSubtitle(
String unavailableSliceSubtitle) {
mUnavailableSliceSubtitle = unavailableSliceSubtitle;

View File

@@ -16,7 +16,6 @@
package com.android.settings.slices;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
@@ -189,7 +188,6 @@ class SliceDataConverter {
| MetadataFlag.FLAG_NEED_PREF_ICON
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG
| MetadataFlag.FLAG_ALLOW_DYNAMIC_SUMMARY_IN_SLICE
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
for (Bundle bundle : metadata) {
@@ -207,8 +205,6 @@ class SliceDataConverter {
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
key);
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
final boolean isDynamicSummaryAllowed = bundle.getBoolean(
METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE);
final String unavailableSliceSubtitle = bundle.getString(
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
@@ -222,7 +218,6 @@ class SliceDataConverter {
.setFragmentName(fragmentName)
.setSliceType(sliceType)
.setPlatformDefined(isPlatformSlice)
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
.build();

View File

@@ -78,6 +78,13 @@ public interface Sliceable {
return false;
}
/**
* Whether or not summary comes from something dynamic (ie, not hardcoded in xml)
*/
default boolean useDynamicSliceSummary() {
return false;
}
/**
* Set the copy content to the clipboard and show the toast.
*/

View File

@@ -49,7 +49,6 @@ public class SlicesDatabaseAccessor {
IndexColumns.CONTROLLER,
IndexColumns.PLATFORM_SLICE,
IndexColumns.SLICE_TYPE,
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
};
@@ -166,8 +165,6 @@ public class SlicesDatabaseAccessor {
cursor.getColumnIndex(IndexColumns.CONTROLLER));
final boolean isPlatformDefined = cursor.getInt(
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)) == TRUE;
final boolean isDynamicSummaryAllowed = cursor.getInt(
cursor.getColumnIndex(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE)) == TRUE;
int sliceType = cursor.getInt(
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
final String unavailableSliceSubtitle = cursor.getString(
@@ -189,7 +186,6 @@ public class SlicesDatabaseAccessor {
.setUri(uri)
.setPlatformDefined(isPlatformDefined)
.setSliceType(sliceType)
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
.build();
}

View File

@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "slices_index.db";
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
private static final int DATABASE_VERSION = 4;
private static final int DATABASE_VERSION = 5;
public interface Tables {
String TABLE_SLICES_INDEX = "slices_index";
@@ -94,12 +94,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
*/
String SLICE_TYPE = "slice_type";
/**
* Boolean flag, {@code true} when the slice object prefers using the dynamic summary from
* preference controller.
*/
String ALLOW_DYNAMIC_SUMMARY_IN_SLICE = "allow_dynamic_summary_in_slice";
/**
* Customized subtitle if it's a unavailable slice
*/
@@ -129,8 +123,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
", " +
IndexColumns.SLICE_TYPE +
", " +
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE +
", " +
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
");";

View File

@@ -110,8 +110,6 @@ class SlicesIndexer implements Runnable {
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
values.put(IndexColumns.PLATFORM_SLICE, dataRow.isPlatformDefined());
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
values.put(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
dataRow.isDynamicSummaryAllowed());
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
dataRow.getUnavailableSliceSubtitle());