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