优化排序号相同导致的排序问题
This commit is contained in:
@@ -54,9 +54,6 @@ interface BookSourceDao {
|
|||||||
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
|
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
|
||||||
fun flowExplore(): Flow<List<BookSource>>
|
fun flowExplore(): Flow<List<BookSource>>
|
||||||
|
|
||||||
// @Query("select * from book_sources where enabledReview = 1 order by customOrder asc")
|
|
||||||
// fun flowReview(): Flow<List<BookSource>>
|
|
||||||
|
|
||||||
@Query("select * from book_sources where loginUrl is not null and loginUrl != ''")
|
@Query("select * from book_sources where loginUrl is not null and loginUrl != ''")
|
||||||
fun flowLogin(): Flow<List<BookSource>>
|
fun flowLogin(): Flow<List<BookSource>>
|
||||||
|
|
||||||
@@ -161,6 +158,9 @@ interface BookSourceDao {
|
|||||||
@get:Query("select max(customOrder) from book_sources")
|
@get:Query("select max(customOrder) from book_sources")
|
||||||
val maxOrder: Int
|
val maxOrder: Int
|
||||||
|
|
||||||
|
@Query("select count(*) from (select customOrder, count(customOrder) from book_sources group by customOrder having count(customOrder) > 1)")
|
||||||
|
fun sameSortNumberSize(): Int
|
||||||
|
|
||||||
private fun dealGroups(list: List<String>): List<String> {
|
private fun dealGroups(list: List<String>): List<String> {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = linkedSetOf<String>()
|
||||||
list.forEach {
|
list.forEach {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
override val viewModel by viewModels<BookSourceViewModel>()
|
override val viewModel by viewModels<BookSourceViewModel>()
|
||||||
private val importRecordKey = "bookSourceRecordKey"
|
private val importRecordKey = "bookSourceRecordKey"
|
||||||
private val adapter by lazy { BookSourceAdapter(this, this) }
|
private val adapter by lazy { BookSourceAdapter(this, this) }
|
||||||
|
private val itemTouchCallback by lazy { ItemTouchCallback(adapter) }
|
||||||
private val searchView: SearchView by lazy {
|
private val searchView: SearchView by lazy {
|
||||||
binding.titleBar.findViewById(R.id.search_view)
|
binding.titleBar.findViewById(R.id.search_view)
|
||||||
}
|
}
|
||||||
@@ -197,8 +198,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
|
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
|
||||||
dragSelectTouchHelper.activeSlideSelect()
|
dragSelectTouchHelper.activeSlideSelect()
|
||||||
// Note: need judge selection first, so add ItemTouchHelper after it.
|
// Note: need judge selection first, so add ItemTouchHelper after it.
|
||||||
val itemTouchCallback = ItemTouchCallback(adapter)
|
|
||||||
itemTouchCallback.isCanDrag = true
|
|
||||||
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
|
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +275,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
|
||||||
delay(500)
|
delay(500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,19 @@ import java.io.FileOutputStream
|
|||||||
*/
|
*/
|
||||||
class BookSourceViewModel(application: Application) : BaseViewModel(application) {
|
class BookSourceViewModel(application: Application) : BaseViewModel(application) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
execute {
|
||||||
|
val sameSortNumberSize = appDb.bookSourceDao.sameSortNumberSize()
|
||||||
|
if (sameSortNumberSize > 0) {
|
||||||
|
val sources = appDb.bookSourceDao.all
|
||||||
|
sources.forEachIndexed { index, bookSource ->
|
||||||
|
bookSource.customOrder = index
|
||||||
|
appDb.bookSourceDao.update(bookSource)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun topSource(vararg sources: BookSource) {
|
fun topSource(vararg sources: BookSource) {
|
||||||
execute {
|
execute {
|
||||||
sources.sortBy { it.customOrder }
|
sources.sortBy { it.customOrder }
|
||||||
|
|||||||
Reference in New Issue
Block a user