pull/1282/head
gedoor 3 years ago
parent ac3f2334d0
commit 1d738cf4e2
  1. 7
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  2. 7
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  3. 14
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt

@ -70,10 +70,10 @@ object LocalBook {
path = uri.path!!
File(path).name
})
var book = appDb.bookDao.getBook(path)
if (book == null) {
val nameAuthor = analyzeNameAuthor(fileName)
val book = Book(
book = Book(
bookUrl = path,
name = nameAuthor.first,
author = nameAuthor.second,
@ -87,6 +87,7 @@ object LocalBook {
if (book.isEpub()) EpubFile.upBookInfo(book)
if (book.isUmd()) UmdFile.upBookInfo(book)
appDb.bookDao.insert(book)
}
return book
}

@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -40,9 +41,11 @@ class FileAssociationActivity :
toastOnUi(it)
finish()
})
viewModel.successLiveData.observe(this, {
viewModel.openBookLiveData.observe(this, {
binding.rotateLoading.hide()
startActivity(it)
startActivity<ReadBookActivity> {
putExtra("bookUrl", it)
}
finish()
})
intent.data?.let { data ->

@ -1,13 +1,11 @@
package io.legado.app.ui.association
import android.app.Application
import android.content.Intent
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.isJson
import io.legado.app.utils.readText
import java.io.File
@ -17,7 +15,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
val importBookSourceLive = MutableLiveData<String>()
val importRssSourceLive = MutableLiveData<String>()
val importReplaceRuleLive = MutableLiveData<String>()
val successLiveData = MutableLiveData<Intent>()
val openBookLiveData = MutableLiveData<String>()
val errorLiveData = MutableLiveData<String>()
@Suppress("BlockingMethodInNonBlockingContext")
@ -48,14 +46,8 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
}
}
}
val book = if (uri.scheme == "content") {
LocalBook.importFile(uri)
} else {
LocalBook.importFile(uri)
}
val intent = Intent(context, ReadBookActivity::class.java)
intent.putExtra("bookUrl", book.bookUrl)
successLiveData.postValue(intent)
val book = LocalBook.importFile(uri)
openBookLiveData.postValue(book.bookUrl)
} ?: throw Exception("文件不存在")
} else {
onLineImportLive.postValue(uri)

Loading…
Cancel
Save