From caf2a04d6724ea244227063877b135d2b30831d5 Mon Sep 17 00:00:00 2001 From: SkyD666 Date: Wed, 13 Dec 2023 22:57:02 +0800 Subject: [PATCH] [fix] Fix stickerslist screen data query bug --- app/build.gradle | 2 +- .../model/respository/SearchRepository.kt | 36 ++++++++++++++----- .../stickerslist/StickersListViewModel.kt | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f72465e..c25898c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,7 +22,7 @@ android { minSdk 24 targetSdk 34 versionCode 55 - versionName "2.0-alpha11" + versionName "2.0-alpha12" flavorDimensions = ["versionName"] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/skyd/rays/model/respository/SearchRepository.kt b/app/src/main/java/com/skyd/rays/model/respository/SearchRepository.kt index 6293bf6..d079290 100644 --- a/app/src/main/java/com/skyd/rays/model/respository/SearchRepository.kt +++ b/app/src/main/java/com/skyd/rays/model/respository/SearchRepository.kt @@ -50,6 +50,16 @@ class SearchRepository @Inject constructor( } } + fun requestStickerWithTagsListWithAllSearchDomain(keyword: String): Flow> { + return flow { emit(genSql(k = keyword, useSearchDomain = { _, _ -> true })) } + .flowOn(Dispatchers.IO) + .flatMapConcat { + stickerDao.getStickerWithTagsList(it) + .flowOn(Dispatchers.IO) + .distinctUntilChanged() + } + } + fun requestStickerWithTagsList(): Flow> { return appContext.dataStore.data .debounce(70) @@ -221,10 +231,15 @@ class SearchRepository @Inject constructor( val searchDomainDao: SearchDomainDao } - fun genSql(k: String): SimpleSQLiteQuery { - val hiltEntryPoint = EntryPointAccessors.fromApplication( - appContext, HomeRepositoryEntryPoint::class.java - ) + fun genSql( + k: String, + useSearchDomain: (tableName: String, columnName: String) -> Boolean = + { tableName, columnName -> + EntryPointAccessors.fromApplication( + appContext, HomeRepositoryEntryPoint::class.java + ).searchDomainDao.getSearchDomain(tableName, columnName) + }, + ): SimpleSQLiteQuery { // 是否使用多个关键字并集查询 val intersectSearchBySpace = appContext.dataStore.getOrDefault(IntersectSearchBySpacePreference) @@ -236,7 +251,7 @@ class SearchRepository @Inject constructor( if (index > 0) append("INTERSECT \n") append( "SELECT * FROM $STICKER_TABLE_NAME WHERE ${ - getFilter(s, hiltEntryPoint.searchDomainDao) + getFilter(k = s, useSearchDomain = useSearchDomain) } \n" ) } @@ -245,13 +260,16 @@ class SearchRepository @Inject constructor( } else { SimpleSQLiteQuery( "SELECT * FROM $STICKER_TABLE_NAME WHERE ${ - getFilter(k, hiltEntryPoint.searchDomainDao) + getFilter(k = k, useSearchDomain = useSearchDomain) }" ) } } - private fun getFilter(k: String, searchDomainDao: SearchDomainDao): String { + private fun getFilter( + k: String, + useSearchDomain: (tableName: String, columnName: String) -> Boolean, + ): String { if (k.isBlank()) return "1" val useRegexSearch = @@ -274,7 +292,7 @@ class SearchRepository @Inject constructor( if (table.first == STICKER_TABLE_NAME) { for (column in columns) { - if (!searchDomainDao.getSearchDomain(table.first, column.first)) { + if (!useSearchDomain(table.first, column.first)) { continue } filter += if (useRegexSearch) { @@ -288,7 +306,7 @@ class SearchRepository @Inject constructor( var subSelect = "(SELECT DISTINCT ${TagBean.STICKER_UUID_COLUMN} FROM ${table.first} WHERE 0 " for (column in columns) { - if (!searchDomainDao.getSearchDomain(table.first, column.first)) { + if (!useSearchDomain(table.first, column.first)) { continue } subSelect += if (useRegexSearch) { diff --git a/app/src/main/java/com/skyd/rays/ui/screen/stickerslist/StickersListViewModel.kt b/app/src/main/java/com/skyd/rays/ui/screen/stickerslist/StickersListViewModel.kt index 58a532c..ab2762b 100644 --- a/app/src/main/java/com/skyd/rays/ui/screen/stickerslist/StickersListViewModel.kt +++ b/app/src/main/java/com/skyd/rays/ui/screen/stickerslist/StickersListViewModel.kt @@ -56,7 +56,7 @@ class StickersListViewModel @Inject constructor( is StickersListIntent.GetStickersList -> intent.query is StickersListIntent.RefreshStickersList -> intent.query } - searchRepo.requestStickerWithTagsList(keyword = keyword).map { + searchRepo.requestStickerWithTagsListWithAllSearchDomain(keyword = keyword).map { StickersListPartialStateChange.StickersList.Success(stickerWithTagsList = it) }.startWith(StickersListPartialStateChange.StickersList.Loading) },