Merge "Add a new column for slices_index table."

This commit is contained in:
Yi-Ling Chuang
2019-11-20 05:44:04 +00:00
committed by Android (Google) Code Review
9 changed files with 93 additions and 5 deletions

View File

@@ -73,6 +73,8 @@ public class SliceData {
private final String mUnavailableSliceSubtitle;
private final boolean mIsPublicSlice;
public String getKey() {
return mKey;
}
@@ -117,6 +119,10 @@ public class SliceData {
return mUnavailableSliceSubtitle;
}
public boolean isPublicSlice() {
return mIsPublicSlice;
}
private SliceData(Builder builder) {
mKey = builder.mKey;
mTitle = builder.mTitle;
@@ -129,6 +135,7 @@ public class SliceData {
mPreferenceController = builder.mPrefControllerClassName;
mSliceType = builder.mSliceType;
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
mIsPublicSlice = builder.mIsPublicSlice;
}
@Override
@@ -168,6 +175,8 @@ public class SliceData {
private String mUnavailableSliceSubtitle;
private boolean mIsPublicSlice;
public Builder setKey(String key) {
mKey = key;
return this;
@@ -224,6 +233,11 @@ public class SliceData {
return this;
}
public Builder setIsPublicSlice(boolean isPublicSlice) {
mIsPublicSlice = isPublicSlice;
return this;
}
public SliceData build() {
if (TextUtils.isEmpty(mKey)) {
throw new InvalidSliceDataException("Key cannot be empty");

View File

@@ -212,6 +212,7 @@ class SliceDataConverter {
final int sliceType = controller.getSliceType();
final String unavailableSliceSubtitle = bundle.getString(
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
final boolean isPublicSlice = controller.isPublicSlice();
final SliceData xmlSlice = new SliceData.Builder()
.setKey(key)
@@ -224,6 +225,7 @@ class SliceDataConverter {
.setFragmentName(fragmentName)
.setSliceType(sliceType)
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
.setIsPublicSlice(isPublicSlice)
.build();
xmlSliceData.add(xmlSlice);

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 = 7;
private static final int DATABASE_VERSION = 8;
public interface Tables {
String TABLE_SLICES_INDEX = "slices_index";
@@ -98,6 +98,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
* The uri of slice.
*/
String SLICE_URI = "slice_uri";
/**
* Whether the slice should be exposed publicly.
*/
String PUBLIC_SLICE = "public_slice";
}
private static final String CREATE_SLICES_TABLE =
@@ -124,6 +129,12 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
IndexColumns.SLICE_TYPE +
", " +
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
", "
+
IndexColumns.PUBLIC_SLICE
+
" INTEGER DEFAULT 0 "
+
");";
private final Context mContext;

View File

@@ -112,6 +112,7 @@ class SlicesIndexer implements Runnable {
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
dataRow.getUnavailableSliceSubtitle());
values.put(IndexColumns.PUBLIC_SLICE, dataRow.isPublicSlice());
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
values);