Merge pull request #9 from gedoor/master

up
pull/69/head
口口吕 5 years ago committed by GitHub
commit d9f58efaf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/assets/updateLog.md
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  3. 45
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  4. 46
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt
  6. 46
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -3,6 +3,9 @@
* 旧版数据导入教程: * 旧版数据导入教程:
* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/01/08**
* 导入本地源不再需要存储权限
**2020/01/07** **2020/01/07**
* 修复备份问题 * 修复备份问题
* 设置背景不再需要存储权限 * 设置背景不再需要存储权限

@ -195,7 +195,6 @@ class BgTextConfigDialog : DialogFragment() {
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(Bus.UP_CONFIG, false) postEvent(Bus.UP_CONFIG, false)
} }
Unit
} }
.request() .request()
} }

@ -21,6 +21,8 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.cancelButton
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
@ -40,6 +42,7 @@ import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.startService import org.jetbrains.anko.startService
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.FileNotFoundException
class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source), class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source),
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
@ -210,14 +213,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
}.show().applyTint() }.show().applyTint()
} }
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json"),
menus = arrayOf(getString(R.string.sys_file_picker))
)
}
private fun selectFileSys() { private fun selectFileSys() {
try { try {
val intent = Intent(Intent.ACTION_GET_CONTENT) val intent = Intent(Intent.ACTION_GET_CONTENT)
@ -226,15 +221,24 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
intent.type = "text/*"//设置类型 intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource) startActivityForResult(intent, importSource)
} catch (e: Exception) { } catch (e: Exception) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFile() 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) { override fun onFilePicked(requestCode: Int, currentPath: String) {
@ -295,11 +299,22 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE)
.show() .show()
viewModel.importSource(it) { msg -> viewModel.importSource(it) { msg ->
toast(msg) title_bar.snackbar(msg)
} }
} }
} catch (e: FileNotFoundException) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFileSys()
}
.request()
} catch (e: Exception) { } catch (e: Exception) {
e.localizedMessage?.let { toast(it) } toast(e.localizedMessage ?: "ERROR")
} }
} }
} }

@ -21,6 +21,8 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.cancelButton
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
@ -28,16 +30,20 @@ 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.replacerule.edit.ReplaceEditDialog import io.legado.app.ui.replacerule.edit.ReplaceEditDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.activity_replace_rule.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File
import java.io.FileNotFoundException
class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule), class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule),
SearchView.OnQueryTextListener, SearchView.OnQueryTextListener,
FileChooserDialog.CallBack,
ReplaceRuleAdapter.CallBack { ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel override val viewModel: ReplaceRuleViewModel
get() = getViewModel(ReplaceRuleViewModel::class.java) get() = getViewModel(ReplaceRuleViewModel::class.java)
@ -188,7 +194,32 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
intent.type = "text/*"//设置类型 intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource) startActivityForResult(intent, importSource)
} catch (e: Exception) { } 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)
}
} }
} }
@ -211,11 +242,22 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE)
.show() .show()
viewModel.importSource(it) { msg -> viewModel.importSource(it) { msg ->
toast(msg) title_bar.snackbar(msg)
}
} }
} catch (e: FileNotFoundException) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFileSys()
} }
.request()
} catch (e: Exception) { } catch (e: Exception) {
e.localizedMessage?.let { toast(it) } toast(e.localizedMessage ?: "ERROR")
} }
} }
} }

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

@ -21,6 +21,8 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.cancelButton
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
@ -37,6 +39,8 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
import java.io.FileNotFoundException
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source),
@ -194,14 +198,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}.show().applyTint() }.show().applyTint()
} }
private fun selectFile() {
FileChooserDialog.show(
supportFragmentManager, importSource,
allowExtensions = arrayOf("txt", "json"),
menus = arrayOf(getString(R.string.sys_file_picker))
)
}
private fun selectFileSys() { private fun selectFileSys() {
try { try {
val intent = Intent(Intent.ACTION_GET_CONTENT) val intent = Intent(Intent.ACTION_GET_CONTENT)
@ -209,15 +205,24 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
intent.type = "text/*"//设置类型 intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource) startActivityForResult(intent, importSource)
} catch (e: Exception) { } catch (e: Exception) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFile() 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) { override fun onFilePicked(requestCode: Int, currentPath: String) {
@ -234,6 +239,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
when (requestCode) { when (requestCode) {
importSource -> if (resultCode == Activity.RESULT_OK) { importSource -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
try {
uri.readText(this)?.let { uri.readText(this)?.let {
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE)
.show() .show()
@ -241,6 +247,20 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
title_bar.snackbar(msg) title_bar.snackbar(msg)
} }
} }
} catch (e: FileNotFoundException) {
PermissionsCompat.Builder(this)
.addPermissions(
Permissions.READ_EXTERNAL_STORAGE,
Permissions.WRITE_EXTERNAL_STORAGE
)
.rationale(R.string.bg_image_per)
.onGranted {
selectFileSys()
}
.request()
} catch (e: Exception) {
toast(e.localizedMessage ?: "ERROR")
}
} }
} }
qrRequestCode -> if (resultCode == RESULT_OK) { qrRequestCode -> if (resultCode == RESULT_OK) {

Loading…
Cancel
Save