From c1d100d8838135699abeb16c7071fc5a7902ba58 Mon Sep 17 00:00:00 2001 From: yehia Date: Thu, 10 Feb 2022 16:22:52 +0200 Subject: [PATCH] Add removeAll Except method --- .idea/jarRepositories.xml | 40 +++++++++++++++++++ app/build.gradle | 4 +- fastsave/build.gradle | 6 +-- .../appizona/yehiahd/fastsave/FastSave.java | 20 ++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .idea/jarRepositories.xml diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..6bf1978 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ca8340f..139d01c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { applicationId "com.appizona.yehiahd.fastsaveexample" minSdkVersion 17 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/fastsave/build.gradle b/fastsave/build.gradle index 0d34f7e..cfb52bb 100644 --- a/fastsave/build.gradle +++ b/fastsave/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 1 versionName "1.0" @@ -22,5 +22,5 @@ android { dependencies { //Gson - implementation 'com.google.code.gson:gson:2.8.2' + implementation 'com.google.code.gson:gson:2.8.9' } diff --git a/fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java b/fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java index 6a9a238..5089d74 100644 --- a/fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java +++ b/fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java @@ -188,4 +188,24 @@ public boolean isKeyExists(String key) { } } + public boolean removeAllExcept(String... keys) { + Boolean isMatch = false; + SharedPreferences.Editor editor = mSharedPreferences.edit(); + for (String key : mSharedPreferences.getAll().keySet()) { + for (String k : keys) { + if (key.equals(k)) { + isMatch = true; + } + } + if (!isMatch) { + editor.remove(key); + } else { + isMatch = false; + } + } + editor.apply(); + + return true; + } + }