|
|
@ -130,6 +130,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
sortCheck(Sort.Update) |
|
|
|
sortCheck(Sort.Update) |
|
|
|
initLiveDataBookSource(searchView.query?.toString()) |
|
|
|
initLiveDataBookSource(searchView.query?.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
R.id.menu_sort_enable -> { |
|
|
|
|
|
|
|
item.isChecked = true |
|
|
|
|
|
|
|
sortCheck(Sort.Enable) |
|
|
|
|
|
|
|
initLiveDataBookSource(searchView.query?.toString()) |
|
|
|
|
|
|
|
} |
|
|
|
R.id.menu_enabled_group -> { |
|
|
|
R.id.menu_enabled_group -> { |
|
|
|
searchView.setQuery(getString(R.string.enabled), true) |
|
|
|
searchView.setQuery(getString(R.string.enabled), true) |
|
|
|
} |
|
|
|
} |
|
|
@ -187,8 +192,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
App.db.bookSourceDao.liveDataSearch("%$searchKey%") |
|
|
|
App.db.bookSourceDao.liveDataSearch("%$searchKey%") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.apply { |
|
|
|
bookSourceLiveDate?.observe(this, { data -> |
|
|
|
observe(this@BookSourceActivity, { data -> |
|
|
|
val sourceList = |
|
|
|
val sourceList = |
|
|
|
if (sortAscending) when (sort) { |
|
|
|
if (sortAscending) when (sort) { |
|
|
|
Sort.Weight -> data.sortedBy { it.weight } |
|
|
|
Sort.Weight -> data.sortedBy { it.weight } |
|
|
@ -197,6 +202,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
} |
|
|
|
} |
|
|
|
Sort.Url -> data.sortedBy { it.bookSourceUrl } |
|
|
|
Sort.Url -> data.sortedBy { it.bookSourceUrl } |
|
|
|
Sort.Update -> data.sortedByDescending { it.lastUpdateTime } |
|
|
|
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 |
|
|
|
else -> data |
|
|
|
} |
|
|
|
} |
|
|
|
else when (sort) { |
|
|
|
else when (sort) { |
|
|
@ -206,11 +218,19 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
} |
|
|
|
} |
|
|
|
Sort.Url -> data.sortedByDescending { it.bookSourceUrl } |
|
|
|
Sort.Url -> data.sortedByDescending { it.bookSourceUrl } |
|
|
|
Sort.Update -> data.sortedBy { it.lastUpdateTime } |
|
|
|
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() |
|
|
|
else -> data.reversed() |
|
|
|
} |
|
|
|
} |
|
|
|
adapter.setItems(sourceList, adapter.diffItemCallback) |
|
|
|
adapter.setItems(sourceList, adapter.diffItemCallback) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun showHelp() { |
|
|
|
private fun showHelp() { |
|
|
|
val text = String(assets.open("help/SourceMBookHelp.md").readBytes()) |
|
|
|
val text = String(assets.open("help/SourceMBookHelp.md").readBytes()) |
|
|
@ -483,6 +503,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum class Sort { |
|
|
|
enum class Sort { |
|
|
|
Default, Name, Url, Weight, Update |
|
|
|
Default, Name, Url, Weight, Update, Enable |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |