pull/48/head
kunfei 5 years ago
parent 6ab8c2c317
commit 41e3b84e5e
  1. 31
      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.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<BookSourceViewModel>(R.layout.activity_book_source),
BookSourceAdapter.CallBack,
FileChooserDialog.CallBack,
SearchView.OnQueryTextListener {
override val viewModel: BookSourceViewModel
get() = getViewModel(BookSourceViewModel::class.java)
@ -101,14 +103,13 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private fun initUriScheme() {
intent.data?.let {
when(it.path)
{
"/importonline" -> {
it.getQueryParameter("src")?.let{
viewModel.importSource(it)
when (it.path) {
"/importonline" -> it.getQueryParameter("src")?.let { url ->
viewModel.importSource(url)
}
else -> {
toast("格式不对")
}
else -> {toast("格式不对")}
}
}
}
@ -204,10 +205,20 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(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 {

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

@ -42,7 +42,8 @@ class FileChooserDialog : DialogFragment(),
initPath: String? = null,
isShowHomeDir: Boolean = false,
isShowUpDir: Boolean = true,
isShowHideDir: Boolean = false
isShowHideDir: Boolean = false,
allowExtensions: Array<String?>? = 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)
}
}

@ -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<RssSourceViewModel>(R.layout.activity_rss_source),
FileChooserDialog.CallBack,
RssSourceAdapter.CallBack {
override val viewModel: RssSourceViewModel
@ -190,10 +192,20 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(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?) {

Loading…
Cancel
Save