From 77c3263ddbec38a2d2a7bd2e5a4585bd390e8056 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:19:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/config/FileAssociation.kt | 14 ++++++++------ .../app/ui/config/FileAssociationViewModel.kt | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt index 0b2a3c749..9e459a226 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt @@ -8,20 +8,22 @@ import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel -class FileAssociation : VMBaseActivity(R.layout.activity_file_association) { +class FileAssociation : + VMBaseActivity(R.layout.activity_file_association) { override val viewModel: FileAssociationViewModel get() = getViewModel(FileAssociationViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - if (null != intent.data){ - val newIntent = viewModel.dispatchIndent(intent.data!!) - if (newIntent != null){ + intent.data?.let { data -> + val newIntent = viewModel.dispatchIndent(data) + if (newIntent != null) { this.startActivityForResult(newIntent, 100) - }else{ + } else { gotoMainActivity() } } } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) @@ -29,7 +31,7 @@ class FileAssociation : VMBaseActivity(R.layout.activi gotoMainActivity() } - private fun gotoMainActivity(){ + private fun gotoMainActivity() { val mIntent = Intent() mIntent.setClass(this, MainActivity::class.java) startActivity(mIntent) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index 810c885f6..11705c537 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -8,7 +8,6 @@ import io.legado.app.base.BaseViewModel import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonObject -import org.jetbrains.anko.toast import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { @@ -22,12 +21,16 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica val content = file.readText() if (content.isJsonObject() || content.isJsonArray()){ //暂时根据文件内容判断属于什么 - if (content.contains("bookSourceUrl")){ - scheme = "booksource" - }else if (content.contains("sourceUrl")){ - scheme = "rsssource" - }else if (content.contains("pattern")){ - scheme = "replace" + when { + content.contains("bookSourceUrl") -> { + scheme = "booksource" + } + content.contains("sourceUrl") -> { + scheme = "rsssource" + } + content.contains("pattern") -> { + scheme = "replace" + } } } if (TextUtils.isEmpty(scheme)){ @@ -54,7 +57,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica } val data = Uri.parse(url) val newIndent = Intent(Intent.ACTION_VIEW) - newIndent.data = data; + newIndent.data = data return newIndent } } \ No newline at end of file