Skip to content

Commit 39575de

Browse files
committed
支持删除本地搜索历史记录
resolves #52,resolves #80
1 parent 20327f8 commit 39575de

File tree

5 files changed

+371
-139
lines changed

5 files changed

+371
-139
lines changed

app/shared/src/main/kotlin/dev/aaa1115910/bv/dao/SearchHistoryDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ interface SearchHistoryDao {
2424
@Delete
2525
suspend fun delete(vararg searchHistoryDB: SearchHistoryDB)
2626

27+
@Query("DELETE FROM search_history")
28+
suspend fun deleteAll()
29+
2730
@Update
2831
suspend fun update(searchHistoryDB: SearchHistoryDB)
2932
}

app/shared/src/main/kotlin/dev/aaa1115910/bv/viewmodel/search/SearchInputViewModel.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,20 @@ class SearchInputViewModel(
102102
loadSearchHistories()
103103
}
104104
}
105+
106+
fun deleteSearchHistory(history: SearchHistoryDB) {
107+
logger.fInfo { "Delete search history: ${history.keyword}" }
108+
viewModelScope.launch(Dispatchers.IO) {
109+
db.searchHistoryDao().delete(history)
110+
loadSearchHistories()
111+
}
112+
}
113+
114+
fun deleteAllSearchHistories() {
115+
logger.fInfo { "Delete all search histories" }
116+
viewModelScope.launch(Dispatchers.IO) {
117+
db.searchHistoryDao().deleteAll()
118+
loadSearchHistories()
119+
}
120+
}
105121
}

app/shared/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
<string name="remote_control_panel_demo_tip_up">剧集/合集/分 P 列表</string>
154154

155155
<string name="search_input_history">历史记录</string>
156+
<string name="search_input_history_delete_all_confirm_dialog_cancel_button">手滑了</string>
157+
<string name="search_input_history_delete_all_confirm_dialog_confirm_button">确认删除</string>
158+
<string name="search_input_history_delete_all_confirm_dialog_text">是否删除所有历史记录,该操作无法撤销</string>
159+
<string name="search_input_history_delete_all_confirm_dialog_title">删除所有记录</string>
156160
<string name="search_input_hotword">bilibili 热搜</string>
157161
<string name="search_input_soft_keybord_clear">清空</string>
158162
<string name="search_input_soft_keybord_delete">删除</string>

app/tv/src/main/kotlin/dev/aaa1115910/bv/tv/component/search/SearchKeyword.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import coil.size.Size
2323
fun SearchKeyword(
2424
modifier: Modifier = Modifier,
2525
keyword: String,
26-
icon: String,
26+
leadingIcon: String,
27+
trailingIcon: @Composable() (() -> Unit)? = null,
2728
onClick: () -> Unit
2829
) {
2930
val context = LocalContext.current
@@ -38,14 +39,14 @@ fun SearchKeyword(
3839
.build()
3940
val painter = rememberAsyncImagePainter(
4041
ImageRequest.Builder(context)
41-
.data(data = icon)
42+
.data(data = leadingIcon)
4243
.size(Size.ORIGINAL)
4344
.build(),
4445
imageLoader = imageLoader,
4546
contentScale = ContentScale.FillHeight
4647
)
4748

48-
if (icon != "" && painter.state is AsyncImagePainter.State.Success) {
49+
if (leadingIcon != "" && painter.state is AsyncImagePainter.State.Success) {
4950
DenseListItem(
5051
modifier = modifier,
5152
selected = false,
@@ -63,7 +64,8 @@ fun SearchKeyword(
6364
painter = painter,
6465
contentDescription = null,
6566
)
66-
}
67+
},
68+
trailingContent = trailingIcon
6769
)
6870
} else {
6971
DenseListItem(
@@ -76,7 +78,8 @@ fun SearchKeyword(
7678
maxLines = 1,
7779
overflow = TextOverflow.Ellipsis
7880
)
79-
}
81+
},
82+
trailingContent = trailingIcon
8083
)
8184
}
8285
}

0 commit comments

Comments
 (0)