|
|
|
@ -130,6 +130,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
|
sortCheck(Sort.Update) |
|
|
|
|
initLiveDataBookSource(searchView.query?.toString()) |
|
|
|
|
} |
|
|
|
|
R.id.menu_sort_enable -> { |
|
|
|
|
item.isChecked = true |
|
|
|
|
sortCheck(Sort.Enable) |
|
|
|
|
initLiveDataBookSource(searchView.query?.toString()) |
|
|
|
|
} |
|
|
|
|
R.id.menu_enabled_group -> { |
|
|
|
|
searchView.setQuery(getString(R.string.enabled), true) |
|
|
|
|
} |
|
|
|
@ -187,29 +192,44 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
|
else -> { |
|
|
|
|
App.db.bookSourceDao.liveDataSearch("%$searchKey%") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
bookSourceLiveDate?.observe(this, { data -> |
|
|
|
|
val sourceList = |
|
|
|
|
if (sortAscending) when (sort) { |
|
|
|
|
Sort.Weight -> data.sortedBy { it.weight } |
|
|
|
|
Sort.Name -> data.sortedWith { o1, o2 -> |
|
|
|
|
o1.bookSourceName.cnCompare(o2.bookSourceName) |
|
|
|
|
}.apply { |
|
|
|
|
observe(this@BookSourceActivity, { data -> |
|
|
|
|
val sourceList = |
|
|
|
|
if (sortAscending) when (sort) { |
|
|
|
|
Sort.Weight -> data.sortedBy { it.weight } |
|
|
|
|
Sort.Name -> data.sortedWith { o1, o2 -> |
|
|
|
|
o1.bookSourceName.cnCompare(o2.bookSourceName) |
|
|
|
|
} |
|
|
|
|
Sort.Url -> data.sortedBy { it.bookSourceUrl } |
|
|
|
|
Sort.Update -> data.sortedByDescending { it.lastUpdateTime } |
|
|
|
|
Sort.Enable -> data.sortedWith { o1, o2 -> |
|
|
|
|
var sort = -o1.enabled.compareTo(o2.enabled) |
|
|
|
|
if (sort == 0) { |
|
|
|
|
sort = o1.bookSourceName.cnCompare(o2.bookSourceName) |
|
|
|
|
} |
|
|
|
|
sort |
|
|
|
|
} |
|
|
|
|
else -> data |
|
|
|
|
} |
|
|
|
|
Sort.Url -> data.sortedBy { it.bookSourceUrl } |
|
|
|
|
Sort.Update -> data.sortedByDescending { it.lastUpdateTime } |
|
|
|
|
else -> data |
|
|
|
|
} |
|
|
|
|
else when (sort) { |
|
|
|
|
Sort.Weight -> data.sortedByDescending { it.weight } |
|
|
|
|
Sort.Name -> data.sortedWith { o1, o2 -> |
|
|
|
|
o2.bookSourceName.cnCompare(o1.bookSourceName) |
|
|
|
|
else when (sort) { |
|
|
|
|
Sort.Weight -> data.sortedByDescending { it.weight } |
|
|
|
|
Sort.Name -> data.sortedWith { o1, o2 -> |
|
|
|
|
o2.bookSourceName.cnCompare(o1.bookSourceName) |
|
|
|
|
} |
|
|
|
|
Sort.Url -> data.sortedByDescending { it.bookSourceUrl } |
|
|
|
|
Sort.Update -> data.sortedBy { it.lastUpdateTime } |
|
|
|
|
Sort.Enable -> data.sortedWith { o1, o2 -> |
|
|
|
|
var sort = o1.enabled.compareTo(o2.enabled) |
|
|
|
|
if (sort == 0) { |
|
|
|
|
sort = o1.bookSourceName.cnCompare(o2.bookSourceName) |
|
|
|
|
} |
|
|
|
|
sort |
|
|
|
|
} |
|
|
|
|
else -> data.reversed() |
|
|
|
|
} |
|
|
|
|
Sort.Url -> data.sortedByDescending { it.bookSourceUrl } |
|
|
|
|
Sort.Update -> data.sortedBy { it.lastUpdateTime } |
|
|
|
|
else -> data.reversed() |
|
|
|
|
} |
|
|
|
|
adapter.setItems(sourceList, adapter.diffItemCallback) |
|
|
|
|
}) |
|
|
|
|
adapter.setItems(sourceList, adapter.diffItemCallback) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showHelp() { |
|
|
|
@ -483,6 +503,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum class Sort { |
|
|
|
|
Default, Name, Url, Weight, Update |
|
|
|
|
Default, Name, Url, Weight, Update, Enable |
|
|
|
|
} |
|
|
|
|
} |