• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.photopicker.core.banners
18 
19 import androidx.room.Dao
20 import androidx.room.Entity
21 import androidx.room.Query
22 import androidx.room.Upsert
23 
24 /**
25  * A [PhotopickerDatabase] table related to the persisted state of an individual banner.
26  *
27  * This table uses a composite key of bannerId,uid to enforce uniqueness.
28  *
29  * @property bannerId The id of the banner the row is referring to.
30  * @property uid the UID of the app the row is referring to. Zero (0) is used for "all apps /
31  *   global"
32  * @property dismissed Whether the banner has been dismissed by the user.
33  */
34 @Entity(tableName = "banner_state", primaryKeys = ["bannerId", "uid"])
35 data class BannerState(
36     val bannerId: String,
37     val uid: Int,
38     val dismissed: Boolean,
39 )
40 
41 /** An interface to read and write rows from the [BannerState] table. */
42 @Dao
43 interface BannerStateDao {
44 
45     /**
46      * Read a row for a specific banner / app combination.
47      *
48      * @param bannerId the Id of the banner
49      * @param uid The UID of the app to check the state of this banner for. Zero(0) should be used
50      *   for "global".
51      * @return The row, if it exists. If it does not exist, null is returned instead.
52      */
53     @Query("SELECT * from banner_state WHERE bannerId=:bannerId AND uid = :uid")
getBannerStatenull54     fun getBannerState(bannerId: String, uid: Int): BannerState?
55 
56     /**
57      * Write a row for a specific [BannerState].
58      *
59      * This is an upsert method that will first try to insert the row, but will update the existing
60      * row on primary key conflict.
61      *
62      * @param bannerState The row to write to the database.
63      */
64     @Upsert fun setBannerState(bannerState: BannerState)
65 }
66