From 0ec80cddc3ace5d49df8ffa442158d3013691ae9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Oct 2022 21:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/BookType.kt | 9 +++++++++ .../main/java/io/legado/app/help/book/BookExtensions.kt | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/BookType.kt b/app/src/main/java/io/legado/app/constant/BookType.kt index 9b998d0e8..9eb8bbbb1 100644 --- a/app/src/main/java/io/legado/app/constant/BookType.kt +++ b/app/src/main/java/io/legado/app/constant/BookType.kt @@ -1,5 +1,7 @@ package io.legado.app.constant +import androidx.annotation.IntDef + /** * 以二进制位来区分,可能一本书籍包含多个类型,每一位代表一个类型,数值为2的n次方 * 以二进制位来区分,数据库查询更高效, 数值>=8和老版本类型区分开 @@ -35,6 +37,13 @@ object BookType { */ const val local = 0b100000000 + + @Target(AnnotationTarget.VALUE_PARAMETER) + @Retention(AnnotationRetention.SOURCE) + @IntDef(text, updateError, audio, image, webFile, local) + annotation class Type + + /** * 本地书籍书源标志 */ diff --git a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt index 179d09b35..42dc8f21b 100644 --- a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt +++ b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt @@ -86,18 +86,18 @@ fun Book.getRemoteUrl(): String? { return null } -fun Book.setType(vararg types: Int) { +fun Book.setType(@BookType.Type vararg types: Int) { type = 0 addType(*types) } -fun Book.addType(vararg types: Int) { +fun Book.addType(@BookType.Type vararg types: Int) { types.forEach { type = type or it } } -fun Book.removeType(vararg types: Int) { +fun Book.removeType(@BookType.Type vararg types: Int) { types.forEach { type = type and it.inv() }