|
|
@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.databinding.DialogAddToBookshelfBinding |
|
|
|
import io.legado.app.databinding.DialogAddToBookshelfBinding |
|
|
@ -54,6 +55,9 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe |
|
|
|
viewModel.loadStateLiveData.observe(this) { |
|
|
|
viewModel.loadStateLiveData.observe(this) { |
|
|
|
//todo |
|
|
|
//todo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
viewModel.loadErrorLiveData.observe(this) { |
|
|
|
|
|
|
|
//todo |
|
|
|
|
|
|
|
} |
|
|
|
viewModel.load(bookUrl) { |
|
|
|
viewModel.load(bookUrl) { |
|
|
|
//todo |
|
|
|
//todo |
|
|
|
} |
|
|
|
} |
|
|
@ -62,6 +66,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe |
|
|
|
class ViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class ViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
|
val loadStateLiveData = MutableLiveData<Boolean>() |
|
|
|
val loadStateLiveData = MutableLiveData<Boolean>() |
|
|
|
|
|
|
|
val loadErrorLiveData = MutableLiveData<String>() |
|
|
|
|
|
|
|
|
|
|
|
fun load(bookUrl: String, success: (book: Book) -> Unit) { |
|
|
|
fun load(bookUrl: String, success: (book: Book) -> Unit) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
@ -90,6 +95,9 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe |
|
|
|
book.order = appDb.bookDao.minOrder - 1 |
|
|
|
book.order = appDb.bookDao.minOrder - 1 |
|
|
|
return@execute book |
|
|
|
return@execute book |
|
|
|
} ?: throw NoStackTraceException("未找到匹配书源") |
|
|
|
} ?: throw NoStackTraceException("未找到匹配书源") |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
AppLog.put("添加书籍 ${bookUrl} 出错", it) |
|
|
|
|
|
|
|
loadErrorLiveData.postValue(it.localizedMessage) |
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
success.invoke(it) |
|
|
|
success.invoke(it) |
|
|
|
}.onStart { |
|
|
|
}.onStart { |
|
|
|