From d9e640b86b24c86da714539e12d0d12a9f0366b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=84=8F=E5=B8=86?= <1657098617@qq.com> Date: Sun, 3 Jul 2022 15:26:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20webdav=E4=B9=A6=E7=B1=8D=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 按更新时间排序,按文件名排序的选项。 默认排序规则为按文件更新时间倒序排列 --- .../app/ui/book/remote/RemoteBookActivity.kt | 77 ++++++++++++++++--- app/src/main/res/menu/book_remote.xml | 7 +- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 79 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt index 3b1ab5e53..0dd6ac2ee 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt @@ -16,12 +16,16 @@ import io.legado.app.ui.book.remote.manager.RemoteBookWebDav import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.dialog.WaitDialog +import io.legado.app.utils.cnCompare import io.legado.app.utils.showDialogFragment import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import java.io.File +import java.util.ArrayList /** * 展示远程书籍 @@ -36,6 +40,8 @@ class RemoteBookActivity : VMBaseActivity + viewModel.dataFlow.conflate().map { remoteBooks -> + + val dirList = ArrayList() + val bookList = ArrayList() + + remoteBooks.forEach { + if (it.isDir) + dirList.add(it) + else + bookList.add(it) + } + //默认情况下,为按修改时间倒序显示 + if (sortAscending) when (sortKey) { + Sort.Name -> { + dirList.sortedBy { it.filename } + + bookList.sortedBy { it.filename } + } + Sort.UpdateTime -> { + dirList.sortedBy { it.lastModify } + + bookList.sortedBy { it.lastModify } + } + else -> dirList + bookList + } + else when (sortKey) { + + Sort.Name -> { + dirList.sortedByDescending { it.filename } + + bookList.sortedByDescending { it.filename } + } + Sort.UpdateTime -> { + dirList.sortedByDescending { it.lastModify } + + bookList.sortedByDescending { it.lastModify } + } + //按修改时间倒序显示 + else -> { + dirList.sortedByDescending { it.lastModify } + + bookList.sortedByDescending { it.lastModify } + } + } + + }.conflate().collect { sortedRemoteBooks -> binding.refreshProgressBar.isAutoLoading = false - binding.tvEmptyMsg.isGone = remoteBooks.isNotEmpty() - adapter.setItems(remoteBooks) + binding.tvEmptyMsg.isGone = sortedRemoteBooks.isNotEmpty() + adapter.setItems(sortedRemoteBooks) + delay(500) } } upPath() @@ -81,20 +136,20 @@ class RemoteBookActivity : VMBaseActivity { item.isChecked = true toastOnUi("menu_sort_auto") - //sortCheck(BookSourceActivity.Sort.Weight) - //upBookSource(searchView.query?.toString()) + sortCheck(Sort.Default) + upPath() } R.id.menu_sort_name -> { item.isChecked = true toastOnUi("menu_sort_name") - //sortCheck(BookSourceActivity.Sort.Name) - //upBookSource(searchView.query?.toString()) + sortCheck(Sort.Name) + upPath() } R.id.menu_sort_time -> { item.isChecked = true toastOnUi("menu_sort_time") - //sortCheck(BookSourceActivity.Sort.Update) - //upBookSource(searchView.query?.toString()) + sortCheck(Sort.UpdateTime) + upPath() } } return super.onCompatOptionsItemSelected(item) @@ -165,4 +220,8 @@ class RemoteBookActivity : VMBaseActivity @@ -21,9 +21,10 @@ android:checkableBehavior="single"> + android:checked="true" + android:title="@string/sort_default" /> Orden ascendente/descendente Ordenar Ordenar automáticamente + Ordenar por defecto Ordenar manualmente Ordenar por nombre Ir al principio diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 4b808acec..885d1ded5 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -351,6 +351,7 @@ Ascending/Descending order Sort Sort automatically + Sort default Sort manually Sort by name Scroll to the top diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index ce063bdc8..9256586f3 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -349,6 +349,7 @@ Ordem ascendente/descendente Ordenar Ordenar automaticamente + Ordenar por defecto Ordenar manualmente Ordenar por nome Vá ao topo diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index e766a58d6..5e8d2bf0a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -348,6 +348,7 @@ 倒序-順序 排序 智能排序 + 默認排序 手動排序 名稱排序 滾動到頂部 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index cede2c668..0324be41a 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -350,6 +350,7 @@ 倒序-順序 排序 智慧排序 + 默認排序 手動排序 名稱排序 滾動到頂部 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index df1d97d84..a35c642c2 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -351,6 +351,7 @@ 排序 智能排序 手动排序 + 默认排序 名称排序 滚动到顶部 滚动到底部 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b245e0419..aed09cb39 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -352,6 +352,7 @@ Sort Sort automatically Sort manually + Sort default Sort by name Scroll to the top Scroll to the bottom