OSDN Git Service

Added card_dismissed field into cards table
authorSunny Shao <sunnyshao@google.com>
Tue, 6 Nov 2018 12:07:12 +0000 (20:07 +0800)
committerSunny Shao <sunnyshao@google.com>
Tue, 6 Nov 2018 12:59:46 +0000 (20:59 +0800)
Added card_dismissed field to keep user dismissal behavior and filter it when cards loaded

Bug: 113783548
Test: manual test
Change-Id: I27549eca95c2e49fcc92fa59a5c02da73814a522

src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
tests/robotests/src/com/android/settings/homepage/contextualcards/CardDatabaseHelperTest.java

index 647d718..0065f5c 100644 (file)
@@ -16,6 +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;
@@ -30,7 +31,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 = 4;
+    private static final int DATABASE_VERSION = 5;
 
     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.
          */
         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 =
@@ -157,6 +163,8 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
                     CardColumns.EXPIRE_TIME_MS +
                     " INTEGER, " +
                     CardColumns.SUPPORT_HALF_WIDTH +
+                    " INTEGER DEFAULT 0, " +
+                    CardColumns.CARD_DISMISSED +
                     " INTEGER DEFAULT 0 " +
                     ");";
 
@@ -190,9 +198,27 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
 
     Cursor getContextualCards() {
         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 /* orderBy */);
         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;
+    }
 }
index 4ef982f..b25508b 100644 (file)
@@ -74,6 +74,7 @@ public class CardDatabaseHelperTest {
                 CardDatabaseHelper.CardColumns.CARD_ACTION,
                 CardDatabaseHelper.CardColumns.EXPIRE_TIME_MS,
                 CardDatabaseHelper.CardColumns.SUPPORT_HALF_WIDTH,
+                CardDatabaseHelper.CardColumns.CARD_DISMISSED,
         };
 
         assertThat(columnNames).isEqualTo(expectedNames);