Merge pull request #2021 from qianfanguojin/master

添加 WebDav 书籍的排序功能,更加详细的横竖屏单双页切换方式
pull/2037/head
kunfei 2 years ago committed by GitHub
commit d668ecc881
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  3. 93
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  4. 5
      app/src/main/res/drawable/ic_baseline_sort_24.xml
  5. 35
      app/src/main/res/menu/book_remote.xml
  6. 1
      app/src/main/res/values-es-rES/strings.xml
  7. 1
      app/src/main/res/values-ja-rJP/strings.xml
  8. 1
      app/src/main/res/values-pt-rBR/strings.xml
  9. 1
      app/src/main/res/values-zh-rHK/strings.xml
  10. 1
      app/src/main/res/values-zh-rTW/strings.xml
  11. 6
      app/src/main/res/values-zh/arrays.xml
  12. 1
      app/src/main/res/values-zh/strings.xml
  13. 6
      app/src/main/res/values/array_values.xml
  14. 6
      app/src/main/res/values/arrays.xml
  15. 1
      app/src/main/res/values/strings.xml
  16. 9
      app/src/main/res/xml/pref_config_read.xml

@ -312,8 +312,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val loadCoverOnlyWifi = appCtx.getPrefBoolean(PreferKey.loadCoverOnlyWifi, false) val loadCoverOnlyWifi = appCtx.getPrefBoolean(PreferKey.loadCoverOnlyWifi, false)
val doublePageHorizontal: Boolean val doublePageHorizontal: String?
get() = appCtx.getPrefBoolean(PreferKey.doublePageHorizontal, true) get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
var searchGroup: String var searchGroup: String
get() = appCtx.getPrefString("searchGroup") ?: "" get() = appCtx.getPrefString("searchGroup") ?: ""

@ -612,9 +612,15 @@ object ChapterProvider {
* 更新绘制尺寸 * 更新绘制尺寸
*/ */
fun upLayout() { fun upLayout() {
doublePage = (viewWidth > viewHeight || appCtx.isPad) when(AppConfig.doublePageHorizontal){
&& ReadBook.pageAnim() != 3 "0" -> doublePage = false
&& AppConfig.doublePageHorizontal "1" -> doublePage = true
"2" -> {
doublePage = (viewWidth > viewHeight)
&& ReadBook.pageAnim() != 3
}
}
if (viewWidth > 0 && viewHeight > 0) { if (viewWidth > 0 && viewHeight > 0) {
paddingLeft = ReadBookConfig.paddingLeft.dpToPx() paddingLeft = ReadBookConfig.paddingLeft.dpToPx()
paddingTop = ReadBookConfig.paddingTop.dpToPx() paddingTop = ReadBookConfig.paddingTop.dpToPx()

@ -3,6 +3,7 @@ package io.legado.app.ui.book.remote
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -12,13 +13,19 @@ import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.remote.manager.RemoteBookWebDav 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.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.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
/** /**
* 展示远程书籍 * 展示远程书籍
@ -32,7 +39,9 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
override val viewModel by viewModels<RemoteBookViewModel>() override val viewModel by viewModels<RemoteBookViewModel>()
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 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()
@ -48,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()
@ -75,10 +133,33 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
when (item.itemId) { when (item.itemId) {
R.id.menu_refresh -> upPath() R.id.menu_refresh -> upPath()
R.id.menu_log -> showDialogFragment<AppLogDialog>() R.id.menu_log -> showDialogFragment<AppLogDialog>()
R.id.menu_sort_auto -> {
item.isChecked = true
toastOnUi("menu_sort_auto")
sortCheck(Sort.Default)
upPath()
}
R.id.menu_sort_name -> {
item.isChecked = true
toastOnUi("menu_sort_name")
sortCheck(Sort.Name)
upPath()
}
R.id.menu_sort_time -> {
item.isChecked = true
toastOnUi("menu_sort_time")
sortCheck(Sort.UpdateTime)
upPath()
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
groupMenu = menu.findItem(R.id.menu_sort)?.subMenu
groupMenu?.setGroupCheckable(R.id.menu_group_sort, true, true)
return super.onPrepareOptionsMenu(menu)
}
override fun revertSelection() { override fun revertSelection() {
adapter.revertSelection() adapter.revertSelection()
} }
@ -139,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
}
} }

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>

@ -9,11 +9,44 @@
android:icon="@drawable/ic_refresh_black_24dp" android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/refresh" android:title="@string/refresh"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/menu_sort"
android:icon="@drawable/ic_baseline_sort_24"
android:title="@string/sort"
app:showAsAction="always"
tools:ignore="AlwaysShowAction">
<menu>
<group
android:id="@+id/menu_group_sort"
android:checkableBehavior="single">
<item
android:id="@+id/menu_sort_default"
android:checkable="true"
android:checked="true"
android:title="@string/sort_default" />
<item
android:id="@+id/menu_sort_name"
android:checkable="true"
android:title="@string/sort_by_name" />
<item
android:id="@+id/menu_sort_time"
android:checkable="true"
android:title="@string/sort_by_lastUpdateTime" />
</group>
</menu>
</item>
<item <item
android:id="@+id/menu_log" android:id="@+id/menu_log"
android:title="@string/log"
android:icon="@drawable/ic_cfg_about" android:icon="@drawable/ic_cfg_about"
android:title="@string/log"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

@ -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>

@ -25,6 +25,12 @@
<item>E-Ink(墨水屏)</item> <item>E-Ink(墨水屏)</item>
</string-array> </string-array>
<string-array name="double_page_title">
<item>全局单页</item>
<item>全局双页</item>
<item>横屏双页/竖屏单页</item>
</string-array>
<string-array name="NavBarColors"> <string-array name="NavBarColors">
<item>自动</item> <item>自动</item>
<item>黑色</item> <item>黑色</item>

@ -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>

@ -33,6 +33,12 @@
<item>3</item> <item>3</item>
</string-array> </string-array>
<string-array name="double_page_value">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="language_value"> <string-array name="language_value">
<item>auto</item> <item>auto</item>
<item>zh</item> <item>zh</item>

@ -61,6 +61,12 @@
<item>@string/screen_sensor</item> <item>@string/screen_sensor</item>
</string-array> </string-array>
<string-array name="double_page_title">
<item>全局单页</item>
<item>全局双页</item>
<item>横屏双页 竖屏单页</item>
</string-array>
<string-array name="icon_names" tools:ignore="Typos"> <string-array name="icon_names" tools:ignore="Typos">
<item>iconMain</item> <item>iconMain</item>
<item>icon1</item> <item>icon1</item>

@ -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>

@ -41,13 +41,16 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.NameListPreference
android:defaultValue="true"
android:title="@string/double_page_horizontal"
android:key="doublePageHorizontal" android:key="doublePageHorizontal"
android:defaultValue="0"
android:title="@string/double_page_horizontal"
android:entries="@array/double_page_title"
android:entryValues="@array/double_page_value"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/use_zh_layout" android:title="@string/use_zh_layout"

Loading…
Cancel
Save