Proyectos de Subversion Android Microlearning

Rev

Rev 32 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
package com.cesams.twogetskills.preference;
2
 
3
import android.content.Context;
4
import android.content.SharedPreferences;
44 efrain 5
import android.util.Log;
6
 
1 efrain 7
import com.cesams.twogetskills.Constants;
8
 
9
public class Preference {
29 efrain 10
 
11
    private static Preference instance;
12
    private Context context;
13
 
1 efrain 14
    private String userUuid;
15
 
16
    private String email;
17
    private String firstName;
18
    private String lastName;
19
    private String maxDateChanges;
20
    private String lastDataRefresh;
21
    private String image;
22
    private String password;
23
    private String aes;
24
    private int fragmentIdxActive;
25
    private String topicUuidActive;
26
    private String capsuleUuidActive;
27
    private String lastCapsuleUuidActive;
20 gabriel 28
    private String slideNameActive;
1 efrain 29
    private String slideUuidActive;
30
    private String companyUuidActive;
31
 
32
    private int companyCount;
33
 
34
    //Device
35
    private String deviceUuid;
36
    private String deviceToken;
37
 
29 efrain 38
    public static Preference getInstance(Context context)
39
    {
40
        if (instance == null) {
41
            instance = new Preference(context);
42
        }
43
 
44
        return instance;
45
    }
46
 
47
 
48
 
1 efrain 49
    public String getUserUuid() {
50
        return userUuid;
51
    }
52
    public void setUserUuid(String userUuid) {
53
        this.userUuid = userUuid;
54
    }
55
 
25 gabriel 56
 
20 gabriel 57
    public String getSlideName() {
58
        return slideNameActive;
59
    }
60
 
61
    public void setSlideName(String slideNameActive) {
62
        this.slideNameActive = slideNameActive;
63
    }
64
 
1 efrain 65
    public String getEmail() {
66
        return email;
67
    }
68
 
69
    public void setEmail(String email) {
70
        this.email = email;
71
    }
72
 
73
    public String getFirstName() {
74
        return firstName;
75
    }
76
 
77
    public void setFirstName(String firstName) {
78
        this.firstName = firstName;
79
    }
80
 
81
    public String getLastName() {
82
        return lastName;
83
    }
84
 
85
    public void setLastName(String lastName) {
86
        this.lastName = lastName;
87
    }
88
 
89
    public String getMaxDateChanges() {
90
        return maxDateChanges;
91
    }
92
 
93
    public void setMaxDateChanges(String maxDateChanges) {
94
        this.maxDateChanges = maxDateChanges;
95
    }
96
 
97
    public String getLastDataRefresh() {
98
        return lastDataRefresh;
99
    }
100
 
101
    public void setLastDataRefresh(String lastDataRefresh) {
102
        this.lastDataRefresh = lastDataRefresh;
103
    }
104
 
105
    public String getImage() {
106
        return image;
107
    }
108
 
109
    public void setImage(String image) {
110
        this.image = image;
111
    }
112
 
113
    public String getPassword() {
114
        return password;
115
    }
116
 
117
    public void setPassword(String password) {
118
        this.password = password;
119
    }
120
 
121
    public String getAes() {
122
        return aes;
123
    }
124
 
125
    public void setAes(String aes) {
126
        this.aes = aes;
127
    }
128
 
129
    public int getFragmentIdxActive() {
130
        return fragmentIdxActive;
131
    }
132
 
133
    public void setFragmentIdxActive(int fragmentIdxActive) {
134
        this.fragmentIdxActive = fragmentIdxActive;
135
    }
136
 
137
    public String getTopicUuidActive() {
138
        return topicUuidActive;
139
    }
140
 
141
    public void setTopicUuidActive(String topicUuidActive) {
142
        this.topicUuidActive = topicUuidActive;
143
    }
144
 
145
    public String getCapsuleUuidActive() {
146
        return capsuleUuidActive;
147
    }
148
 
149
    public void setCapsuleUuidActive(String capsuleUuidActive) {
150
        this.capsuleUuidActive = capsuleUuidActive;
151
    }
152
 
153
    public String getSlideUuidActive() {
154
        return slideUuidActive;
155
    }
156
 
157
    public void setSlideUuidActive(String slideUuidActive) {
158
        this.slideUuidActive = slideUuidActive;
159
    }
160
 
161
    public String getCompanyUuidActive() {
162
        return companyUuidActive;
163
    }
164
 
165
    public void setCompanyUuidActive(String companyUuidActive) {
166
        this.companyUuidActive = companyUuidActive;
167
    }
168
 
169
    public String getLastCapsuleUuidActive() {
170
        return lastCapsuleUuidActive;
171
    }
172
 
173
    public void setLastCapsuleUuidActive(String lastCapsuleUuidActive) {
174
        this.lastCapsuleUuidActive = lastCapsuleUuidActive;
175
    }
176
 
177
    public int getCompanyCount() {
178
        return companyCount;
179
    }
180
 
181
    public void setCompanyCount(int companyCount) {
182
        this.companyCount = companyCount;
183
    }
184
 
185
    public String getDeviceUuid() {
186
        return deviceUuid;
187
    }
188
 
189
    public void setDeviceUuid(String deviceUuid) {
190
        this.deviceUuid = deviceUuid;
191
    }
192
 
193
    public String getDeviceToken() {
194
        return deviceToken;
195
    }
196
 
197
    public void setDeviceToken(String deviceToken) {
198
        this.deviceToken = deviceToken;
199
    }
200
 
29 efrain 201
    private Preference(Context context) {
202
        this.context = context;
203
        this.load();
204
 
22 efrain 205
    }
206
 
44 efrain 207
    public synchronized void load()
29 efrain 208
    {
209
 
210
 
1 efrain 211
        SharedPreferences sharedPreferences = context.getSharedPreferences(
212
                Constants.PREFERENCE_FILENAME, Context.MODE_PRIVATE);
213
 
214
        deviceUuid = sharedPreferences.getString("device_uuid" , "");
215
        deviceToken = sharedPreferences.getString("device_token" , "");
216
        userUuid = sharedPreferences.getString("user_uuid", "");
217
        email = sharedPreferences.getString("email", "");
218
        firstName = sharedPreferences.getString("first_name", "");
219
        lastName = sharedPreferences.getString("last_name", "");
220
        image = sharedPreferences.getString("image", "");
221
 
222
        maxDateChanges = sharedPreferences.getString("max_date_changes", "");
223
        lastDataRefresh = sharedPreferences.getString("last_date_refresh", "");
224
 
225
        password = sharedPreferences.getString("password", "");
226
        aes = sharedPreferences.getString("aes", "");
227
 
228
        fragmentIdxActive = sharedPreferences.getInt("fragment_idx_active", Constants.IDX_FRAGMENT_INTRO);
229
        topicUuidActive = sharedPreferences.getString("topic_uuid_active", "");
230
        capsuleUuidActive = sharedPreferences.getString("capsule_uuid_active", "");
231
        slideUuidActive = sharedPreferences.getString("slide_uuid_active", "");
232
        companyUuidActive = sharedPreferences.getString("company_uuid_active", "");
233
        companyCount = sharedPreferences.getInt("company_count", 0);
234
        lastCapsuleUuidActive = sharedPreferences.getString("last_capsule_uuid_active", "");
235
 
44 efrain 236
        Log.d("BUG 2PLANO", "Preference Load - userUuid : " + userUuid  );
237
        Log.d("BUG 2PLANO", "Preference Load - topicUuid : " + topicUuidActive  );
238
        Log.d("BUG 2PLANO", "Preference Load - capsuleUuid : " + capsuleUuidActive );
239
        Log.d("BUG 2PLANO", "Preference Load - slideUuid : " + slideUuidActive  );
240
 
1 efrain 241
    }
242
 
44 efrain 243
    public synchronized void save()
1 efrain 244
    {
245
        SharedPreferences sharedPreferences = context.getSharedPreferences(
246
                Constants.PREFERENCE_FILENAME, Context.MODE_PRIVATE);
247
 
248
        SharedPreferences.Editor editor = sharedPreferences.edit();
249
        editor.putString("device_uuid" , deviceUuid);
250
        editor.putString("device_token" , deviceToken);
251
        editor.putString("user_uuid", userUuid);
252
        editor.putString("email", email);
253
        editor.putString("first_name", firstName);
254
        editor.putString("last_name", lastName);
255
        editor.putString("image", image);
256
        editor.putString("max_date_changes", maxDateChanges);
257
        editor.putString("last_date_refresh", lastDataRefresh);
20 gabriel 258
        editor.putString("last_slidename",slideNameActive);
1 efrain 259
        editor.putString("password", password);
260
        editor.putString("aes", aes);
261
 
262
 
263
        editor.putInt("fragment_idx_active", fragmentIdxActive);
264
        editor.putString("topic_uuid_active", topicUuidActive);
265
        editor.putString("capsule_uuid_active", capsuleUuidActive);
266
        editor.putString("slide_uuid_active", slideUuidActive);
267
        editor.putString("company_uuid_active", companyUuidActive);
268
        editor.putInt("company_count", companyCount);
269
        editor.putString("last_capsule_uuid_active", lastCapsuleUuidActive);
270
 
25 gabriel 271
        editor.apply();
1 efrain 272
    }
273
}