Implement new dismissal behaviour of contextual card
Currently, if a contextual card gets dismissed, it will be gone forever. After this change, all cards being dismissed can be shown again after a certain amount of time(e.g one day). In order to calculate the amount of time, CARD_DISMISSED column is replaced with DISMISSED_TIMESTAMP. Once a card gets dismissed, a timestamp will be recorded for a corresponding card. In this change, some methods are moved from CardDatabaseHelper to ContextualCardFeatureProvider. So OEMs could replace the providers with their own ones to get cards and have different dismissal behaviours. Bug: 143055685 Test: rototests Change-Id: I00ace98991cabcbfcae4fc47a44e9448683d680c
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
|
||||
package com.android.settings.homepage.contextualcards;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
@@ -31,7 +29,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
public class CardDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String TAG = "CardDatabaseHelper";
|
||||
private static final String DATABASE_NAME = "homepage_cards.db";
|
||||
private static final int DATABASE_VERSION = 6;
|
||||
private static final int DATABASE_VERSION = 7;
|
||||
|
||||
public static final String CARD_TABLE = "cards";
|
||||
|
||||
@@ -72,31 +70,32 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
||||
String APP_VERSION = "app_version";
|
||||
|
||||
/**
|
||||
* Decide the card is dismissed or not.
|
||||
* Timestamp of card being dismissed.
|
||||
*/
|
||||
String CARD_DISMISSED = "card_dismissed";
|
||||
String DISMISSED_TIMESTAMP = "dismissed_timestamp";
|
||||
}
|
||||
|
||||
private static final String CREATE_CARD_TABLE =
|
||||
"CREATE TABLE " + CARD_TABLE +
|
||||
"(" +
|
||||
CardColumns.NAME +
|
||||
" TEXT NOT NULL PRIMARY KEY, " +
|
||||
CardColumns.TYPE +
|
||||
" INTEGER NOT NULL, " +
|
||||
CardColumns.SCORE +
|
||||
" DOUBLE NOT NULL, " +
|
||||
CardColumns.SLICE_URI +
|
||||
" TEXT, " +
|
||||
CardColumns.CATEGORY +
|
||||
" INTEGER DEFAULT 0, " +
|
||||
CardColumns.PACKAGE_NAME +
|
||||
" TEXT NOT NULL, " +
|
||||
CardColumns.APP_VERSION +
|
||||
" INTEGER NOT NULL, " +
|
||||
CardColumns.CARD_DISMISSED +
|
||||
" INTEGER DEFAULT 0 " +
|
||||
");";
|
||||
"CREATE TABLE "
|
||||
+ CARD_TABLE
|
||||
+ "("
|
||||
+ CardColumns.NAME
|
||||
+ " TEXT NOT NULL PRIMARY KEY, "
|
||||
+ CardColumns.TYPE
|
||||
+ " INTEGER NOT NULL, "
|
||||
+ CardColumns.SCORE
|
||||
+ " DOUBLE NOT NULL, "
|
||||
+ CardColumns.SLICE_URI
|
||||
+ " TEXT, "
|
||||
+ CardColumns.CATEGORY
|
||||
+ " INTEGER DEFAULT 0, "
|
||||
+ CardColumns.PACKAGE_NAME
|
||||
+ " TEXT NOT NULL, "
|
||||
+ CardColumns.APP_VERSION
|
||||
+ " INTEGER NOT NULL, "
|
||||
+ CardColumns.DISMISSED_TIMESTAMP
|
||||
+ " INTEGER"
|
||||
+ ");";
|
||||
|
||||
public CardDatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
@@ -125,32 +124,4 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
return sCardDatabaseHelper;
|
||||
}
|
||||
|
||||
Cursor getContextualCards() {
|
||||
final SQLiteDatabase db = getReadableDatabase();
|
||||
final String selection = CardColumns.CARD_DISMISSED + "=0";
|
||||
return db.query(CARD_TABLE, null /* columns */, selection,
|
||||
null /* selectionArgs */, null /* groupBy */, null /* having */,
|
||||
CardColumns.SCORE + " DESC" /* orderBy */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a specific ContextualCard with dismissal flag in the database to indicate that the
|
||||
* card has been dismissed.
|
||||
*
|
||||
* @param context Context
|
||||
* @param cardName The card name of the ContextualCard which is dismissed by user.
|
||||
* @return The number of rows updated
|
||||
*/
|
||||
public int markContextualCardAsDismissed(Context context, String cardName) {
|
||||
final SQLiteDatabase database = 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);
|
||||
database.close();
|
||||
context.getContentResolver().notifyChange(CardContentProvider.DELETE_CARD_URI, null);
|
||||
return rowsUpdated;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user