Skip to content

Commit

Permalink
prefs list
Browse files Browse the repository at this point in the history
  • Loading branch information
tiromansev committed Apr 29, 2018
1 parent cda9b1e commit cc27c86
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 26 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
applicationId "com.tiromansev.prefswrapperexample"
minSdkVersion 15
Expand All @@ -18,14 +18,14 @@ android {
}
}

def support = '26.1.0'
def support = '27.1.1'

dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$support"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':prefswrapper')
implementation "com.android.support:appcompat-v7:$support"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
implementation project(':prefswrapper')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Oct 27 13:23:45 MSK 2017
#Sun Apr 29 10:45:51 MSK 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
12 changes: 6 additions & 6 deletions prefswrapper/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
Expand All @@ -19,13 +19,13 @@ android {
}
}

def support = '26.1.0'
def support = '27.1.1'

dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$support"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
implementation "com.android.support:appcompat-v7:$support"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.util.HashMap;

public class BasePreference {

private static Context context;
private static SharedPreferences appPreferences;
protected static HashMap<String, BasePreference> prefsList = new HashMap<>();

private String fileName = null;
private String key = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public void setValue(boolean value) {
}
}

public static Builder builder() {
return new BooleanPreference().new Builder();
public static Builder builder(String key) {
BasePreference pref = prefsList.get(key);
if (pref == null) {
pref = new BooleanPreference();
((BooleanPreference) pref).setKey(key);
prefsList.put(key, pref);
}
return ((BooleanPreference) pref).new Builder();
}

public class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public void setValue(float value) {
}
}

public static Builder builder() {
return new FloatPreference().new Builder();
public static Builder builder(String key) {
BasePreference pref = prefsList.get(key);
if (pref == null) {
pref = new FloatPreference();
((FloatPreference) pref).setKey(key);
prefsList.put(key, pref);
}
return ((FloatPreference) pref).new Builder();
}

public class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public void setValue(int value) {
}
}

public static Builder builder() {
return new IntegerPreference().new Builder();
public static Builder builder(String key) {
BasePreference pref = prefsList.get(key);
if (pref == null) {
pref = new IntegerPreference();
((IntegerPreference) pref).setKey(key);
prefsList.put(key, pref);
}
return ((IntegerPreference) pref).new Builder();
}

public class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public void setValue(long value) {
}
}

public static Builder builder() {
return new LongPreference().new Builder();
public static Builder builder(String key) {
BasePreference pref = prefsList.get(key);
if (pref == null) {
pref = new LongPreference();
((LongPreference) pref).setKey(key);
prefsList.put(key, pref);
}
return ((LongPreference) pref).new Builder();
}

public class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public void setValue(String value) {
}
}

public static Builder builder() {
return new StringPreference().new Builder();
public static Builder builder(String key) {
BasePreference pref = prefsList.get(key);
if (pref == null) {
pref = new StringPreference();
((StringPreference) pref).setKey(key);
prefsList.put(key, pref);
}
return ((StringPreference) pref).new Builder();
}

public class Builder {
Expand Down

0 comments on commit cc27c86

Please sign in to comment.