pull/306/head
gedoor 4 years ago
parent ceb2cd600e
commit 9ecc192186
  1. 11
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt

@ -8,6 +8,8 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme
import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_translucence.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
@ -20,11 +22,13 @@ class FileAssociationActivity : VMBaseActivity<FileAssociationViewModel>(
get() = getViewModel(FileAssociationViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
rotate_loading.show()
viewModel.errorLiveData.observe(this, Observer {
rotate_loading.hide()
toast(it)
gotoMainActivity()
})
viewModel.successLiveData.observe(this, Observer {
rotate_loading.hide()
startActivity(it)
finish()
})
@ -35,13 +39,12 @@ class FileAssociationActivity : VMBaseActivity<FileAssociationViewModel>(
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
finish()
//返回后直接跳转到主页面
gotoMainActivity()
}
private fun gotoMainActivity() {
val mIntent = Intent()
mIntent.setClass(this, MainActivity::class.java)
startActivity(mIntent)
startActivity<MainActivity>()
}
}

@ -24,6 +24,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
val url: String
//如果是普通的url,需要根据返回的内容判断是什么
if (uri.scheme == "file" || uri.scheme == "content") {
var scheme = ""
val content = if (uri.scheme == "file") {
val file = File(uri.path.toString())
if (file.exists()) {
@ -34,7 +35,6 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
} else {
DocumentFile.fromSingleUri(context, uri)?.readText(context)
}
var scheme = ""
if (content != null) {
if (content.isJsonObject() || content.isJsonArray()) {
//暂时根据文件内容判断属于什么
@ -84,7 +84,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
return@execute
}.onError {
it.printStackTrace()
toast(it.localizedMessage)
errorLiveData.postValue(it.localizedMessage)
}
}
}
Loading…
Cancel
Save