From 0c061ac37917e983305a48bfa269d0f5e5a2326c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:07:20 +0800 Subject: [PATCH 1/4] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 985505281..48dc30c5b 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/08** +* 导入本地源不再需要存储权限 + **2020/01/07** * 修复备份问题 * 设置背景不再需要存储权限 From 676fdd4d47a20c80e28fbdbd70ffc2b6e804e2be Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:26:19 +0800 Subject: [PATCH 2/4] up --- .../java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 9ba3a5a0f..be97fcacd 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -211,7 +211,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() viewModel.importSource(it) { msg -> - toast(msg) + title_bar.snackbar(msg) } } } catch (e: Exception) { From 8446fe356eeab0e5f585a026b2fd8504322bf992 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:38:39 +0800 Subject: [PATCH 3/4] up --- .../ui/book/read/config/BgTextConfigDialog.kt | 1 - .../book/source/manage/BookSourceActivity.kt | 18 ++++++++++-- .../app/ui/replacerule/ReplaceRuleActivity.kt | 16 +++++++++- .../ui/rss/source/manage/RssSourceActivity.kt | 29 +++++++++++++++---- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index b19b86c91..2b4a7dc4f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -195,7 +195,6 @@ class BgTextConfigDialog : DialogFragment() { ReadBookConfig.upBg() postEvent(Bus.UP_CONFIG, false) } - Unit } .request() } 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 314eb3621..af1231556 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 @@ -21,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.BookSource 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.cancelButton 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.startService import org.jetbrains.anko.toast +import java.io.FileNotFoundException class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), BookSourceAdapter.CallBack, @@ -295,11 +298,22 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() 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) { - e.localizedMessage?.let { toast(it) } + toast(e.localizedMessage ?: "ERROR") } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index be97fcacd..00dfd3f34 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -21,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.ReplaceRule 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.cancelButton import io.legado.app.lib.dialogs.customView @@ -34,6 +36,7 @@ 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.FileNotFoundException class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), @@ -214,8 +217,19 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi 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) { - e.localizedMessage?.let { toast(it) } + toast(e.localizedMessage ?: "ERROR") } } } 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 c8232669d..883acbb8c 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 @@ -21,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssSource 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.cancelButton 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 org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult +import org.jetbrains.anko.toast +import java.io.FileNotFoundException class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), @@ -234,12 +238,27 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r when (requestCode) { importSource -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - uri.readText(this)?.let { - Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) - .show() - viewModel.importSource(it) { msg -> - title_bar.snackbar(msg) + try { + uri.readText(this)?.let { + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) + .show() + viewModel.importSource(it) { 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") } } } From a145933b1618d9dfc99e823ffd462c9c56b9ff7d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:46:55 +0800 Subject: [PATCH 4/4] up --- .../book/source/manage/BookSourceActivity.kt | 29 ++++++++++--------- .../app/ui/replacerule/ReplaceRuleActivity.kt | 28 ++++++++++++++++++ .../ui/replacerule/ReplaceRuleViewModel.kt | 6 ++-- .../ui/rss/source/manage/RssSourceActivity.kt | 29 ++++++++++--------- 4 files changed, 61 insertions(+), 31 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 af1231556..52b433a32 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 @@ -213,14 +213,6 @@ class BookSourceActivity : VMBaseActivity(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(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) { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 00dfd3f34..5c53e91e1 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -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(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(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) + } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 540900eec..ba6bc2a61 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -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)) } } 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 883acbb8c..b536a0b84 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 @@ -198,14 +198,6 @@ class RssSourceActivity : VMBaseActivity(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(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) {