mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
ccac347519
commit
ce2e8bfc22
@ -66,7 +66,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
private var sourceFlowJob: Job? = null
|
||||
private val groups = linkedSetOf<String>()
|
||||
private var groupMenu: SubMenu? = null
|
||||
private var sort = Sort.Default
|
||||
override var sort = BookSourceSort.Default
|
||||
private set
|
||||
override var sortAscending = true
|
||||
private set
|
||||
private var snackBar: Snackbar? = null
|
||||
@ -157,43 +158,43 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
|
||||
R.id.menu_sort_manual -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Default
|
||||
sort = BookSourceSort.Default
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_auto -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Weight
|
||||
sort = BookSourceSort.Weight
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_name -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Name
|
||||
sort = BookSourceSort.Name
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_url -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Url
|
||||
sort = BookSourceSort.Url
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_time -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Update
|
||||
sort = BookSourceSort.Update
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_respondTime -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Respond
|
||||
sort = BookSourceSort.Respond
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
R.id.menu_sort_enable -> {
|
||||
item.isChecked = true
|
||||
sort = Sort.Enable
|
||||
sort = BookSourceSort.Enable
|
||||
upBookSource(searchView.query?.toString())
|
||||
}
|
||||
|
||||
@ -279,15 +280,15 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}.conflate().map { data ->
|
||||
if (sortAscending) {
|
||||
when (sort) {
|
||||
Sort.Weight -> data.sortedBy { it.weight }
|
||||
Sort.Name -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Weight -> data.sortedBy { it.weight }
|
||||
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
||||
o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
}
|
||||
|
||||
Sort.Url -> data.sortedBy { it.bookSourceUrl }
|
||||
Sort.Update -> data.sortedByDescending { it.lastUpdateTime }
|
||||
Sort.Respond -> data.sortedBy { it.respondTime }
|
||||
Sort.Enable -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Url -> data.sortedBy { it.bookSourceUrl }
|
||||
BookSourceSort.Update -> data.sortedByDescending { it.lastUpdateTime }
|
||||
BookSourceSort.Respond -> data.sortedBy { it.respondTime }
|
||||
BookSourceSort.Enable -> data.sortedWith { o1, o2 ->
|
||||
var sort = -o1.enabled.compareTo(o2.enabled)
|
||||
if (sort == 0) {
|
||||
sort = o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
@ -299,15 +300,15 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
} else {
|
||||
when (sort) {
|
||||
Sort.Weight -> data.sortedByDescending { it.weight }
|
||||
Sort.Name -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Weight -> data.sortedByDescending { it.weight }
|
||||
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
||||
o2.bookSourceName.cnCompare(o1.bookSourceName)
|
||||
}
|
||||
|
||||
Sort.Url -> data.sortedByDescending { it.bookSourceUrl }
|
||||
Sort.Update -> data.sortedBy { it.lastUpdateTime }
|
||||
Sort.Respond -> data.sortedByDescending { it.respondTime }
|
||||
Sort.Enable -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Url -> data.sortedByDescending { it.bookSourceUrl }
|
||||
BookSourceSort.Update -> data.sortedBy { it.lastUpdateTime }
|
||||
BookSourceSort.Respond -> data.sortedByDescending { it.respondTime }
|
||||
BookSourceSort.Enable -> data.sortedWith { o1, o2 ->
|
||||
var sort = o1.enabled.compareTo(o2.enabled)
|
||||
if (sort == 0) {
|
||||
sort = o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
@ -322,7 +323,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
AppLog.put("书源界面更新书源出错", it)
|
||||
}.conflate().collect { data ->
|
||||
adapter.setItems(data, adapter.diffItemCallback)
|
||||
itemTouchCallback.isCanDrag = sort == Sort.Default
|
||||
itemTouchCallback.isCanDrag = sort == BookSourceSort.Default
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
@ -699,7 +700,4 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
}
|
||||
|
||||
enum class Sort {
|
||||
Default, Name, Url, Weight, Update, Enable, Respond
|
||||
}
|
||||
}
|
@ -152,6 +152,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
||||
val source = getItem(position) ?: return
|
||||
val popupMenu = PopupMenu(context, view)
|
||||
popupMenu.inflate(R.menu.book_source_item)
|
||||
popupMenu.menu.findItem(R.id.menu_top).isVisible = callBack.sort == BookSourceSort.Default
|
||||
popupMenu.menu.findItem(R.id.menu_bottom).isVisible =
|
||||
callBack.sort == BookSourceSort.Default
|
||||
val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore)
|
||||
if (!source.hasExploreUrl) {
|
||||
qyMenu.isVisible = false
|
||||
@ -327,6 +330,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
val sort: BookSourceSort
|
||||
val sortAscending: Boolean
|
||||
fun del(bookSource: BookSourcePart)
|
||||
fun edit(bookSource: BookSourcePart)
|
||||
|
@ -0,0 +1,5 @@
|
||||
package io.legado.app.ui.book.source.manage
|
||||
|
||||
enum class BookSourceSort {
|
||||
Default, Name, Url, Weight, Update, Enable, Respond
|
||||
}
|
@ -9,7 +9,6 @@ import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.BookSourcePart
|
||||
import io.legado.app.data.entities.toBookSource
|
||||
import io.legado.app.help.config.SourceConfig
|
||||
import io.legado.app.ui.book.source.manage.BookSourceActivity.Sort
|
||||
import io.legado.app.utils.*
|
||||
import splitties.init.appCtx
|
||||
import java.io.BufferedOutputStream
|
||||
@ -145,7 +144,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
adapter: BookSourceAdapter,
|
||||
searchKey: String?,
|
||||
sortAscending: Boolean,
|
||||
sort: Sort,
|
||||
sort: BookSourceSort,
|
||||
success: (file: File) -> Unit
|
||||
) {
|
||||
execute {
|
||||
@ -169,7 +168,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
private fun getBookSources(
|
||||
searchKey: String?,
|
||||
sortAscending: Boolean,
|
||||
sort: Sort
|
||||
sort: BookSourceSort
|
||||
): List<BookSource> {
|
||||
return when {
|
||||
searchKey.isNullOrEmpty() -> {
|
||||
@ -202,15 +201,15 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
}.let { data ->
|
||||
if (sortAscending) when (sort) {
|
||||
Sort.Weight -> data.sortedBy { it.weight }
|
||||
Sort.Name -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Weight -> data.sortedBy { it.weight }
|
||||
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
||||
o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
}
|
||||
|
||||
Sort.Url -> data.sortedBy { it.bookSourceUrl }
|
||||
Sort.Update -> data.sortedByDescending { it.lastUpdateTime }
|
||||
Sort.Respond -> data.sortedBy { it.respondTime }
|
||||
Sort.Enable -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Url -> data.sortedBy { it.bookSourceUrl }
|
||||
BookSourceSort.Update -> data.sortedByDescending { it.lastUpdateTime }
|
||||
BookSourceSort.Respond -> data.sortedBy { it.respondTime }
|
||||
BookSourceSort.Enable -> data.sortedWith { o1, o2 ->
|
||||
var sortNum = -o1.enabled.compareTo(o2.enabled)
|
||||
if (sortNum == 0) {
|
||||
sortNum = o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
@ -221,15 +220,15 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
else -> data
|
||||
}
|
||||
else when (sort) {
|
||||
Sort.Weight -> data.sortedByDescending { it.weight }
|
||||
Sort.Name -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Weight -> data.sortedByDescending { it.weight }
|
||||
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
||||
o2.bookSourceName.cnCompare(o1.bookSourceName)
|
||||
}
|
||||
|
||||
Sort.Url -> data.sortedByDescending { it.bookSourceUrl }
|
||||
Sort.Update -> data.sortedBy { it.lastUpdateTime }
|
||||
Sort.Respond -> data.sortedByDescending { it.respondTime }
|
||||
Sort.Enable -> data.sortedWith { o1, o2 ->
|
||||
BookSourceSort.Url -> data.sortedByDescending { it.bookSourceUrl }
|
||||
BookSourceSort.Update -> data.sortedBy { it.lastUpdateTime }
|
||||
BookSourceSort.Respond -> data.sortedByDescending { it.respondTime }
|
||||
BookSourceSort.Enable -> data.sortedWith { o1, o2 ->
|
||||
var sortNum = o1.enabled.compareTo(o2.enabled)
|
||||
if (sortNum == 0) {
|
||||
sortNum = o1.bookSourceName.cnCompare(o2.bookSourceName)
|
||||
|
Loading…
Reference in New Issue
Block a user