-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedPrefManager.java
123 lines (101 loc) · 4.19 KB
/
SharedPrefManager.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.example.cosmic.androidappclasses;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPrefManager {
SharedPreferences sharedPreferences;
Context mContext;
// shared pref mode
int PRIVATE_MODE = 0;
// Shared preferences file name
private static final String PREF_NAME = "sessionPref";
SharedPreferences.Editor editor;
public SharedPrefManager(Context context) {
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = sharedPreferences.edit();
}
public void saveIsLoggedIn(Context context, Boolean isLoggedIn){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean ("IS_LOGGED_IN", isLoggedIn);
editor.commit();
}
public boolean getISLogged_IN() {
//mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getBoolean("IS_LOGGED_IN", false);
}
public void saveToken(Context context, String toke){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("ID_TOKEN", toke);
editor.commit();
}
public String getUserToken(){
//mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("ID_TOKEN", "");
}
public void saveUiD(Context context, String UID){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("UID_USER", UID);
editor.commit();
}
public String getUserUiD(){
//mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("UID_USER", "");
}
public void saveEmail(Context context, String email){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("EMAIL", email);
editor.commit();
}
public String getUserEmail(){
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("EMAIL", null);
}
public void saveName(Context context, String name){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("NAME", name);
editor.commit();
}
public String getName(){
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("NAME", null);
}
public void saveUserName(Context context, String username){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("userNAME", username);
editor.commit();
}
public String getUserName(){
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("userNAME", null);
}
public void savePhoto(Context context, String photo){
mContext = context;
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("PHOTO", photo);
editor.commit();
}
public String getPhoto(){
sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
return sharedPreferences.getString("PHOTO", null);
}
public void clear(){
editor.clear();
editor.apply();
}
}