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

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