Skip to content

Commit

Permalink
[fix] Fix stickerslist screen data query bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Dec 13, 2023
1 parent 39861ae commit caf2a04
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class SearchRepository @Inject constructor(
}
}

fun requestStickerWithTagsListWithAllSearchDomain(keyword: String): Flow<List<StickerWithTags>> {
return flow { emit(genSql(k = keyword, useSearchDomain = { _, _ -> true })) }
.flowOn(Dispatchers.IO)
.flatMapConcat {
stickerDao.getStickerWithTagsList(it)
.flowOn(Dispatchers.IO)
.distinctUntilChanged()
}
}

fun requestStickerWithTagsList(): Flow<List<StickerWithTags>> {
return appContext.dataStore.data
.debounce(70)
Expand Down Expand Up @@ -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)
Expand All @@ -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"
)
}
Expand All @@ -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 =
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down

0 comments on commit caf2a04

Please sign in to comment.