kunfei 4 lat temu
rodzic
commit
592a22decc

+ 9 - 0
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
+
+
     /**
      * 本地书籍书源标志
      */

+ 3 - 3
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()
     }