This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d19c2af
commit 01470eb
Showing
17 changed files
with
318 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
r2-lcp/src/main/java/org/readium/r2/lcp/persistence/LcpDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.readium.r2.lcp.persistence | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface LcpDao { | ||
|
||
/** | ||
* Retrieve passphrase | ||
* @return Passphrase | ||
*/ | ||
@Query("SELECT ${Passphrase.PASSPHRASE} FROM ${Passphrase.TABLE_NAME} WHERE ${Passphrase.PROVIDER} = :licenseId") | ||
suspend fun passphrase(licenseId: String): String? | ||
|
||
@Query("SELECT ${Passphrase.PASSPHRASE} FROM ${Passphrase.TABLE_NAME} WHERE ${Passphrase.USERID} = :userId") | ||
suspend fun passphrases(userId: String): List<String> | ||
|
||
@Query("SELECT ${Passphrase.PASSPHRASE} FROM ${Passphrase.TABLE_NAME}") | ||
suspend fun allPassphrases(): List<String> | ||
|
||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
suspend fun addPassphrase(passphrase: Passphrase) | ||
|
||
@Query("SELECT ${License.LICENSE_ID} FROM ${License.TABLE_NAME} WHERE ${License.LICENSE_ID} = :licenseId") | ||
suspend fun exists(licenseId: String): String? | ||
|
||
@Query("SELECT ${License.REGISTERED} FROM ${License.TABLE_NAME} WHERE ${License.LICENSE_ID} = :licenseId") | ||
suspend fun isDeviceRegistered(licenseId: String): Boolean | ||
|
||
@Query("UPDATE ${License.TABLE_NAME} SET ${License.REGISTERED} = 1 WHERE ${License.LICENSE_ID} = :licenseId") | ||
suspend fun registerDevice(licenseId: String) | ||
|
||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
suspend fun addLicense(license: License) | ||
|
||
@Query("SELECT ${License.RIGHTCOPY} FROM ${License.TABLE_NAME} WHERE ${License.LICENSE_ID} = :licenseId") | ||
fun getCopiesLeft(licenseId: String): Int? | ||
|
||
@Query("UPDATE ${License.TABLE_NAME} SET ${License.RIGHTCOPY} = :quantity WHERE ${License.LICENSE_ID} = :licenseId") | ||
fun setCopiesLeft(quantity: Int, licenseId: String) | ||
|
||
@Query("SELECT ${License.RIGHTPRINT} FROM ${License.TABLE_NAME} WHERE ${License.LICENSE_ID} = :licenseId") | ||
fun getPrintsLeft(licenseId: String): Int? | ||
|
||
@Query("UPDATE ${License.TABLE_NAME} SET ${License.RIGHTPRINT} = :quantity WHERE ${License.LICENSE_ID} = :licenseId") | ||
fun setPrintsLeft(quantity: Int, licenseId: String) | ||
} |
40 changes: 40 additions & 0 deletions
40
r2-lcp/src/main/java/org/readium/r2/lcp/persistence/License.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Module: r2-lcp-kotlin | ||
* Developers: Aferdita Muriqi | ||
* | ||
* Copyright (c) 2019. Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license which is detailed in the | ||
* LICENSE file present in the project repository where this source code is maintained. | ||
*/ | ||
|
||
package org.readium.r2.lcp.persistence | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = License.TABLE_NAME) | ||
data class License( | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo(name = ID) | ||
var id: Long? = null, | ||
@ColumnInfo(name = LICENSE_ID) | ||
var licenseId: String, | ||
@ColumnInfo(name = RIGHTPRINT) | ||
val rightPrint: Int?, | ||
@ColumnInfo(name = RIGHTCOPY) | ||
val rightCopy: Int?, | ||
@ColumnInfo(name = REGISTERED, defaultValue = "0") | ||
val registered: Boolean = false | ||
) { | ||
|
||
companion object { | ||
|
||
const val TABLE_NAME = "licenses" | ||
const val LICENSE_ID = "license_id" | ||
const val ID = "id" | ||
const val RIGHTPRINT = "right_print" | ||
const val RIGHTCOPY = "right_copy" | ||
const val REGISTERED = "registered" | ||
} | ||
} |
Oops, something went wrong.