feat: 优化代码

pull/173/head
kunfei 5 years ago
parent 7f5d9435ca
commit 77c3263ddb
  1. 14
      app/src/main/java/io/legado/app/ui/config/FileAssociation.kt
  2. 19
      app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt

@ -8,20 +8,22 @@ import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
class FileAssociation : VMBaseActivity<FileAssociationViewModel>(R.layout.activity_file_association) { class FileAssociation :
VMBaseActivity<FileAssociationViewModel>(R.layout.activity_file_association) {
override val viewModel: FileAssociationViewModel override val viewModel: FileAssociationViewModel
get() = getViewModel(FileAssociationViewModel::class.java) get() = getViewModel(FileAssociationViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
if (null != intent.data){ intent.data?.let { data ->
val newIntent = viewModel.dispatchIndent(intent.data!!) val newIntent = viewModel.dispatchIndent(data)
if (newIntent != null){ if (newIntent != null) {
this.startActivityForResult(newIntent, 100) this.startActivityForResult(newIntent, 100)
}else{ } else {
gotoMainActivity() gotoMainActivity()
} }
} }
} }
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)
@ -29,7 +31,7 @@ class FileAssociation : VMBaseActivity<FileAssociationViewModel>(R.layout.activi
gotoMainActivity() gotoMainActivity()
} }
private fun gotoMainActivity(){ private fun gotoMainActivity() {
val mIntent = Intent() val mIntent = Intent()
mIntent.setClass(this, MainActivity::class.java) mIntent.setClass(this, MainActivity::class.java)
startActivity(mIntent) startActivity(mIntent)

@ -8,7 +8,6 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonArray
import io.legado.app.utils.isJsonObject import io.legado.app.utils.isJsonObject
import org.jetbrains.anko.toast
import java.io.File import java.io.File
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { class FileAssociationViewModel(application: Application) : BaseViewModel(application) {
@ -22,12 +21,16 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
val content = file.readText() val content = file.readText()
if (content.isJsonObject() || content.isJsonArray()){ if (content.isJsonObject() || content.isJsonArray()){
//暂时根据文件内容判断属于什么 //暂时根据文件内容判断属于什么
if (content.contains("bookSourceUrl")){ when {
scheme = "booksource" content.contains("bookSourceUrl") -> {
}else if (content.contains("sourceUrl")){ scheme = "booksource"
scheme = "rsssource" }
}else if (content.contains("pattern")){ content.contains("sourceUrl") -> {
scheme = "replace" scheme = "rsssource"
}
content.contains("pattern") -> {
scheme = "replace"
}
} }
} }
if (TextUtils.isEmpty(scheme)){ if (TextUtils.isEmpty(scheme)){
@ -54,7 +57,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
} }
val data = Uri.parse(url) val data = Uri.parse(url)
val newIndent = Intent(Intent.ACTION_VIEW) val newIndent = Intent(Intent.ACTION_VIEW)
newIndent.data = data; newIndent.data = data
return newIndent return newIndent
} }
} }
Loading…
Cancel
Save