add clear cache
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 6s

This commit is contained in:
2026-05-15 12:00:59 +05:00
parent 7c0ffece35
commit e8469a8888
11 changed files with 72 additions and 0 deletions

View File

@@ -26,6 +26,11 @@ object TransactionCache {
} catch (_: Exception) {}
}
fun clearAll(context: Context) {
context.cacheDir.listFiles { f -> f.name.startsWith("tx_") && f.name.endsWith(".json") }
?.forEach { it.delete() }
}
fun load(context: Context, key: String): List<Transaction> = try {
val arr = JSONArray(File(context.cacheDir, "tx_$key.json").readText())
(0 until arr.length()).map { i ->

View File

@@ -5,14 +5,22 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.setApplicationLocales
import androidx.biometric.BiometricManager
import androidx.core.os.LocaleListCompat
import androidx.fragment.app.Fragment
import sh.sar.basedbank.R
import sh.sar.basedbank.api.mib.TransactionCache
import sh.sar.basedbank.databinding.FragmentSettingsBinding
import sh.sar.basedbank.ui.onboarding.SecuritySetupFragment
import sh.sar.basedbank.util.AccountCache
import sh.sar.basedbank.util.ContactImageCache
import sh.sar.basedbank.util.ContactsCache
import sh.sar.basedbank.util.FinancingCache
import sh.sar.basedbank.util.ForeignLimitsCache
import sh.sar.basedbank.util.RecentsCache
class SettingsFragment : Fragment() {
@@ -82,6 +90,19 @@ class SettingsFragment : Fragment() {
(activity as? HomeActivity)?.resetAutolockTimer()
}
// Clear cache
binding.btnClearCache.setOnClickListener {
val ctx = requireContext()
AccountCache.clear(ctx)
ContactsCache.clear(ctx)
FinancingCache.clear(ctx)
ForeignLimitsCache.clear(ctx)
RecentsCache.clear(ctx)
TransactionCache.clearAll(ctx)
ContactImageCache.clearAll(ctx)
Toast.makeText(ctx, R.string.settings_cache_cleared, Toast.LENGTH_SHORT).show()
}
// Change lock
binding.btnChangeLock.setOnClickListener {
(requireActivity() as HomeActivity).showWithBackStack(

View File

@@ -85,6 +85,10 @@ object AccountCache {
} catch (e: Exception) { emptyList() }
}
fun clear(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
}
fun load(context: Context): List<MibAccount> {
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
.getString(KEY_MIB, null) ?: return emptyList()

View File

@@ -10,6 +10,11 @@ object ContactImageCache {
private fun file(context: Context, hash: String) =
File(context.cacheDir, "cimg_${hash.replace(Regex("[^A-Za-z0-9]"), "_")}.png")
fun clearAll(context: Context) {
context.cacheDir.listFiles { f -> f.name.startsWith("cimg_") && f.name.endsWith(".png") }
?.forEach { it.delete() }
}
fun save(context: Context, hash: String, bitmap: Bitmap) {
try {
file(context, hash).outputStream().use {

View File

@@ -51,6 +51,10 @@ object ContactsCache {
prefs.apply()
}
fun clear(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
}
fun loadContacts(context: Context): List<MibBeneficiary> {
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
.getString(KEY_CONTACTS, null) ?: return emptyList()

View File

@@ -34,6 +34,10 @@ object FinancingCache {
.edit().putString(KEY_MIB, arr.toString()).apply()
}
fun clear(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
}
fun load(context: Context): List<MibFinanceDeal> {
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
.getString(KEY_MIB, null) ?: return emptyList()

View File

@@ -42,6 +42,10 @@ object ForeignLimitsCache {
.edit().putString(KEY, arr.toString()).apply()
}
fun clear(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
}
fun load(context: Context): List<HomeViewModel.BmlLimitsData> {
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
.getString(KEY, null) ?: return emptyList()

View File

@@ -57,6 +57,10 @@ object RecentsCache {
.edit().putString(KEY, arr.toString()).apply()
}
fun clear(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
}
fun load(context: Context): List<RecentPick> {
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
.getString(KEY, null) ?: return emptyList()

View File

@@ -158,6 +158,21 @@
</com.google.android.material.button.MaterialButtonToggleGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_cache"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:layout_marginTop="24dp"
android:layout_marginBottom="12dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnClearCache"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_clear_cache" />
<LinearLayout
android:id="@+id/rowBiometrics"
android:layout_width="match_parent"

View File

@@ -89,6 +89,9 @@
<string name="language">ބަސް</string>
<string name="lang_english">English</string>
<string name="lang_dhivehi">ދިވެހި</string>
<string name="settings_cache">ކޭޝް</string>
<string name="settings_clear_cache">ކޭޝް ސާފުކުރޭ</string>
<string name="settings_cache_cleared">ކޭޝް ސާފުކުރެވިއްޖެ</string>
<!-- Home -->
<string name="accounts">އެކައުންޓްތައް</string>

View File

@@ -107,6 +107,9 @@
<string name="language">Language</string>
<string name="lang_english">English</string>
<string name="lang_dhivehi">ދިވެހި</string>
<string name="settings_cache">Cache</string>
<string name="settings_clear_cache">Clear Cache</string>
<string name="settings_cache_cleared">Cache cleared</string>
<!-- Home -->
<string name="transfer_same_account">This is your source account</string>