forked from shihaam/thijooree
add clear cache
This commit is contained in:
@@ -26,6 +26,11 @@ object TransactionCache {
|
|||||||
} catch (_: Exception) {}
|
} 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 {
|
fun load(context: Context, key: String): List<Transaction> = try {
|
||||||
val arr = JSONArray(File(context.cacheDir, "tx_$key.json").readText())
|
val arr = JSONArray(File(context.cacheDir, "tx_$key.json").readText())
|
||||||
(0 until arr.length()).map { i ->
|
(0 until arr.length()).map { i ->
|
||||||
|
|||||||
@@ -5,14 +5,22 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.appcompat.app.AppCompatDelegate.setApplicationLocales
|
import androidx.appcompat.app.AppCompatDelegate.setApplicationLocales
|
||||||
import androidx.biometric.BiometricManager
|
import androidx.biometric.BiometricManager
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import sh.sar.basedbank.R
|
import sh.sar.basedbank.R
|
||||||
|
import sh.sar.basedbank.api.mib.TransactionCache
|
||||||
import sh.sar.basedbank.databinding.FragmentSettingsBinding
|
import sh.sar.basedbank.databinding.FragmentSettingsBinding
|
||||||
import sh.sar.basedbank.ui.onboarding.SecuritySetupFragment
|
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() {
|
class SettingsFragment : Fragment() {
|
||||||
|
|
||||||
@@ -82,6 +90,19 @@ class SettingsFragment : Fragment() {
|
|||||||
(activity as? HomeActivity)?.resetAutolockTimer()
|
(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
|
// Change lock
|
||||||
binding.btnChangeLock.setOnClickListener {
|
binding.btnChangeLock.setOnClickListener {
|
||||||
(requireActivity() as HomeActivity).showWithBackStack(
|
(requireActivity() as HomeActivity).showWithBackStack(
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ object AccountCache {
|
|||||||
} catch (e: Exception) { emptyList() }
|
} catch (e: Exception) { emptyList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clear(context: Context) {
|
||||||
|
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
|
||||||
|
}
|
||||||
|
|
||||||
fun load(context: Context): List<MibAccount> {
|
fun load(context: Context): List<MibAccount> {
|
||||||
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
.getString(KEY_MIB, null) ?: return emptyList()
|
.getString(KEY_MIB, null) ?: return emptyList()
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ object ContactImageCache {
|
|||||||
private fun file(context: Context, hash: String) =
|
private fun file(context: Context, hash: String) =
|
||||||
File(context.cacheDir, "cimg_${hash.replace(Regex("[^A-Za-z0-9]"), "_")}.png")
|
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) {
|
fun save(context: Context, hash: String, bitmap: Bitmap) {
|
||||||
try {
|
try {
|
||||||
file(context, hash).outputStream().use {
|
file(context, hash).outputStream().use {
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ object ContactsCache {
|
|||||||
prefs.apply()
|
prefs.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clear(context: Context) {
|
||||||
|
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
|
||||||
|
}
|
||||||
|
|
||||||
fun loadContacts(context: Context): List<MibBeneficiary> {
|
fun loadContacts(context: Context): List<MibBeneficiary> {
|
||||||
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
.getString(KEY_CONTACTS, null) ?: return emptyList()
|
.getString(KEY_CONTACTS, null) ?: return emptyList()
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ object FinancingCache {
|
|||||||
.edit().putString(KEY_MIB, arr.toString()).apply()
|
.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> {
|
fun load(context: Context): List<MibFinanceDeal> {
|
||||||
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
.getString(KEY_MIB, null) ?: return emptyList()
|
.getString(KEY_MIB, null) ?: return emptyList()
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ object ForeignLimitsCache {
|
|||||||
.edit().putString(KEY, arr.toString()).apply()
|
.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> {
|
fun load(context: Context): List<HomeViewModel.BmlLimitsData> {
|
||||||
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
.getString(KEY, null) ?: return emptyList()
|
.getString(KEY, null) ?: return emptyList()
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ object RecentsCache {
|
|||||||
.edit().putString(KEY, arr.toString()).apply()
|
.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> {
|
fun load(context: Context): List<RecentPick> {
|
||||||
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
val json = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
.getString(KEY, null) ?: return emptyList()
|
.getString(KEY, null) ?: return emptyList()
|
||||||
|
|||||||
@@ -158,6 +158,21 @@
|
|||||||
|
|
||||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
</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
|
<LinearLayout
|
||||||
android:id="@+id/rowBiometrics"
|
android:id="@+id/rowBiometrics"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -89,6 +89,9 @@
|
|||||||
<string name="language">ބަސް</string>
|
<string name="language">ބަސް</string>
|
||||||
<string name="lang_english">English</string>
|
<string name="lang_english">English</string>
|
||||||
<string name="lang_dhivehi">ދިވެހި</string>
|
<string name="lang_dhivehi">ދިވެހި</string>
|
||||||
|
<string name="settings_cache">ކޭޝް</string>
|
||||||
|
<string name="settings_clear_cache">ކޭޝް ސާފުކުރޭ</string>
|
||||||
|
<string name="settings_cache_cleared">ކޭޝް ސާފުކުރެވިއްޖެ</string>
|
||||||
|
|
||||||
<!-- Home -->
|
<!-- Home -->
|
||||||
<string name="accounts">އެކައުންޓްތައް</string>
|
<string name="accounts">އެކައުންޓްތައް</string>
|
||||||
|
|||||||
@@ -107,6 +107,9 @@
|
|||||||
<string name="language">Language</string>
|
<string name="language">Language</string>
|
||||||
<string name="lang_english">English</string>
|
<string name="lang_english">English</string>
|
||||||
<string name="lang_dhivehi">ދިވެހި</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 -->
|
<!-- Home -->
|
||||||
<string name="transfer_same_account">This is your source account</string>
|
<string name="transfer_same_account">This is your source account</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user