Parcourir la source

feat(webFileImport): add waitDialog

close #2847
Xwite il y a 3 ans
Parent
commit
012dc106c3

+ 2 - 2
app/src/main/java/io/legado/app/model/Debug.kt

@@ -2,8 +2,8 @@ package io.legado.app.model
 
 
 import android.annotation.SuppressLint
 import android.annotation.SuppressLint
 import io.legado.app.constant.AppPattern
 import io.legado.app.constant.AppPattern
-import io.legado.app.constant.BookType
 import io.legado.app.data.entities.*
 import io.legado.app.data.entities.*
+import io.legado.app.help.book.isWebFile
 import io.legado.app.help.coroutine.CompositeCoroutine
 import io.legado.app.help.coroutine.CompositeCoroutine
 import io.legado.app.help.source.sortUrls
 import io.legado.app.help.source.sortUrls
 import io.legado.app.model.rss.Rss
 import io.legado.app.model.rss.Rss
@@ -240,7 +240,7 @@ object Debug {
             .onSuccess {
             .onSuccess {
                 log(debugSource, "︽详情页解析完成")
                 log(debugSource, "︽详情页解析完成")
                 log(debugSource, showTime = false)
                 log(debugSource, showTime = false)
-                if (book.type and BookType.webFile == 0) {
+                if (!book.isWebFile) {
                     tocDebug(scope, bookSource, book)
                     tocDebug(scope, bookSource, book)
                 } else {
                 } else {
                     log(debugSource, "≡文件类书源跳过解析目录", state = 1000)
                     log(debugSource, "≡文件类书源跳过解析目录", state = 1000)

+ 17 - 2
app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt

@@ -52,7 +52,8 @@ class BookInfoActivity :
     VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
     VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
     GroupSelectDialog.CallBack,
     GroupSelectDialog.CallBack,
     ChangeBookSourceDialog.CallBack,
     ChangeBookSourceDialog.CallBack,
-    ChangeCoverDialog.CallBack {
+    ChangeCoverDialog.CallBack,
+    BookInfoViewModel.CallBack {
 
 
     private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
     private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
         it?.let {
         it?.let {
@@ -93,6 +94,7 @@ class BookInfoActivity :
         }
         }
     }
     }
     private var tocChanged = false
     private var tocChanged = false
+    private val waitDialog by lazy { WaitDialog(this) }
 
 
     override val binding by viewBinding(ActivityBookInfoBinding::inflate)
     override val binding by viewBinding(ActivityBookInfoBinding::inflate)
     override val viewModel by viewModels<BookInfoViewModel>()
     override val viewModel by viewModels<BookInfoViewModel>()
@@ -106,6 +108,7 @@ class BookInfoActivity :
         binding.flAction.setBackgroundColor(bottomBackground)
         binding.flAction.setBackgroundColor(bottomBackground)
         binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
         binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
         binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
         binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
+        viewModel.callBack = this
         viewModel.bookData.observe(this) { showBook(it) }
         viewModel.bookData.observe(this) { showBook(it) }
         viewModel.chapterListData.observe(this) { upLoading(false, it) }
         viewModel.chapterListData.observe(this) { upLoading(false, it) }
         //viewModel.webFileData.observe(this) { showWebFileDownloadAlert() }
         //viewModel.webFileData.observe(this) { showWebFileDownloadAlert() }
@@ -223,7 +226,6 @@ class BookInfoActivity :
         bookWebDav: RemoteBookWebDav? = AppWebDav.defaultBookWebDav
         bookWebDav: RemoteBookWebDav? = AppWebDav.defaultBookWebDav
     ) {
     ) {
         launch {
         launch {
-            val waitDialog = WaitDialog(this@BookInfoActivity)
             waitDialog.setText("上传中.....")
             waitDialog.setText("上传中.....")
             waitDialog.show()
             waitDialog.show()
             try {
             try {
@@ -501,6 +503,7 @@ class BookInfoActivity :
             alert(titleResource = R.string.download_and_import_file) {
             alert(titleResource = R.string.download_and_import_file) {
                 items<BookInfoViewModel.WebFile>(it) { _, webFile, _ ->
                 items<BookInfoViewModel.WebFile>(it) { _, webFile, _ ->
                     if (webFile.isSupported) {
                     if (webFile.isSupported) {
+                        /* import */
                         viewModel.importOrDownloadWebFile<Book>(webFile) {
                         viewModel.importOrDownloadWebFile<Book>(webFile) {
                             onClick?.invoke(it)
                             onClick?.invoke(it)
                         }
                         }
@@ -510,6 +513,7 @@ class BookInfoActivity :
                             message = getString(R.string.file_not_supported, webFile.name)
                             message = getString(R.string.file_not_supported, webFile.name)
                         ) {
                         ) {
                             neutralButton(R.string.open_fun) {
                             neutralButton(R.string.open_fun) {
+                                /* download only */
                                 viewModel.importOrDownloadWebFile<Uri>(webFile) { uri ->
                                 viewModel.importOrDownloadWebFile<Uri>(webFile) { uri ->
                                     openFileUri(uri, "*/*")
                                     openFileUri(uri, "*/*")
                                 }
                                 }
@@ -584,4 +588,15 @@ class BookInfoActivity :
         }
         }
     }
     }
 
 
+    override fun onWebFileProcessFinally() {
+        waitDialog.dismiss()
+    }
+
+    override fun onWebFileProcessStart() {
+        waitDialog.run {
+            setText("Loading.....")
+            show()
+        }
+    }
+
 }
 }

+ 10 - 1
app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@@ -40,6 +40,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
     var inBookshelf = false
     var inBookshelf = false
     var bookSource: BookSource? = null
     var bookSource: BookSource? = null
     private var changeSourceCoroutine: Coroutine<*>? = null
     private var changeSourceCoroutine: Coroutine<*>? = null
+    var callBack: CallBack? = null
 
 
     fun initData(intent: Intent) {
     fun initData(intent: Intent) {
         execute {
         execute {
@@ -273,6 +274,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
     fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
     fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
        bookSource ?: return
        bookSource ?: return
        execute {
        execute {
+           callBack?.onWebFileProcessStart()
            if (webFile.isSupported) {
            if (webFile.isSupported) {
                val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
                val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
                changeToLocalBook(book)
                changeToLocalBook(book)
@@ -283,7 +285,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
            success?.invoke(it as T)
            success?.invoke(it as T)
        }.onError {
        }.onError {
            context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
            context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
-       }
+       }.onFinally {
+            callBack?.onWebFileProcessFinally()
+        }
     }
     }
 
 
     fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
     fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
@@ -419,4 +423,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
         }
         }
     }
     }
 
 
+    interface CallBack {
+        fun onWebFileProcessStart()
+        fun onWebFileProcessFinally()
+    }
+
 }
 }