Merge "Adding the ability to customize the subtitle on an unavailable slice"

This commit is contained in:
Console Chen
2019-01-11 03:07:50 +00:00
committed by Android (Google) Code Review
17 changed files with 256 additions and 31 deletions

View File

@@ -425,7 +425,10 @@ public class SliceBuilderUtils {
final String title = data.getTitle();
final Set<String> keywords = buildSliceKeywords(data);
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
final CharSequence summary = context.getText(R.string.disabled_dependent_setting_summary);
final String customSubtitle = data.getUnavailableSliceSubtitle();
final CharSequence subtitle = !TextUtils.isEmpty(customSubtitle) ? customSubtitle
: context.getText(R.string.disabled_dependent_setting_summary);
final IconCompat icon = getSafeIcon(context, data);
final SliceAction primaryAction = SliceAction.createDeeplink(
getContentPendingIntent(context, data),
@@ -436,7 +439,7 @@ public class SliceBuilderUtils {
.addRow(new RowBuilder()
.setTitle(title)
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
.setSubtitle(summary)
.setSubtitle(subtitle)
.setPrimaryAction(primaryAction))
.setKeywords(keywords)
.build();

View File

@@ -28,7 +28,6 @@ import java.lang.annotation.RetentionPolicy;
* Note that {@link #mKey} is treated as a primary key for this class and determines equality.
*/
public class SliceData {
/**
* Flags indicating the UI type of the Slice.
*/
@@ -76,6 +75,8 @@ public class SliceData {
private final boolean mIsDynamicSummaryAllowed;
private final String mUnavailableSliceSubtitle;
public String getKey() {
return mKey;
}
@@ -124,6 +125,10 @@ public class SliceData {
return mIsDynamicSummaryAllowed;
}
public String getUnavailableSliceSubtitle() {
return mUnavailableSliceSubtitle;
}
private SliceData(Builder builder) {
mKey = builder.mKey;
mTitle = builder.mTitle;
@@ -137,6 +142,7 @@ public class SliceData {
mSliceType = builder.mSliceType;
mIsPlatformDefined = builder.mIsPlatformDefined;
mIsDynamicSummaryAllowed = builder.mIsDynamicSummaryAllowed;
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
}
@Override
@@ -178,6 +184,8 @@ public class SliceData {
private boolean mIsDynamicSummaryAllowed;
private String mUnavailableSliceSubtitle;
public Builder setKey(String key) {
mKey = key;
return this;
@@ -238,6 +246,12 @@ public class SliceData {
return this;
}
public Builder setUnavailableSliceSubtitle(
String unavailableSliceSubtitle) {
mUnavailableSliceSubtitle = unavailableSliceSubtitle;
return this;
}
public SliceData build() {
if (TextUtils.isEmpty(mKey)) {
throw new InvalidSliceDataException("Key cannot be empty");

View File

@@ -16,12 +16,12 @@
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_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;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAILABLE_SLICE_SUBTITLE;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
@@ -189,7 +189,8 @@ 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_ALLOW_DYNAMIC_SUMMARY_IN_SLICE
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
for (Bundle bundle : metadata) {
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
@@ -208,6 +209,8 @@ class SliceDataConverter {
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);
final SliceData xmlSlice = new SliceData.Builder()
.setKey(key)
@@ -220,6 +223,7 @@ class SliceDataConverter {
.setSliceType(sliceType)
.setPlatformDefined(isPlatformSlice)
.setDynamicSummaryAllowed(isDynamicSummaryAllowed)
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
.build();
final BasePreferenceController controller =

View File

@@ -50,6 +50,7 @@ public class SlicesDatabaseAccessor {
IndexColumns.PLATFORM_SLICE,
IndexColumns.SLICE_TYPE,
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE,
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
};
// Cursor value for boolean true
@@ -167,6 +168,8 @@ public class SlicesDatabaseAccessor {
cursor.getColumnIndex(IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE)) == TRUE;
int sliceType = cursor.getInt(
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
final String unavailableSliceSubtitle = cursor.getString(
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE));
if (isIntentOnly) {
sliceType = SliceData.SliceType.INTENT;
@@ -185,6 +188,7 @@ public class SlicesDatabaseAccessor {
.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 = 3;
private static final int DATABASE_VERSION = 4;
public interface Tables {
String TABLE_SLICES_INDEX = "slices_index";
@@ -99,6 +99,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
* preference controller.
*/
String ALLOW_DYNAMIC_SUMMARY_IN_SLICE = "allow_dynamic_summary_in_slice";
/**
* Customized subtitle if it's a unavailable slice
*/
String UNAVAILABLE_SLICE_SUBTITLE = "unavailable_slice_subtitle";
}
private static final String CREATE_SLICES_TABLE =
@@ -125,6 +130,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
IndexColumns.SLICE_TYPE +
", " +
IndexColumns.ALLOW_DYNAMIC_SUMMARY_IN_SLICE +
", " +
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
");";
private final Context mContext;
@@ -151,7 +158,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < DATABASE_VERSION) {
Log.d(TAG, "Reconstructing DB from " + oldVersion + "to " + newVersion);
Log.d(TAG, "Reconstructing DB from " + oldVersion + " to " + newVersion);
reconstruct(db);
}
}

View File

@@ -113,6 +113,8 @@ class SlicesIndexer implements Runnable {
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());
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
values);