Support clearing search history
This commit is contained in:
1 parent
0a5600d949
commit
acbe4eafa9
8 files changed
+54
-11
No files matched your search
@@ -31,6 +31,7 @@ import com.hippo.ehviewer.client.data.GalleryDetail
|
||||
import com.hippo.ehviewer.coil.MergeInterceptor
|
||||
import com.hippo.ehviewer.coil.installCronetHttpUriFetcher
|
||||
import com.hippo.ehviewer.dailycheck.checkDawn
|
||||
import com.hippo.ehviewer.dao.SearchDatabase
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
import com.hippo.ehviewer.ktbuilder.cache
|
||||
import com.hippo.ehviewer.ktbuilder.chunker
|
||||
@@ -56,6 +57,7 @@ import moe.tarsin.kt.unreachable
|
||||
import okhttp3.AsyncDns
|
||||
import okhttp3.android.AndroidAsyncDns
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import splitties.arch.room.roomDb
|
||||
import splitties.init.appCtx
|
||||
|
||||
private val lifecycle = ProcessLifecycleOwner.get().lifecycle
|
||||
@@ -202,5 +204,7 @@ class EhApplication : Application(), ImageLoaderFactory {
|
||||
maxSizeBytes(Settings.readCacheSize.coerceIn(320, 5120).toLong() * 1024 * 1024)
|
||||
}
|
||||
}
|
||||
|
||||
val searchDatabase by lazy { roomDb<SearchDatabase>("search_database.db") }
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface SearchDao {
|
||||
@Query("DELETE FROM suggestions")
|
||||
suspend fun clear()
|
||||
|
||||
@Query("DELETE FROM suggestions WHERE `query` = :query")
|
||||
suspend fun deleteQuery(query: String)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.hippo.ehviewer.ui.settings.EhScreen
|
||||
import com.hippo.ehviewer.ui.settings.FilterScreen
|
||||
import com.hippo.ehviewer.ui.settings.LicenseScreen
|
||||
import com.hippo.ehviewer.ui.settings.MyTagsScreen
|
||||
import com.hippo.ehviewer.ui.settings.SecurityScreen
|
||||
import com.hippo.ehviewer.ui.settings.PrivacyScreen
|
||||
import com.hippo.ehviewer.ui.settings.UConfigScreen
|
||||
|
||||
class ConfigureActivity : EhActivity() {
|
||||
@@ -72,8 +72,8 @@ class ConfigureActivity : EhActivity() {
|
||||
composable(LICENSE_SCREEN) {
|
||||
LicenseScreen()
|
||||
}
|
||||
composable(SECURITY_SETTINGS_SCREEN) {
|
||||
SecurityScreen()
|
||||
composable(PRIVACY_SETTINGS_SCREEN) {
|
||||
PrivacyScreen()
|
||||
}
|
||||
composable(ADVANCED_SETTINGS_SCREEN) {
|
||||
AdvancedScreen()
|
||||
@@ -109,7 +109,7 @@ val LocalNavController = compositionLocalOf<NavController> { error("CompositionL
|
||||
const val BASE_SETTINGS_SCREEN = "Base"
|
||||
const val EH_SETTINGS_SCREEN = "Eh"
|
||||
const val DOWNLOAD_SETTINGS_SCREEN = "Download"
|
||||
const val SECURITY_SETTINGS_SCREEN = "Security"
|
||||
const val PRIVACY_SETTINGS_SCREEN = "Privacy"
|
||||
const val ADVANCED_SETTINGS_SCREEN = "Advanced"
|
||||
const val ABOUT_SETTINGS_SCREEN = "About"
|
||||
const val LICENSE_SCREEN = "License"
|
||||
|
||||
@@ -19,12 +19,12 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.search.SearchView
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.hippo.ehviewer.EhApplication.Companion.searchDatabase
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhTagDatabase
|
||||
import com.hippo.ehviewer.dao.Search
|
||||
import com.hippo.ehviewer.dao.SearchDao
|
||||
import com.hippo.ehviewer.dao.SearchDatabase
|
||||
import com.hippo.ehviewer.databinding.ItemSimpleList2Binding
|
||||
import com.hippo.ehviewer.databinding.SceneSearchbarBinding
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
@@ -32,9 +32,6 @@ import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import splitties.arch.room.roomDb
|
||||
|
||||
private val searchDatabase by lazy { roomDb<SearchDatabase>("search_database.db") }
|
||||
|
||||
abstract class SearchBarScene : BaseScene(), ToolBarScene {
|
||||
private var _binding: SceneSearchbarBinding? = null
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.hippo.ehviewer.ui.DOWNLOAD_SETTINGS_SCREEN
|
||||
import com.hippo.ehviewer.ui.EH_SETTINGS_SCREEN
|
||||
import com.hippo.ehviewer.ui.FINISH_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.SECURITY_SETTINGS_SCREEN
|
||||
import com.hippo.ehviewer.ui.PRIVACY_SETTINGS_SCREEN
|
||||
|
||||
@Composable
|
||||
fun BaseScreen() {
|
||||
@@ -59,7 +59,7 @@ fun BaseScreen() {
|
||||
PreferenceHeader(
|
||||
icon = Icons.Default.Security,
|
||||
title = R.string.settings_privacy,
|
||||
childRouteName = SECURITY_SETTINGS_SCREEN,
|
||||
childRouteName = PRIVACY_SETTINGS_SCREEN,
|
||||
)
|
||||
PreferenceHeader(
|
||||
icon = Icons.Default.Adb,
|
||||
|
||||
+32
-1
@@ -7,25 +7,38 @@ import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.hippo.ehviewer.EhApplication.Companion.searchDatabase
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.isAuthenticationSupported
|
||||
import com.hippo.ehviewer.ui.tools.observed
|
||||
import com.hippo.ehviewer.ui.tools.rememberDialogState
|
||||
import com.hippo.ehviewer.ui.tools.rememberedAccessor
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun SecurityScreen() {
|
||||
fun PrivacyScreen() {
|
||||
val navController = LocalNavController.current
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
|
||||
fun launchSnackBar(content: String) = coroutineScope.launch { snackbarHostState.showSnackbar(content) }
|
||||
val dialogState = rememberDialogState()
|
||||
dialogState.Handler()
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
@@ -38,6 +51,7 @@ fun SecurityScreen() {
|
||||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
},
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
) {
|
||||
Column(modifier = Modifier.padding(it).nestedScroll(scrollBehavior.nestedScrollConnection)) {
|
||||
SwitchPreference(
|
||||
@@ -59,6 +73,23 @@ fun SecurityScreen() {
|
||||
summary = stringResource(id = R.string.settings_privacy_secure_summary),
|
||||
value = Settings::enabledSecurity,
|
||||
)
|
||||
val searchHistoryCleared = stringResource(id = R.string.search_history_cleared)
|
||||
Preference(
|
||||
title = stringResource(id = R.string.clear_search_history),
|
||||
summary = stringResource(id = R.string.clear_search_history_summary),
|
||||
) {
|
||||
coroutineScope.launch {
|
||||
val confirmed = dialogState.show(
|
||||
confirmText = R.string.clear_all,
|
||||
dismissText = android.R.string.cancel,
|
||||
title = R.string.clear_search_history_confirm,
|
||||
)
|
||||
if (confirmed) {
|
||||
searchDatabase.searchDao().clear()
|
||||
launchSnackBar(searchHistoryCleared)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -461,6 +461,10 @@
|
||||
<string name="settings_privacy">隐私</string>
|
||||
<string name="settings_privacy_secure">不允许屏幕抓取</string>
|
||||
<string name="settings_privacy_secure_summary">启用后,将不能截取该应用的屏幕截图,同时,将不会在系统任务切换器中显示该应用的内容预览,重新加载应用以生效此更改</string>
|
||||
<string name="clear_search_history">清除设备上的搜索记录</string>
|
||||
<string name="clear_search_history_summary">移除您在此设备上执行过的搜索查询的记录</string>
|
||||
<string name="clear_search_history_confirm">要清除搜索记录吗?</string>
|
||||
<string name="search_history_cleared">已清除搜索记录</string>
|
||||
<string name="download_service">下载服务</string>
|
||||
<string name="favorite_name">收藏画廊</string>
|
||||
<string name="black_dark_theme">纯黑深色主题</string>
|
||||
|
||||
@@ -526,6 +526,10 @@
|
||||
<string name="settings_privacy">Privacy</string>
|
||||
<string name="settings_privacy_secure">Prevent screenshots</string>
|
||||
<string name="settings_privacy_secure_summary">Prevent the content of the app from being taken screenshots of or shown in the \"Recent Apps\" list.</string>
|
||||
<string name="clear_search_history">Clear device search history</string>
|
||||
<string name="clear_search_history_summary">Remove searches you have performed from this device</string>
|
||||
<string name="clear_search_history_confirm">Clear search history?</string>
|
||||
<string name="search_history_cleared">Search history cleared</string>
|
||||
<string name="download_service">Download Service</string>
|
||||
<string name="favorite_name">Favorite</string>
|
||||
<string name="black_dark_theme">Black dark theme</string>
|
||||
|
||||
Reference in new issue
Block a user