Merge "Add a new column for slices_index table."
This commit is contained in:
committed by
Android (Google) Code Review
commit
c19f4f41ec
@@ -73,6 +73,8 @@ public class SliceData {
|
|||||||
|
|
||||||
private final String mUnavailableSliceSubtitle;
|
private final String mUnavailableSliceSubtitle;
|
||||||
|
|
||||||
|
private final boolean mIsPublicSlice;
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return mKey;
|
return mKey;
|
||||||
}
|
}
|
||||||
@@ -117,6 +119,10 @@ public class SliceData {
|
|||||||
return mUnavailableSliceSubtitle;
|
return mUnavailableSliceSubtitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPublicSlice() {
|
||||||
|
return mIsPublicSlice;
|
||||||
|
}
|
||||||
|
|
||||||
private SliceData(Builder builder) {
|
private SliceData(Builder builder) {
|
||||||
mKey = builder.mKey;
|
mKey = builder.mKey;
|
||||||
mTitle = builder.mTitle;
|
mTitle = builder.mTitle;
|
||||||
@@ -129,6 +135,7 @@ public class SliceData {
|
|||||||
mPreferenceController = builder.mPrefControllerClassName;
|
mPreferenceController = builder.mPrefControllerClassName;
|
||||||
mSliceType = builder.mSliceType;
|
mSliceType = builder.mSliceType;
|
||||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||||
|
mIsPublicSlice = builder.mIsPublicSlice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,6 +175,8 @@ public class SliceData {
|
|||||||
|
|
||||||
private String mUnavailableSliceSubtitle;
|
private String mUnavailableSliceSubtitle;
|
||||||
|
|
||||||
|
private boolean mIsPublicSlice;
|
||||||
|
|
||||||
public Builder setKey(String key) {
|
public Builder setKey(String key) {
|
||||||
mKey = key;
|
mKey = key;
|
||||||
return this;
|
return this;
|
||||||
@@ -224,6 +233,11 @@ public class SliceData {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setIsPublicSlice(boolean isPublicSlice) {
|
||||||
|
mIsPublicSlice = isPublicSlice;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public SliceData build() {
|
public SliceData build() {
|
||||||
if (TextUtils.isEmpty(mKey)) {
|
if (TextUtils.isEmpty(mKey)) {
|
||||||
throw new InvalidSliceDataException("Key cannot be empty");
|
throw new InvalidSliceDataException("Key cannot be empty");
|
||||||
|
@@ -212,6 +212,7 @@ class SliceDataConverter {
|
|||||||
final int sliceType = controller.getSliceType();
|
final int sliceType = controller.getSliceType();
|
||||||
final String unavailableSliceSubtitle = bundle.getString(
|
final String unavailableSliceSubtitle = bundle.getString(
|
||||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
final boolean isPublicSlice = controller.isPublicSlice();
|
||||||
|
|
||||||
final SliceData xmlSlice = new SliceData.Builder()
|
final SliceData xmlSlice = new SliceData.Builder()
|
||||||
.setKey(key)
|
.setKey(key)
|
||||||
@@ -224,6 +225,7 @@ class SliceDataConverter {
|
|||||||
.setFragmentName(fragmentName)
|
.setFragmentName(fragmentName)
|
||||||
.setSliceType(sliceType)
|
.setSliceType(sliceType)
|
||||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||||
|
.setIsPublicSlice(isPublicSlice)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
xmlSliceData.add(xmlSlice);
|
xmlSliceData.add(xmlSlice);
|
||||||
|
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
private static final String DATABASE_NAME = "slices_index.db";
|
private static final String DATABASE_NAME = "slices_index.db";
|
||||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
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 {
|
public interface Tables {
|
||||||
String TABLE_SLICES_INDEX = "slices_index";
|
String TABLE_SLICES_INDEX = "slices_index";
|
||||||
@@ -98,6 +98,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
* The uri of slice.
|
* The uri of slice.
|
||||||
*/
|
*/
|
||||||
String SLICE_URI = "slice_uri";
|
String SLICE_URI = "slice_uri";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the slice should be exposed publicly.
|
||||||
|
*/
|
||||||
|
String PUBLIC_SLICE = "public_slice";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String CREATE_SLICES_TABLE =
|
private static final String CREATE_SLICES_TABLE =
|
||||||
@@ -124,6 +129,12 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
IndexColumns.SLICE_TYPE +
|
IndexColumns.SLICE_TYPE +
|
||||||
", " +
|
", " +
|
||||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||||
|
", "
|
||||||
|
+
|
||||||
|
IndexColumns.PUBLIC_SLICE
|
||||||
|
+
|
||||||
|
" INTEGER DEFAULT 0 "
|
||||||
|
+
|
||||||
");";
|
");";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
@@ -112,6 +112,7 @@ class SlicesIndexer implements Runnable {
|
|||||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
dataRow.getUnavailableSliceSubtitle());
|
dataRow.getUnavailableSliceSubtitle());
|
||||||
|
values.put(IndexColumns.PUBLIC_SLICE, dataRow.isPublicSlice());
|
||||||
|
|
||||||
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
||||||
values);
|
values);
|
||||||
|
@@ -41,6 +41,11 @@ public class FakePreferenceController extends BasePreferenceController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPublicSlice() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean useDynamicSliceSummary() {
|
public boolean useDynamicSliceSummary() {
|
||||||
return true;
|
return true;
|
||||||
|
@@ -128,6 +128,7 @@ public class SliceDataConverterTest {
|
|||||||
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
||||||
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
||||||
"subtitleOfUnavailableSlice"); // from XML
|
"subtitleOfUnavailableSlice"); // from XML
|
||||||
|
assertThat(fakeSlice.isPublicSlice()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertFakeA11ySlice(SliceData fakeSlice) {
|
private void assertFakeA11ySlice(SliceData fakeSlice) {
|
||||||
|
@@ -52,7 +52,8 @@ public class SliceDataTest {
|
|||||||
.setUri(URI)
|
.setUri(URI)
|
||||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||||
.setSliceType(SLICE_TYPE)
|
.setSliceType(SLICE_TYPE)
|
||||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE)
|
||||||
|
.setIsPublicSlice(true);
|
||||||
|
|
||||||
SliceData data = builder.build();
|
SliceData data = builder.build();
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ public class SliceDataTest {
|
|||||||
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
||||||
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
||||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
assertThat(data.isPublicSlice()).isEqualTo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SliceData.InvalidSliceDataException.class)
|
@Test(expected = SliceData.InvalidSliceDataException.class)
|
||||||
|
@@ -75,6 +75,7 @@ public class SlicesDatabaseHelperTest {
|
|||||||
IndexColumns.CONTROLLER,
|
IndexColumns.CONTROLLER,
|
||||||
IndexColumns.SLICE_TYPE,
|
IndexColumns.SLICE_TYPE,
|
||||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
|
IndexColumns.PUBLIC_SLICE
|
||||||
};
|
};
|
||||||
|
|
||||||
assertThat(columnNames).isEqualTo(expectedNames);
|
assertThat(columnNames).isEqualTo(expectedNames);
|
||||||
|
@@ -105,8 +105,8 @@ public class SlicesIndexerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertSliceData_mockDataInserted() {
|
public void testInsertSliceData_nonPublicSlice_mockDataInserted() {
|
||||||
final List<SliceData> sliceData = getDummyIndexableData();
|
final List<SliceData> sliceData = getDummyIndexableData(false);
|
||||||
doReturn(sliceData).when(mManager).getSliceData();
|
doReturn(sliceData).when(mManager).getSliceData();
|
||||||
|
|
||||||
mManager.run();
|
mManager.run();
|
||||||
@@ -140,6 +140,53 @@ public class SlicesIndexerTest {
|
|||||||
assertThat(cursor.getString(
|
assertThat(cursor.getString(
|
||||||
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)))
|
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)))
|
||||||
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
assertThat(cursor.getInt(
|
||||||
|
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(0);
|
||||||
|
cursor.moveToNext();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insertSliceData_publicSlice_mockDataInserted() {
|
||||||
|
final List<SliceData> sliceData = getDummyIndexableData(true);
|
||||||
|
doReturn(sliceData).when(mManager).getSliceData();
|
||||||
|
|
||||||
|
mManager.run();
|
||||||
|
|
||||||
|
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||||
|
try (Cursor cursor = db.rawQuery("SELECT * FROM slices_index", null)) {
|
||||||
|
assertThat(cursor.getCount()).isEqualTo(sliceData.size());
|
||||||
|
|
||||||
|
cursor.moveToFirst();
|
||||||
|
for (int i = 0; i < sliceData.size(); i++) {
|
||||||
|
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.KEY)))
|
||||||
|
.isEqualTo(KEYS[i]);
|
||||||
|
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.TITLE)))
|
||||||
|
.isEqualTo(TITLES[i]);
|
||||||
|
assertThat(
|
||||||
|
cursor.getString(cursor.getColumnIndex(IndexColumns.FRAGMENT)))
|
||||||
|
.isEqualTo(FRAGMENT_NAME);
|
||||||
|
assertThat(cursor.getString(
|
||||||
|
cursor.getColumnIndex(IndexColumns.SCREENTITLE))).isEqualTo(SCREEN_TITLE);
|
||||||
|
assertThat(
|
||||||
|
cursor.getString(cursor.getColumnIndex(IndexColumns.KEYWORDS)))
|
||||||
|
.isEqualTo(KEYWORDS);
|
||||||
|
assertThat(
|
||||||
|
cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE)))
|
||||||
|
.isEqualTo(ICON);
|
||||||
|
assertThat(
|
||||||
|
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
||||||
|
.isEqualTo(PREF_CONTROLLER);
|
||||||
|
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
||||||
|
.isEqualTo(SLICE_TYPE);
|
||||||
|
assertThat(cursor.getString(
|
||||||
|
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)))
|
||||||
|
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
assertThat(cursor.getInt(
|
||||||
|
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(1);
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -162,7 +209,7 @@ public class SlicesIndexerTest {
|
|||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SliceData> getDummyIndexableData() {
|
private List<SliceData> getDummyIndexableData(boolean isPublicSlice) {
|
||||||
final List<SliceData> sliceData = new ArrayList<>();
|
final List<SliceData> sliceData = new ArrayList<>();
|
||||||
final SliceData.Builder builder = new SliceData.Builder()
|
final SliceData.Builder builder = new SliceData.Builder()
|
||||||
.setSummary(SUMMARY)
|
.setSummary(SUMMARY)
|
||||||
@@ -175,6 +222,10 @@ public class SlicesIndexerTest {
|
|||||||
.setSliceType(SLICE_TYPE)
|
.setSliceType(SLICE_TYPE)
|
||||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
|
||||||
|
if (isPublicSlice) {
|
||||||
|
builder.setIsPublicSlice(true);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < KEYS.length; i++) {
|
for (int i = 0; i < KEYS.length; i++) {
|
||||||
builder.setKey(KEYS[i]).setTitle(TITLES[i]);
|
builder.setKey(KEYS[i]).setTitle(TITLES[i]);
|
||||||
sliceData.add(builder.build());
|
sliceData.add(builder.build());
|
||||||
|
Reference in New Issue
Block a user