Added card_dismissed field into cards table
Added card_dismissed field to keep user dismissal behavior and filter it when cards loaded Bug: 113783548 Test: manual test Change-Id: I27549eca95c2e49fcc92fa59a5c02da73814a522
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.homepage.contextualcards;
|
package com.android.settings.homepage.contextualcards;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
@@ -30,7 +31,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
public class CardDatabaseHelper extends SQLiteOpenHelper {
|
public class CardDatabaseHelper extends SQLiteOpenHelper {
|
||||||
private static final String TAG = "CardDatabaseHelper";
|
private static final String TAG = "CardDatabaseHelper";
|
||||||
private static final String DATABASE_NAME = "homepage_cards.db";
|
private static final String DATABASE_NAME = "homepage_cards.db";
|
||||||
private static final int DATABASE_VERSION = 4;
|
private static final int DATABASE_VERSION = 5;
|
||||||
|
|
||||||
public static final String CARD_TABLE = "cards";
|
public static final String CARD_TABLE = "cards";
|
||||||
|
|
||||||
@@ -119,6 +120,11 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
* Decide the card display full-length width or half-width in screen.
|
* Decide the card display full-length width or half-width in screen.
|
||||||
*/
|
*/
|
||||||
String SUPPORT_HALF_WIDTH = "support_half_width";
|
String SUPPORT_HALF_WIDTH = "support_half_width";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decide the card is dismissed or not.
|
||||||
|
*/
|
||||||
|
String CARD_DISMISSED = "card_dismissed";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String CREATE_CARD_TABLE =
|
private static final String CREATE_CARD_TABLE =
|
||||||
@@ -157,6 +163,8 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
CardColumns.EXPIRE_TIME_MS +
|
CardColumns.EXPIRE_TIME_MS +
|
||||||
" INTEGER, " +
|
" INTEGER, " +
|
||||||
CardColumns.SUPPORT_HALF_WIDTH +
|
CardColumns.SUPPORT_HALF_WIDTH +
|
||||||
|
" INTEGER DEFAULT 0, " +
|
||||||
|
CardColumns.CARD_DISMISSED +
|
||||||
" INTEGER DEFAULT 0 " +
|
" INTEGER DEFAULT 0 " +
|
||||||
");";
|
");";
|
||||||
|
|
||||||
@@ -190,9 +198,27 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
Cursor getContextualCards() {
|
Cursor getContextualCards() {
|
||||||
final SQLiteDatabase db = this.getReadableDatabase();
|
final SQLiteDatabase db = this.getReadableDatabase();
|
||||||
Cursor cursor = db.query(CARD_TABLE, null /* columns */, null /* selection */,
|
final String selection = CardColumns.CARD_DISMISSED + "=0";
|
||||||
|
Cursor cursor = db.query(CARD_TABLE, null /* columns */, selection,
|
||||||
null /* selectionArgs */, null /* groupBy */, null /* having */,
|
null /* selectionArgs */, null /* groupBy */, null /* having */,
|
||||||
null /* orderBy */);
|
null /* orderBy */);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a specific ContextualCard with dismissal flag in the database to indicate that the
|
||||||
|
* card has been dismissed.
|
||||||
|
*
|
||||||
|
* @param cardName the card name of the ContextualCard which is dismissed by user.
|
||||||
|
* @return updated row number
|
||||||
|
*/
|
||||||
|
public int markContextualCardAsDismissed(String cardName) {
|
||||||
|
final SQLiteDatabase database = this.getWritableDatabase();
|
||||||
|
final ContentValues values = new ContentValues();
|
||||||
|
values.put(CardColumns.CARD_DISMISSED, 1);
|
||||||
|
final String selection = CardColumns.NAME + "=?";
|
||||||
|
final String[] selectionArgs = {cardName};
|
||||||
|
final int rowsUpdated = database.update(CARD_TABLE, values, selection, selectionArgs);
|
||||||
|
return rowsUpdated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -74,6 +74,7 @@ public class CardDatabaseHelperTest {
|
|||||||
CardDatabaseHelper.CardColumns.CARD_ACTION,
|
CardDatabaseHelper.CardColumns.CARD_ACTION,
|
||||||
CardDatabaseHelper.CardColumns.EXPIRE_TIME_MS,
|
CardDatabaseHelper.CardColumns.EXPIRE_TIME_MS,
|
||||||
CardDatabaseHelper.CardColumns.SUPPORT_HALF_WIDTH,
|
CardDatabaseHelper.CardColumns.SUPPORT_HALF_WIDTH,
|
||||||
|
CardDatabaseHelper.CardColumns.CARD_DISMISSED,
|
||||||
};
|
};
|
||||||
|
|
||||||
assertThat(columnNames).isEqualTo(expectedNames);
|
assertThat(columnNames).isEqualTo(expectedNames);
|
||||||
|
Reference in New Issue
Block a user