mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
Compare commits
No commits in common. "5acfe9be68c1b0585248d0f1f0ab307e357214f4" and "c53e7897624a14a374b127bc2ccd10abcde3b049" have entirely different histories.
5acfe9be68
...
c53e789762
@ -27,15 +27,6 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio
|
|||||||
return Coroutine.async(scope, context, start, executeContext, block)
|
return Coroutine.async(scope, context, start, executeContext, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> executeLazy(
|
|
||||||
scope: CoroutineScope = viewModelScope,
|
|
||||||
context: CoroutineContext = Dispatchers.IO,
|
|
||||||
executeContext: CoroutineContext = Dispatchers.Main,
|
|
||||||
block: suspend CoroutineScope.() -> T
|
|
||||||
): Coroutine<T> {
|
|
||||||
return Coroutine.async(scope, context, CoroutineStart.LAZY, executeContext, block)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <R> submit(
|
fun <R> submit(
|
||||||
scope: CoroutineScope = viewModelScope,
|
scope: CoroutineScope = viewModelScope,
|
||||||
context: CoroutineContext = Dispatchers.IO,
|
context: CoroutineContext = Dispatchers.IO,
|
||||||
|
@ -188,7 +188,6 @@ class ContentProcessor private constructor(
|
|||||||
mContent = mContent.replace('\u00A0', ' ')
|
mContent = mContent.replace('\u00A0', ' ')
|
||||||
}
|
}
|
||||||
val contents = arrayListOf<String>()
|
val contents = arrayListOf<String>()
|
||||||
val paragraphIndent = ReadBookConfig.paragraphIndent
|
|
||||||
mContent.split("\n").forEach { str ->
|
mContent.split("\n").forEach { str ->
|
||||||
val paragraph = str.trim {
|
val paragraph = str.trim {
|
||||||
it.code <= 0x20 || it == ' '
|
it.code <= 0x20 || it == ' '
|
||||||
@ -197,14 +196,10 @@ class ContentProcessor private constructor(
|
|||||||
if (contents.isEmpty() && includeTitle) {
|
if (contents.isEmpty() && includeTitle) {
|
||||||
contents.add(paragraph)
|
contents.add(paragraph)
|
||||||
} else {
|
} else {
|
||||||
contents.add("$paragraphIndent$paragraph")
|
contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contents.isEmpty()) {
|
|
||||||
contents.add("${paragraphIndent}加载正文失败")
|
|
||||||
contents.add("${paragraphIndent}内容处理后为空")
|
|
||||||
}
|
|
||||||
return BookContent(sameTitleRemoved, contents, effectiveReplaceRules)
|
return BookContent(sameTitleRemoved, contents, effectiveReplaceRules)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,11 +170,7 @@ class RemoteBookActivity : BaseImportBookActivity<RemoteBookViewModel>(),
|
|||||||
|
|
||||||
private fun upPath() {
|
private fun upPath() {
|
||||||
binding.tvGoBack.isEnabled = viewModel.dirList.isNotEmpty()
|
binding.tvGoBack.isEnabled = viewModel.dirList.isNotEmpty()
|
||||||
var path = if (viewModel.isDefaultWebdav) {
|
var path = "books" + File.separator
|
||||||
"books" + File.separator
|
|
||||||
} else {
|
|
||||||
File.separator
|
|
||||||
}
|
|
||||||
viewModel.dirList.forEach {
|
viewModel.dirList.forEach {
|
||||||
path = path + it.filename + File.separator
|
path = path + it.filename + File.separator
|
||||||
}
|
}
|
||||||
|
@ -90,17 +90,14 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}.flowOn(Dispatchers.IO)
|
}.flowOn(Dispatchers.IO)
|
||||||
|
|
||||||
private var remoteBookWebDav: RemoteBookWebDav? = null
|
private var remoteBookWebDav: RemoteBookWebDav? = null
|
||||||
var isDefaultWebdav = false
|
|
||||||
|
|
||||||
fun initData(onSuccess: () -> Unit) {
|
fun initData(onSuccess: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
isDefaultWebdav = false
|
|
||||||
appDb.serverDao.get(AppConfig.remoteServerId)?.getWebDavConfig()?.let {
|
appDb.serverDao.get(AppConfig.remoteServerId)?.getWebDavConfig()?.let {
|
||||||
val authorization = Authorization(it)
|
val authorization = Authorization(it)
|
||||||
remoteBookWebDav = RemoteBookWebDav(it.url, authorization, AppConfig.remoteServerId)
|
remoteBookWebDav = RemoteBookWebDav(it.url, authorization, AppConfig.remoteServerId)
|
||||||
return@execute
|
return@execute
|
||||||
}
|
}
|
||||||
isDefaultWebdav = true
|
|
||||||
remoteBookWebDav = AppWebDav.defaultBookWebDav
|
remoteBookWebDav = AppWebDav.defaultBookWebDav
|
||||||
?: throw NoStackTraceException("webDav没有配置")
|
?: throw NoStackTraceException("webDav没有配置")
|
||||||
}.onError {
|
}.onError {
|
||||||
@ -111,7 +108,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun loadRemoteBookList(path: String?, loadCallback: (loading: Boolean) -> Unit) {
|
fun loadRemoteBookList(path: String?, loadCallback: (loading: Boolean) -> Unit) {
|
||||||
executeLazy {
|
execute {
|
||||||
val bookWebDav = remoteBookWebDav
|
val bookWebDav = remoteBookWebDav
|
||||||
?: throw NoStackTraceException("没有配置webDav")
|
?: throw NoStackTraceException("没有配置webDav")
|
||||||
dataCallback?.clear()
|
dataCallback?.clear()
|
||||||
@ -125,7 +122,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
loadCallback.invoke(true)
|
loadCallback.invoke(true)
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
loadCallback.invoke(false)
|
loadCallback.invoke(false)
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addToBookshelf(remoteBooks: HashSet<RemoteBook>, finally: () -> Unit) {
|
fun addToBookshelf(remoteBooks: HashSet<RemoteBook>, finally: () -> Unit) {
|
||||||
|
@ -154,8 +154,8 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
|||||||
*/
|
*/
|
||||||
private fun calcNextPageOffset(): Int {
|
private fun calcNextPageOffset(): Int {
|
||||||
val visibleHeight = ChapterProvider.visibleHeight
|
val visibleHeight = ChapterProvider.visibleHeight
|
||||||
val book = ReadBook.book
|
val book = ReadBook.book!!
|
||||||
if (book == null || book.isImage) {
|
if (book.isImage) {
|
||||||
return -visibleHeight
|
return -visibleHeight
|
||||||
}
|
}
|
||||||
val visiblePage = readView.getCurVisiblePage()
|
val visiblePage = readView.getCurVisiblePage()
|
||||||
@ -170,8 +170,8 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
|||||||
|
|
||||||
private fun calcPrevPageOffset(): Int {
|
private fun calcPrevPageOffset(): Int {
|
||||||
val visibleHeight = ChapterProvider.visibleHeight
|
val visibleHeight = ChapterProvider.visibleHeight
|
||||||
val book = ReadBook.book
|
val book = ReadBook.book!!
|
||||||
if (book == null || book.isImage) {
|
if (book.isImage) {
|
||||||
return visibleHeight
|
return visibleHeight
|
||||||
}
|
}
|
||||||
val visiblePage = readView.getCurVisiblePage()
|
val visiblePage = readView.getCurVisiblePage()
|
||||||
|
Loading…
Reference in New Issue
Block a user