按启用禁用排序

pull/801/head
gedoor 4 years ago
parent 3d09170ad4
commit 52966de8d3
  1. 64
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 6
      app/src/main/res/menu/book_source.xml
  3. 1
      app/src/main/res/values-zh-rHK/strings.xml
  4. 1
      app/src/main/res/values-zh-rTW/strings.xml
  5. 1
      app/src/main/res/values-zh/strings.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -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,29 +192,44 @@ 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 }
Sort.Name -> data.sortedWith { o1, o2 -> Sort.Name -> data.sortedWith { o1, o2 ->
o1.bookSourceName.cnCompare(o2.bookSourceName) 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 } else when (sort) {
Sort.Update -> data.sortedByDescending { it.lastUpdateTime } Sort.Weight -> data.sortedByDescending { it.weight }
else -> data Sort.Name -> data.sortedWith { o1, o2 ->
} o2.bookSourceName.cnCompare(o1.bookSourceName)
else when (sort) { }
Sort.Weight -> data.sortedByDescending { it.weight } Sort.Url -> data.sortedByDescending { it.bookSourceUrl }
Sort.Name -> data.sortedWith { o1, o2 -> Sort.Update -> data.sortedBy { it.lastUpdateTime }
o2.bookSourceName.cnCompare(o1.bookSourceName) 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 } adapter.setItems(sourceList, adapter.diffItemCallback)
Sort.Update -> data.sortedBy { it.lastUpdateTime } })
else -> data.reversed() }
}
adapter.setItems(sourceList, adapter.diffItemCallback)
})
} }
private fun showHelp() { private fun showHelp() {
@ -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
} }
} }

@ -50,6 +50,12 @@
android:id="@+id/menu_sort_time" android:id="@+id/menu_sort_time"
android:checkable="true" android:checkable="true"
android:title="@string/sort_by_lastUpdateTime" /> android:title="@string/sort_by_lastUpdateTime" />
<item
android:id="@+id/menu_sort_enable"
android:checkable="true"
android:title="@string/sort_enable" />
</group> </group>
</menu> </menu>

@ -799,5 +799,6 @@
<string name="import_bookshelf">导入书单</string> <string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string> <string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string> <string name="pre_download_s">预先下载10章正文</string>
<string name="sort_enable">启用排序</string>
</resources> </resources>

@ -800,5 +800,6 @@
<string name="import_bookshelf">导入书单</string> <string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string> <string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string> <string name="pre_download_s">预先下载10章正文</string>
<string name="sort_enable">启用排序</string>
</resources> </resources>

@ -803,5 +803,6 @@
<string name="import_bookshelf">导入书单</string> <string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string> <string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string> <string name="pre_download_s">预先下载10章正文</string>
<string name="sort_enable">启用排序</string>
</resources> </resources>

@ -806,5 +806,6 @@
<string name="import_bookshelf">导入书单</string> <string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string> <string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string> <string name="pre_download_s">预先下载10章正文</string>
<string name="sort_enable">启用排序</string>
</resources> </resources>

Loading…
Cancel
Save