-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLocalStorage.java
87 lines (67 loc) · 1.78 KB
/
LocalStorage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
/**
* LocalStorage class
* @author Mohammadreza Yektamaram <[email protected]>
* @since 2020-01-23 11:13 AM
*/
public class LocalStorage {
private static SharedPreferences variable;
private static SharedPreferences.Editor storage;
public LocalStorage( Context context ) {
variable = PreferenceManager.getDefaultSharedPreferences( context );
storage = variable.edit();
}
/**
* Get int variable from local storage
* @param name
* @return int
*/
public int getInt( String name ) {
return variable.getInt( name, 0 );
}
/**
* Get string variable from local storage
* @param name
* @return int
*/
public String getString( String name ) {
return variable.getString( name, "" );
}
/**
* Get boolean variable from local storage
* @param name
* @return int
*/
public boolean getBoolean( String name ) {
return variable.getBoolean( name, false );
}
/**
* Save int variable in local storage
* @param name
* @param value
*/
public void putInt( String name, int value ) {
storage.putInt( name, value );
storage.commit();
}
/**
* Save string variable in local storage
* @param name
* @param value
*/
public void putString( String name, String value ) {
storage.putString( name, value );
storage.commit();
}
/**
* Save boolean variable in local storage
* @param name
* @param value
*/
public void putBoolean( String name, boolean value ) {
storage.putBoolean( name, value );
storage.commit();
}
}