pull/69/head
kunfei 5 years ago
parent 8446fe356e
commit a145933b16
  1. 29
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 28
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt
  4. 29
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -213,14 +213,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
}.show().applyTint()
}
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json"),
menus = arrayOf(getString(R.string.sys_file_picker))
)
}
private fun selectFileSys() {
try {
val intent = Intent(Intent.ACTION_GET_CONTENT)
@ -229,15 +221,24 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource)
} catch (e: Exception) {
selectFile()
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFile()
}
.request()
}
}
override fun onMenuClick(menu: String) {
super.onMenuClick(menu)
when (menu) {
getString(R.string.sys_file_picker) -> selectFileSys()
}
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json")
)
}
override fun onFilePicked(requestCode: Int, currentPath: String) {

@ -30,17 +30,20 @@ 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.replacerule.edit.ReplaceEditDialog
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_replace_rule.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.toast
import java.io.File
import java.io.FileNotFoundException
class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule),
SearchView.OnQueryTextListener,
FileChooserDialog.CallBack,
ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel
get() = getViewModel(ReplaceRuleViewModel::class.java)
@ -191,7 +194,32 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource)
} catch (e: Exception) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFile()
}
.request()
}
}
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json")
)
}
override fun onFilePicked(requestCode: Int, currentPath: String) {
if (requestCode == importSource) {
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show()
viewModel.importSource(File(currentPath).readText()) { msg ->
title_bar.snackbar(msg)
}
}
}

@ -16,13 +16,13 @@ import java.io.File
class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) {
fun importSource(text: String, toast: (msg: String) -> Unit) {
fun importSource(text: String, showMsg: (msg: String) -> Unit) {
execute {
Restore.importOldReplaceRule(text)
}.onError {
toast(it.localizedMessage ?: "ERROR")
showMsg(it.localizedMessage ?: "ERROR")
}.onSuccess {
toast(context.getString(R.string.success))
showMsg(context.getString(R.string.success))
}
}

@ -198,14 +198,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}.show().applyTint()
}
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json"),
menus = arrayOf(getString(R.string.sys_file_picker))
)
}
private fun selectFileSys() {
try {
val intent = Intent(Intent.ACTION_GET_CONTENT)
@ -213,15 +205,24 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource)
} catch (e: Exception) {
selectFile()
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFile()
}
.request()
}
}
override fun onMenuClick(menu: String) {
super.onMenuClick(menu)
when (menu) {
getString(R.string.sys_file_picker) -> selectFileSys()
}
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json")
)
}
override fun onFilePicked(requestCode: Int, currentPath: String) {

Loading…
Cancel
Save