From 41e3b84e5ea262f2a1e7c65bdcfb7a65eabc87cd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 12 Nov 2019 11:03:21 +0800 Subject: [PATCH] up --- .../book/source/manage/BookSourceActivity.kt | 35 ++++++++++++------- .../io/legado/app/ui/config/ConfigFragment.kt | 1 - .../app/ui/filechooser/FileChooserDialog.kt | 7 ++-- .../ui/rss/source/manage/RssSourceActivity.kt | 20 ++++++++--- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index dd46e26bc..4d07a5403 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -29,6 +29,7 @@ import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.service.CheckSourceService import io.legado.app.ui.book.source.edit.BookSourceEditActivity +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* @@ -42,6 +43,7 @@ import org.jetbrains.anko.toast class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), BookSourceAdapter.CallBack, + FileChooserDialog.CallBack, SearchView.OnQueryTextListener { override val viewModel: BookSourceViewModel get() = getViewModel(BookSourceViewModel::class.java) @@ -100,15 +102,14 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun initUriScheme() { - intent.data?.let{ - when(it.path) - { - "/importonline" -> { - it.getQueryParameter("src")?.let{ - viewModel.importSource(it) - } + intent.data?.let { + when (it.path) { + "/importonline" -> it.getQueryParameter("src")?.let { url -> + viewModel.importSource(url) + } + else -> { + toast("格式不对") } - else -> {toast("格式不对")} } } } @@ -204,10 +205,20 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun selectFile() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "text/*"//设置类型 - startActivityForResult(intent, importSource) + FileChooserDialog.show( + supportFragmentManager, importSource, + allowExtensions = arrayOf("txt", "json") + ) +// val intent = Intent(Intent.ACTION_GET_CONTENT) +// intent.addCategory(Intent.CATEGORY_OPENABLE) +// intent.type = "text/*"//设置类型 +// startActivityForResult(intent, importSource) + } + + override fun onFilePicked(requestCode: Int, currentPath: String) { + if (requestCode == importSource) { + viewModel.importSourceFromFilePath(currentPath) + } } override fun onQueryTextChange(newText: String?): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index 3d5c43896..24b296f7c 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -131,7 +131,6 @@ class ConfigFragment : PreferenceFragmentCompat(), } override fun onFilePicked(requestCode: Int, currentPath: String) { - super.onFilePicked(requestCode, currentPath) putPrefString(PreferKey.downloadPath, currentPath) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 6899a388d..2fffac981 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -42,7 +42,8 @@ class FileChooserDialog : DialogFragment(), initPath: String? = null, isShowHomeDir: Boolean = false, isShowUpDir: Boolean = true, - isShowHideDir: Boolean = false + isShowHideDir: Boolean = false, + allowExtensions: Array? = null ) { val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) ?: FileChooserDialog().apply { @@ -54,6 +55,7 @@ class FileChooserDialog : DialogFragment(), bundle.putBoolean("isShowUpDir", isShowUpDir) bundle.putBoolean("isShowHideDir", isShowHideDir) bundle.putString("initPath", initPath) + bundle.putStringArray("allowExtensions", allowExtensions) arguments = bundle } fragment.show(manager, tag) @@ -103,6 +105,7 @@ class FileChooserDialog : DialogFragment(), it.getString("initPath")?.let { path -> initPath = path } + allowExtensions = it.getStringArray("allowExtensions") } tool_bar.title = title ?: let { if (isOnlyListDir) { @@ -191,6 +194,6 @@ class FileChooserDialog : DialogFragment(), } interface CallBack { - fun onFilePicked(requestCode: Int, currentPath: String) {} + fun onFilePicked(requestCode: Int, currentPath: String) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index dce6b21cf..600d09fbf 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -27,6 +27,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.utils.* @@ -39,6 +40,7 @@ import org.jetbrains.anko.startActivityForResult class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), + FileChooserDialog.CallBack, RssSourceAdapter.CallBack { override val viewModel: RssSourceViewModel @@ -190,10 +192,20 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } private fun selectFile() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "text/*"//设置类型 - startActivityForResult(intent, importSource) + FileChooserDialog.show( + supportFragmentManager, importSource, + allowExtensions = arrayOf("txt", "json") + ) +// val intent = Intent(Intent.ACTION_GET_CONTENT) +// intent.addCategory(Intent.CATEGORY_OPENABLE) +// intent.type = "text/*"//设置类型 +// startActivityForResult(intent, importSource) + } + + override fun onFilePicked(requestCode: Int, currentPath: String) { + if (requestCode == importSource) { + viewModel.importSourceFromFilePath(currentPath) + } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {