feat: webdav书籍排序

添加 按更新时间排序,按文件名排序的选项。
默认排序规则为按文件更新时间倒序排列
pull/2021/head
谢意帆 2 years ago
parent 761570091a
commit d9e640b86b
  1. 77
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  2. 7
      app/src/main/res/menu/book_remote.xml
  3. 1
      app/src/main/res/values-es-rES/strings.xml
  4. 1
      app/src/main/res/values-ja-rJP/strings.xml
  5. 1
      app/src/main/res/values-pt-rBR/strings.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 1
      app/src/main/res/values-zh/strings.xml
  9. 1
      app/src/main/res/values/strings.xml

@ -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.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.dialog.WaitDialog 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.showDialogFragment
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.util.ArrayList
/** /**
* 展示远程书籍 * 展示远程书籍
@ -36,6 +40,8 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
private val adapter by lazy { RemoteBookAdapter(this, this) } private val adapter by lazy { RemoteBookAdapter(this, this) }
private val waitDialog by lazy { WaitDialog(this) } private val waitDialog by lazy { WaitDialog(this) }
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private var sortKey = Sort.Default
private var sortAscending = false
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.setTitle(R.string.remote_book) binding.titleBar.setTitle(R.string.remote_book)
initView() initView()
@ -51,13 +57,62 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
binding.selectActionBar.setCallBack(this) binding.selectActionBar.setCallBack(this)
} }
private fun sortCheck(sortKey: Sort) {
if (this.sortKey == sortKey) {
sortAscending = !sortAscending
} else {
sortAscending = true
this.sortKey = sortKey
}
}
private fun initData() { private fun initData() {
binding.refreshProgressBar.isAutoLoading = true binding.refreshProgressBar.isAutoLoading = true
launch { launch {
viewModel.dataFlow.conflate().collect { remoteBooks -> viewModel.dataFlow.conflate().map { remoteBooks ->
val dirList = ArrayList<RemoteBook>()
val bookList = ArrayList<RemoteBook>()
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.refreshProgressBar.isAutoLoading = false
binding.tvEmptyMsg.isGone = remoteBooks.isNotEmpty() binding.tvEmptyMsg.isGone = sortedRemoteBooks.isNotEmpty()
adapter.setItems(remoteBooks) adapter.setItems(sortedRemoteBooks)
delay(500)
} }
} }
upPath() upPath()
@ -81,20 +136,20 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
R.id.menu_sort_auto -> { R.id.menu_sort_auto -> {
item.isChecked = true item.isChecked = true
toastOnUi("menu_sort_auto") toastOnUi("menu_sort_auto")
//sortCheck(BookSourceActivity.Sort.Weight) sortCheck(Sort.Default)
//upBookSource(searchView.query?.toString()) upPath()
} }
R.id.menu_sort_name -> { R.id.menu_sort_name -> {
item.isChecked = true item.isChecked = true
toastOnUi("menu_sort_name") toastOnUi("menu_sort_name")
//sortCheck(BookSourceActivity.Sort.Name) sortCheck(Sort.Name)
//upBookSource(searchView.query?.toString()) upPath()
} }
R.id.menu_sort_time -> { R.id.menu_sort_time -> {
item.isChecked = true item.isChecked = true
toastOnUi("menu_sort_time") toastOnUi("menu_sort_time")
//sortCheck(BookSourceActivity.Sort.Update) sortCheck(Sort.UpdateTime)
//upBookSource(searchView.query?.toString()) upPath()
} }
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
@ -165,4 +220,8 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
override fun upCountView() { override fun upCountView() {
binding.selectActionBar.upCountView(adapter.selected.size, adapter.checkableCount) binding.selectActionBar.upCountView(adapter.selected.size, adapter.checkableCount)
} }
enum class Sort {
Default, Name, UpdateTime
}
} }

@ -12,7 +12,7 @@
<item <item
android:id="@+id/menu_sort" android:id="@+id/menu_sort"
android:icon="@drawable/ic_baseline_sort_24" android:icon="@drawable/ic_baseline_sort_24"
android:title="排序" android:title="@string/sort"
app:showAsAction="always" app:showAsAction="always"
tools:ignore="AlwaysShowAction"> tools:ignore="AlwaysShowAction">
<menu> <menu>
@ -21,9 +21,10 @@
android:checkableBehavior="single"> android:checkableBehavior="single">
<item <item
android:id="@+id/menu_sort_auto" android:id="@+id/menu_sort_default"
android:checkable="true" android:checkable="true"
android:title="@string/sort_auto" /> android:checked="true"
android:title="@string/sort_default" />
<item <item
android:id="@+id/menu_sort_name" android:id="@+id/menu_sort_name"

@ -347,6 +347,7 @@
<string name="swap_sort">Orden ascendente/descendente</string> <string name="swap_sort">Orden ascendente/descendente</string>
<string name="sort">Ordenar</string> <string name="sort">Ordenar</string>
<string name="sort_auto">Ordenar automáticamente</string> <string name="sort_auto">Ordenar automáticamente</string>
<string name="sort_default">Ordenar por defecto</string>
<string name="sort_manual">Ordenar manualmente</string> <string name="sort_manual">Ordenar manualmente</string>
<string name="sort_by_name">Ordenar por nombre</string> <string name="sort_by_name">Ordenar por nombre</string>
<string name="go_to_top">Ir al principio</string> <string name="go_to_top">Ir al principio</string>

@ -351,6 +351,7 @@
<string name="swap_sort">Ascending/Descending order</string> <string name="swap_sort">Ascending/Descending order</string>
<string name="sort">Sort</string> <string name="sort">Sort</string>
<string name="sort_auto">Sort automatically</string> <string name="sort_auto">Sort automatically</string>
<string name="sort_default">Sort default</string>
<string name="sort_manual">Sort manually</string> <string name="sort_manual">Sort manually</string>
<string name="sort_by_name">Sort by name</string> <string name="sort_by_name">Sort by name</string>
<string name="go_to_top">Scroll to the top</string> <string name="go_to_top">Scroll to the top</string>

@ -349,6 +349,7 @@
<string name="swap_sort">Ordem ascendente/descendente</string> <string name="swap_sort">Ordem ascendente/descendente</string>
<string name="sort">Ordenar</string> <string name="sort">Ordenar</string>
<string name="sort_auto">Ordenar automaticamente</string> <string name="sort_auto">Ordenar automaticamente</string>
<string name="sort_default">Ordenar por defecto</string>
<string name="sort_manual">Ordenar manualmente</string> <string name="sort_manual">Ordenar manualmente</string>
<string name="sort_by_name">Ordenar por nome</string> <string name="sort_by_name">Ordenar por nome</string>
<string name="go_to_top">Vá ao topo</string> <string name="go_to_top">Vá ao topo</string>

@ -348,6 +348,7 @@
<string name="swap_sort">倒序-順序</string> <string name="swap_sort">倒序-順序</string>
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="sort_auto">智能排序</string> <string name="sort_auto">智能排序</string>
<string name="sort_default">默認排序</string>
<string name="sort_manual">手動排序</string> <string name="sort_manual">手動排序</string>
<string name="sort_by_name">名稱排序</string> <string name="sort_by_name">名稱排序</string>
<string name="go_to_top">滾動到頂部</string> <string name="go_to_top">滾動到頂部</string>

@ -350,6 +350,7 @@
<string name="swap_sort">倒序-順序</string> <string name="swap_sort">倒序-順序</string>
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="sort_auto">智慧排序</string> <string name="sort_auto">智慧排序</string>
<string name="sort_default">默認排序</string>
<string name="sort_manual">手動排序</string> <string name="sort_manual">手動排序</string>
<string name="sort_by_name">名稱排序</string> <string name="sort_by_name">名稱排序</string>
<string name="go_to_top">滾動到頂部</string> <string name="go_to_top">滾動到頂部</string>

@ -351,6 +351,7 @@
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="sort_auto">智能排序</string> <string name="sort_auto">智能排序</string>
<string name="sort_manual">手动排序</string> <string name="sort_manual">手动排序</string>
<string name="sort_default">默认排序</string>
<string name="sort_by_name">名称排序</string> <string name="sort_by_name">名称排序</string>
<string name="go_to_top">滚动到顶部</string> <string name="go_to_top">滚动到顶部</string>
<string name="go_to_bottom">滚动到底部</string> <string name="go_to_bottom">滚动到底部</string>

@ -352,6 +352,7 @@
<string name="sort">Sort</string> <string name="sort">Sort</string>
<string name="sort_auto">Sort automatically</string> <string name="sort_auto">Sort automatically</string>
<string name="sort_manual">Sort manually</string> <string name="sort_manual">Sort manually</string>
<string name="sort_default">Sort default</string>
<string name="sort_by_name">Sort by name</string> <string name="sort_by_name">Sort by name</string>
<string name="go_to_top">Scroll to the top</string> <string name="go_to_top">Scroll to the top</string>
<string name="go_to_bottom">Scroll to the bottom</string> <string name="go_to_bottom">Scroll to the bottom</string>

Loading…
Cancel
Save