pull/48/head
kunfei 5 years ago
parent 6ab8c2c317
commit 41e3b84e5e
  1. 33
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 1
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  3. 7
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt
  4. 20
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -29,6 +29,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.lib.theme.view.ATEAutoCompleteTextView
import io.legado.app.service.CheckSourceService import io.legado.app.service.CheckSourceService
import io.legado.app.ui.book.source.edit.BookSourceEditActivity 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.ui.qrcode.QrCodeActivity
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.activity_book_source.*
@ -42,6 +43,7 @@ import org.jetbrains.anko.toast
class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source), class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source),
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
FileChooserDialog.CallBack,
SearchView.OnQueryTextListener { SearchView.OnQueryTextListener {
override val viewModel: BookSourceViewModel override val viewModel: BookSourceViewModel
get() = getViewModel(BookSourceViewModel::class.java) get() = getViewModel(BookSourceViewModel::class.java)
@ -100,15 +102,14 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
private fun initUriScheme() { private fun initUriScheme() {
intent.data?.let{ intent.data?.let {
when(it.path) when (it.path) {
{ "/importonline" -> it.getQueryParameter("src")?.let { url ->
"/importonline" -> { viewModel.importSource(url)
it.getQueryParameter("src")?.let{
viewModel.importSource(it)
} }
else -> {
toast("格式不对")
} }
else -> {toast("格式不对")}
} }
} }
} }
@ -204,10 +205,20 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
private fun selectFile() { private fun selectFile() {
val intent = Intent(Intent.ACTION_GET_CONTENT) FileChooserDialog.show(
intent.addCategory(Intent.CATEGORY_OPENABLE) supportFragmentManager, importSource,
intent.type = "text/*"//设置类型 allowExtensions = arrayOf("txt", "json")
startActivityForResult(intent, importSource) )
// 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 { override fun onQueryTextChange(newText: String?): Boolean {

@ -131,7 +131,6 @@ class ConfigFragment : PreferenceFragmentCompat(),
} }
override fun onFilePicked(requestCode: Int, currentPath: String) { override fun onFilePicked(requestCode: Int, currentPath: String) {
super.onFilePicked(requestCode, currentPath)
putPrefString(PreferKey.downloadPath, currentPath) putPrefString(PreferKey.downloadPath, currentPath)
} }
} }

@ -42,7 +42,8 @@ class FileChooserDialog : DialogFragment(),
initPath: String? = null, initPath: String? = null,
isShowHomeDir: Boolean = false, isShowHomeDir: Boolean = false,
isShowUpDir: Boolean = true, isShowUpDir: Boolean = true,
isShowHideDir: Boolean = false isShowHideDir: Boolean = false,
allowExtensions: Array<String?>? = null
) { ) {
val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog)
?: FileChooserDialog().apply { ?: FileChooserDialog().apply {
@ -54,6 +55,7 @@ class FileChooserDialog : DialogFragment(),
bundle.putBoolean("isShowUpDir", isShowUpDir) bundle.putBoolean("isShowUpDir", isShowUpDir)
bundle.putBoolean("isShowHideDir", isShowHideDir) bundle.putBoolean("isShowHideDir", isShowHideDir)
bundle.putString("initPath", initPath) bundle.putString("initPath", initPath)
bundle.putStringArray("allowExtensions", allowExtensions)
arguments = bundle arguments = bundle
} }
fragment.show(manager, tag) fragment.show(manager, tag)
@ -103,6 +105,7 @@ class FileChooserDialog : DialogFragment(),
it.getString("initPath")?.let { path -> it.getString("initPath")?.let { path ->
initPath = path initPath = path
} }
allowExtensions = it.getStringArray("allowExtensions")
} }
tool_bar.title = title ?: let { tool_bar.title = title ?: let {
if (isOnlyListDir) { if (isOnlyListDir) {
@ -191,6 +194,6 @@ class FileChooserDialog : DialogFragment(),
} }
interface CallBack { interface CallBack {
fun onFilePicked(requestCode: Int, currentPath: String) {} fun onFilePicked(requestCode: Int, currentPath: String)
} }
} }

@ -27,6 +27,7 @@ import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.lib.theme.view.ATEAutoCompleteTextView 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.qrcode.QrCodeActivity
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.* import io.legado.app.utils.*
@ -39,6 +40,7 @@ import org.jetbrains.anko.startActivityForResult
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source),
FileChooserDialog.CallBack,
RssSourceAdapter.CallBack { RssSourceAdapter.CallBack {
override val viewModel: RssSourceViewModel override val viewModel: RssSourceViewModel
@ -190,10 +192,20 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
} }
private fun selectFile() { private fun selectFile() {
val intent = Intent(Intent.ACTION_GET_CONTENT) FileChooserDialog.show(
intent.addCategory(Intent.CATEGORY_OPENABLE) supportFragmentManager, importSource,
intent.type = "text/*"//设置类型 allowExtensions = arrayOf("txt", "json")
startActivityForResult(intent, importSource) )
// 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?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

Loading…
Cancel
Save