Skip to content

Commit

Permalink
Add removeAll Except method
Browse files Browse the repository at this point in the history
  • Loading branch information
yehiahd committed Feb 10, 2022
1 parent bd1fba3 commit c1d100d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
40 changes: 40 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions fastsave/build.gradle
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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'
}
20 changes: 20 additions & 0 deletions fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit c1d100d

Please sign in to comment.