Option to clear cache

This commit is contained in:
Sad Ellie 2023-09-28 15:39:20 +03:00
parent 59c151d2a6
commit 5109449907
5 changed files with 24 additions and 1 deletions

View File

@ -1419,4 +1419,5 @@ Used in this dialog window. Should be short -->
<string name="calculator_settings_support">History view</string>
<string name="converter_settings_support">Unit groups, sorting, formatting</string>
<string name="display_settings">Display</string>
<string name="clear_cache">Clear cache</string>
</resources>

View File

@ -31,4 +31,7 @@ interface CurrencyRatesDao {
@Query("SELECT DISTINCT * FROM currency_rates WHERE timestamp = (SELECT MAX(timestamp) FROM currency_rates) AND base_unit_id = :baseId")
suspend fun getLatestRates(baseId: String): List<CurrencyRatesEntity>
@Query("DELETE FROM currency_rates")
suspend fun clear()
}

View File

@ -33,6 +33,7 @@ dependencies {
implementation(libs.androidx.appcompat.appcompat)
implementation(project(":data:common"))
implementation(project(":data:database"))
implementation(project(":data:model"))
implementation(project(":data:userprefs"))
implementation(project(":data:licenses"))

View File

@ -21,6 +21,7 @@ package com.sadellie.unitto.feature.settings
import androidx.compose.foundation.clickable
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cached
import androidx.compose.material.icons.filled.Calculate
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Info
@ -64,6 +65,7 @@ internal fun SettingsRoute(
navigateUp = navigateUp,
navControllerAction = navControllerAction,
updateVibrations = viewModel::updateVibrations,
clearCache = viewModel::clearCache
)
}
@ -73,6 +75,7 @@ private fun SettingsScreen(
navigateUp: () -> Unit,
navControllerAction: (String) -> Unit,
updateVibrations: (Boolean) -> Unit,
clearCache: () -> Unit,
) {
val mContext = LocalContext.current
@ -146,7 +149,15 @@ private fun SettingsScreen(
)
}
// RATE THIS APP
item("clear cache") {
UnittoListItem(
headlineText = stringResource(R.string.clear_cache),
icon = Icons.Default.Cached,
iconDescription = stringResource(R.string.clear_cache),
modifier = Modifier.clickable { clearCache() },
)
}
if (BuildConfig.STORE_LINK.isNotEmpty()) {
item("rate this app") {
UnittoListItem(
@ -179,5 +190,6 @@ private fun PreviewSettingsScreen() {
navigateUp = {},
navControllerAction = {},
updateVibrations = {},
clearCache = {}
)
}

View File

@ -21,6 +21,7 @@ package com.sadellie.unitto.feature.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sadellie.unitto.data.common.stateIn
import com.sadellie.unitto.data.database.CurrencyRatesDao
import com.sadellie.unitto.data.userprefs.GeneralPreferences
import com.sadellie.unitto.data.userprefs.UserPreferencesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
@ -30,6 +31,7 @@ import javax.inject.Inject
@HiltViewModel
internal class SettingsViewModel @Inject constructor(
private val userPrefsRepository: UserPreferencesRepository,
private val currencyRatesDao: CurrencyRatesDao,
) : ViewModel() {
val userPrefs = userPrefsRepository.generalPrefs
.stateIn(viewModelScope, GeneralPreferences())
@ -40,4 +42,8 @@ internal class SettingsViewModel @Inject constructor(
fun updateVibrations(enabled: Boolean) = viewModelScope.launch {
userPrefsRepository.updateVibrations(enabled)
}
fun clearCache() = viewModelScope.launch {
currencyRatesDao.clear()
}
}