parent
5a26f87a71
commit
21729149cc
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@ |
||||
package io.legado.app.constant |
||||
|
||||
import androidx.annotation.IntDef |
||||
|
||||
object BookSourceType { |
||||
|
||||
const val default = 0 // 0 文本 |
||||
const val audio = 1 // 1 音频 |
||||
const val image = 2 // 2 图片 |
||||
const val file = 3 // 3 只提供下载服务的网站 |
||||
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER) |
||||
@Retention(AnnotationRetention.SOURCE) |
||||
@IntDef(default, audio, image, file) |
||||
annotation class Type |
||||
|
||||
fun toBookType(sourceType: Int) { |
||||
when (sourceType) { |
||||
file -> BookType.text or BookType.webFile |
||||
image -> BookType.image |
||||
audio -> BookType.audio |
||||
else -> BookType.text |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,65 @@ |
||||
package io.legado.app.help |
||||
|
||||
import io.legado.app.constant.BookSourceType |
||||
import io.legado.app.constant.BookType |
||||
import io.legado.app.data.entities.Book |
||||
import io.legado.app.data.entities.BookSource |
||||
|
||||
|
||||
val Book.isAudio: Boolean |
||||
get() { |
||||
return type and BookType.audio > 0 |
||||
} |
||||
|
||||
val Book.isImage: Boolean |
||||
get() { |
||||
return type and BookType.image > 0 |
||||
} |
||||
|
||||
val Book.isLocal: Boolean |
||||
get() { |
||||
return type and BookType.local > 0 |
||||
} |
||||
|
||||
val Book.isLocalTxt: Boolean |
||||
get() { |
||||
return isLocal && originName.endsWith(".txt", true) |
||||
} |
||||
|
||||
val Book.isEpub: Boolean |
||||
get() { |
||||
return isLocal && originName.endsWith(".epub", true) |
||||
} |
||||
|
||||
val Book.isUmd: Boolean |
||||
get() { |
||||
return isLocal && originName.endsWith(".umd", true) |
||||
} |
||||
|
||||
val Book.isOnLineTxt: Boolean |
||||
get() { |
||||
return !isLocal && type and BookType.text > 0 |
||||
} |
||||
|
||||
fun Book.upType() { |
||||
if (type < 8) { |
||||
type = when (type) { |
||||
BookSourceType.image -> BookType.image |
||||
BookSourceType.audio -> BookType.audio |
||||
BookSourceType.file -> BookType.webFile |
||||
else -> BookType.text |
||||
} |
||||
if (origin == "loc_book" || origin.startsWith(BookType.webDavTag)) { |
||||
type = type or BookType.local |
||||
} |
||||
} |
||||
} |
||||
|
||||
fun BookSource.getBookType(): Int { |
||||
return when (bookSourceType) { |
||||
BookSourceType.file -> BookType.text or BookType.webFile |
||||
BookSourceType.image -> BookType.image |
||||
BookSourceType.audio -> BookType.audio |
||||
else -> BookType.text |
||||
} |
||||
} |
Loading…
Reference in new issue