优化
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package io.legado.app.constant
|
package io.legado.app.constant
|
||||||
|
|
||||||
|
import androidx.annotation.IntDef
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以二进制位来区分,可能一本书籍包含多个类型,每一位代表一个类型,数值为2的n次方
|
* 以二进制位来区分,可能一本书籍包含多个类型,每一位代表一个类型,数值为2的n次方
|
||||||
* 以二进制位来区分,数据库查询更高效, 数值>=8和老版本类型区分开
|
* 以二进制位来区分,数据库查询更高效, 数值>=8和老版本类型区分开
|
||||||
@@ -35,6 +37,13 @@ object BookType {
|
|||||||
*/
|
*/
|
||||||
const val local = 0b100000000
|
const val local = 0b100000000
|
||||||
|
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
|
@IntDef(text, updateError, audio, image, webFile, local)
|
||||||
|
annotation class Type
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地书籍书源标志
|
* 本地书籍书源标志
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -86,18 +86,18 @@ fun Book.getRemoteUrl(): String? {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Book.setType(vararg types: Int) {
|
fun Book.setType(@BookType.Type vararg types: Int) {
|
||||||
type = 0
|
type = 0
|
||||||
addType(*types)
|
addType(*types)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Book.addType(vararg types: Int) {
|
fun Book.addType(@BookType.Type vararg types: Int) {
|
||||||
types.forEach {
|
types.forEach {
|
||||||
type = type or it
|
type = type or it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Book.removeType(vararg types: Int) {
|
fun Book.removeType(@BookType.Type vararg types: Int) {
|
||||||
types.forEach {
|
types.forEach {
|
||||||
type = type and it.inv()
|
type = type and it.inv()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user