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** * 修复备份问题 * 设置背景不再需要存储权限 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..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 @@ -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, @@ -210,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) @@ -226,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) { @@ -295,11 +299,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 9ba3a5a0f..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 @@ -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 @@ -28,16 +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) @@ -188,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) + } } } @@ -211,11 +242,22 @@ 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: 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/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 c8232669d..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 @@ -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), @@ -194,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) @@ -209,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) { @@ -234,12 +239,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") } } }