优化
This commit is contained in:
@@ -44,8 +44,19 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
|
||||
return@launch
|
||||
}
|
||||
initView()
|
||||
initData()
|
||||
initEvent()
|
||||
launch {
|
||||
viewModel.dataFlow.conflate().collect { sortedRemoteBooks ->
|
||||
binding.refreshProgressBar.isAutoLoading = false
|
||||
binding.tvEmptyMsg.isGone = sortedRemoteBooks.isNotEmpty()
|
||||
adapter.setItems(sortedRemoteBooks)
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
viewModel.initData {
|
||||
binding.refreshProgressBar.isAutoLoading = true
|
||||
upPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,19 +80,6 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
|
||||
}
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
binding.refreshProgressBar.isAutoLoading = true
|
||||
launch {
|
||||
viewModel.dataFlow.conflate().collect { sortedRemoteBooks ->
|
||||
binding.refreshProgressBar.isAutoLoading = false
|
||||
binding.tvEmptyMsg.isGone = sortedRemoteBooks.isNotEmpty()
|
||||
adapter.setItems(sortedRemoteBooks)
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
upPath()
|
||||
}
|
||||
|
||||
private fun initEvent() {
|
||||
binding.tvGoBack.setOnClickListener {
|
||||
goBackDir()
|
||||
|
||||
@@ -74,7 +74,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
private var remoteBookWebDav: RemoteBookWebDav? = null
|
||||
|
||||
init {
|
||||
fun initData(onSuccess: () -> Unit) {
|
||||
execute {
|
||||
val rootUrl = "${AppWebDav.rootWebDavUrl}books"
|
||||
val authorization = AppWebDav.authorization
|
||||
@@ -82,6 +82,8 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
remoteBookWebDav = RemoteBookWebDav(rootUrl, authorization)
|
||||
}.onError {
|
||||
context.toastOnUi("初始化webDav出错:${it.localizedMessage}")
|
||||
}.onSuccess {
|
||||
onSuccess.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user