优化本地导入

pull/457/head
gedoor 4 years ago
parent 7c0514a6dd
commit 3cccff03d4
  1. 28
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  2. 11
      app/src/main/res/layout/activity_import_book.xml
  3. 1
      app/src/main/res/values-zh-rHK/strings.xml
  4. 1
      app/src/main/res/values-zh-rTW/strings.xml
  5. 1
      app/src/main/res/values-zh/strings.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -122,12 +122,14 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
val lastPath = AppConfig.importBookPath
when {
lastPath.isNullOrEmpty() -> {
tv_empty_msg.visible()
FilePicker.selectFolder(this, requestCodeSelectFolder)
}
lastPath.isContentPath() -> {
val rootUri = Uri.parse(lastPath)
rootDoc = DocumentFile.fromTreeUri(this, rootUri)
if (rootDoc == null) {
tv_empty_msg.visible()
FilePicker.selectFolder(this, requestCodeSelectFolder)
} else {
subDocs.clear()
@ -135,18 +137,22 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
}
}
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> {
tv_empty_msg.visible()
FilePicker.selectFolder(this, requestCodeSelectFolder)
}
else -> PermissionsCompat.Builder(this)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
rootDoc = null
subDocs.clear()
path = lastPath
upPath()
}
.request()
else -> {
tv_empty_msg.visible()
PermissionsCompat.Builder(this)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
rootDoc = null
subDocs.clear()
path = lastPath
upPath()
}
.request()
}
}
}
@ -154,6 +160,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
@Synchronized
private fun upPath() {
rootDoc?.let { rootDoc ->
tv_empty_msg.gone()
var path = rootDoc.name.toString() + File.separator
var lastDoc = rootDoc
for (doc in subDocs) {
@ -183,6 +190,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
}
} ?: let {
if (path.isBlank()) return
tv_empty_msg.gone()
tv_path.text = path.replace(sdPath, "SD")
val docList = arrayListOf<DocItem>()
File(path).listFiles()?.forEach {

@ -65,6 +65,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/tv_empty_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
android:layout_gravity="center"
android:visibility="gone"
android:text="@string/empty_msg_import_book"
tools:text="TextView" />
</FrameLayout>
<io.legado.app.ui.widget.SelectActionBar

@ -776,5 +776,6 @@
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
<string name="re_segment">重新分段</string>
<string name="style_name">样式名称:</string>
<string name="empty_msg_import_book">点击右上角文件夹图标,选择文件夹</string>
</resources>

@ -776,5 +776,6 @@
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
<string name="re_segment">重新分段</string>
<string name="style_name">样式名称:</string>
<string name="empty_msg_import_book">点击右上角文件夹图标,选择文件夹</string>
</resources>

@ -779,5 +779,6 @@
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
<string name="re_segment">重新分段</string>
<string name="style_name">样式名称:</string>
<string name="empty_msg_import_book">点击右上角文件夹图标,选择文件夹</string>
</resources>

@ -782,5 +782,6 @@
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
<string name="re_segment">重新分段</string>
<string name="style_name">样式名称:</string>
<string name="empty_msg_import_book">点击右上角文件夹图标,选择文件夹</string>
</resources>

Loading…
Cancel
Save