-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathNueva_version_de_Firebase.patch
473 lines (427 loc) · 19.8 KB
/
Nueva_version_de_Firebase.patch
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
Index: app/src/main/java/edu/galileo/android/androidchat/login/LoginRepositoryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/login/LoginRepositoryImpl.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/login/LoginRepositoryImpl.java (revision )
@@ -1,11 +1,17 @@
package edu.galileo.android.androidchat.login;
-import com.firebase.client.AuthData;
-import com.firebase.client.DataSnapshot;
-import com.firebase.client.Firebase;
-import com.firebase.client.FirebaseError;
-import com.firebase.client.ValueEventListener;
+import android.support.annotation.NonNull;
+import com.google.android.gms.tasks.OnFailureListener;
+import com.google.android.gms.tasks.OnSuccessListener;
+import com.google.firebase.auth.AuthResult;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseUser;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.DatabaseError;
+import com.google.firebase.database.ValueEventListener;
+
import java.util.Map;
import edu.galileo.android.androidchat.contactlist.entities.User;
@@ -19,8 +25,8 @@
*/
public class LoginRepositoryImpl implements LoginRepository {
private FirebaseHelper helper;
- private Firebase dataReference;
- private Firebase myUserReference;
+ private DatabaseReference dataReference;
+ private DatabaseReference myUserReference;
public LoginRepositoryImpl(){
helper = FirebaseHelper.getInstance();
@@ -30,48 +36,57 @@
@Override
public void signUp(final String email, final String password) {
- dataReference.createUser(email, password, new Firebase.ValueResultHandler<Map<String, Object>>() {
+ FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
+ .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
- @Override
+ @Override
- public void onSuccess(Map<String, Object> result) {
+ public void onSuccess(AuthResult authResult) {
- postEvent(LoginEvent.onSignUpSuccess);
- signIn(email, password);
- }
+ postEvent(LoginEvent.onSignUpSuccess);
+ signIn(email, password);
+ }
-
+ })
+ .addOnFailureListener(new OnFailureListener() {
- @Override
+ @Override
- public void onError(FirebaseError firebaseError) {
- postEvent(LoginEvent.onSignUpError, firebaseError.getMessage());
+ public void onFailure(@NonNull Exception e) {
+ postEvent(LoginEvent.onSignUpError, e.getMessage());
- }
- });
+ }
+ });
}
@Override
public void signIn(String email, String password) {
- dataReference.authWithPassword(email, password, new Firebase.AuthResultHandler() {
+ try {
+ FirebaseAuth auth = FirebaseAuth.getInstance();
+ auth.signInWithEmailAndPassword(email, password)
+ .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
- @Override
+ @Override
- public void onAuthenticated(AuthData authData) {
+ public void onSuccess(AuthResult authResult) {
- myUserReference = helper.getMyUserReference();
- myUserReference.addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot snapshot) {
- initSignIn(snapshot);
- }
+ myUserReference = helper.getMyUserReference();
+ myUserReference.addListenerForSingleValueEvent(new ValueEventListener() {
+ @Override
+ public void onDataChange(DataSnapshot snapshot) {
+ initSignIn(snapshot);
+ }
-
- @Override
+ @Override
- public void onCancelled(FirebaseError firebaseError) {
+ public void onCancelled(DatabaseError firebaseError) {
+ postEvent(LoginEvent.onSignInError, firebaseError.getMessage());
- }
- });
- }
+ }
+ });
+ }
-
+ })
+ .addOnFailureListener(new OnFailureListener() {
- @Override
+ @Override
- public void onAuthenticationError(FirebaseError firebaseError) {
- postEvent(LoginEvent.onSignInError, firebaseError.getMessage());
+ public void onFailure(@NonNull Exception e) {
+ postEvent(LoginEvent.onSignInError, e.getMessage());
- }
- });
+ }
+ });
+ } catch (Exception e) {
+ postEvent(LoginEvent.onSignInError, e.getMessage());
- }
+ }
+ }
@Override
public void checkAlreadyAuthenticated() {
- if (dataReference.getAuth() != null) {
+ if (FirebaseAuth.getInstance().getCurrentUser() != null) {
myUserReference = helper.getMyUserReference();
myUserReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
@@ -80,7 +95,7 @@
}
@Override
- public void onCancelled(FirebaseError firebaseError) {
+ public void onCancelled(DatabaseError firebaseError) {
postEvent(LoginEvent.onSignInError, firebaseError.getMessage());
}
});
Index: app/src/main/java/edu/galileo/android/androidchat/contactlist/ContactListRepositoryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/contactlist/ContactListRepositoryImpl.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/contactlist/ContactListRepositoryImpl.java (revision )
@@ -1,8 +1,8 @@
package edu.galileo.android.androidchat.contactlist;
-import com.firebase.client.ChildEventListener;
-import com.firebase.client.DataSnapshot;
-import com.firebase.client.FirebaseError;
+import com.google.firebase.database.ChildEventListener;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseError;
import edu.galileo.android.androidchat.contactlist.entities.User;
import edu.galileo.android.androidchat.contactlist.events.ContactListEvent;
@@ -58,7 +58,7 @@
}
@Override
- public void onCancelled(FirebaseError firebaseError) {}
+ public void onCancelled(DatabaseError firebaseError) {}
};
}
Index: app/src/main/java/edu/galileo/android/androidchat/domain/FirebaseHelper.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/domain/FirebaseHelper.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/domain/FirebaseHelper.java (revision )
@@ -1,10 +1,12 @@
package edu.galileo.android.androidchat.domain;
-import com.firebase.client.AuthData;
-import com.firebase.client.DataSnapshot;
-import com.firebase.client.Firebase;
-import com.firebase.client.FirebaseError;
-import com.firebase.client.ValueEventListener;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseUser;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.DatabaseError;
+import com.google.firebase.database.FirebaseDatabase;
+import com.google.firebase.database.ValueEventListener;
import java.util.HashMap;
import java.util.Map;
@@ -15,12 +17,11 @@
* Created by ykro.
*/
public class FirebaseHelper {
- private Firebase dataReference;
+ private DatabaseReference dataReference;
private final static String SEPARATOR = "___";
private final static String CHATS_PATH = "chats";
private final static String USERS_PATH = "users";
public final static String CONTACTS_PATH = "contacts";
- private final static String FIREBASE_URL = "https://android-chat-example.firebaseio.com";
private static class SingletonHolder {
private static final FirebaseHelper INSTANCE = new FirebaseHelper();
@@ -31,25 +32,24 @@
}
public FirebaseHelper(){
- dataReference = new Firebase(FIREBASE_URL);
+ dataReference = FirebaseDatabase.getInstance().getReference();
}
- public Firebase getDataReference() {
+ public DatabaseReference getDataReference() {
return dataReference;
}
public String getAuthUserEmail() {
- AuthData authData = dataReference.getAuth();
+ FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String email = null;
- if (authData != null) {
- Map<String, Object> providerData = authData.getProviderData();
- email = providerData.get("email").toString();
+ if (user != null) {
+ email = user.getEmail();
}
return email;
}
- public Firebase getUserReference(String email){
- Firebase userReference = null;
+ public DatabaseReference getUserReference(String email){
+ DatabaseReference userReference = null;
if (email != null) {
String emailKey = email.replace(".", "_");
userReference = dataReference.getRoot().child(USERS_PATH).child(emailKey);
@@ -57,24 +57,24 @@
return userReference;
}
- public Firebase getMyUserReference() {
+ public DatabaseReference getMyUserReference() {
return getUserReference(getAuthUserEmail());
}
- public Firebase getContactsReference(String email){
+ public DatabaseReference getContactsReference(String email){
return getUserReference(email).child(CONTACTS_PATH);
}
- public Firebase getMyContactsReference(){
+ public DatabaseReference getMyContactsReference(){
return getContactsReference(getAuthUserEmail());
}
- public Firebase getOneContactReference(String mainEmail, String childEmail){
+ public DatabaseReference getOneContactReference(String mainEmail, String childEmail){
String childKey = childEmail.replace(".","_");
return getUserReference(mainEmail).child(CONTACTS_PATH).child(childKey);
}
- public Firebase getChatsReference(String receiver){
+ public DatabaseReference getChatsReference(String receiver){
String keySender = getAuthUserEmail().replace(".","_");
String keyReceiver = receiver.replace(".","_");
@@ -102,16 +102,16 @@
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child : snapshot.getChildren()) {
String email = child.getKey();
- Firebase reference = getOneContactReference(email, myEmail);
+ DatabaseReference reference = getOneContactReference(email, myEmail);
reference.setValue(online);
}
if (signoff){
- dataReference.unauth();
+ FirebaseAuth.getInstance().signOut();
}
}
@Override
- public void onCancelled(FirebaseError firebaseError) {
+ public void onCancelled(DatabaseError firebaseError) {
}
});
}
Index: app/src/main/java/edu/galileo/android/androidchat/chat/ChatRepositoryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/chat/ChatRepositoryImpl.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/chat/ChatRepositoryImpl.java (revision )
@@ -1,9 +1,9 @@
package edu.galileo.android.androidchat.chat;
-import com.firebase.client.ChildEventListener;
-import com.firebase.client.DataSnapshot;
-import com.firebase.client.Firebase;
-import com.firebase.client.FirebaseError;
+import com.google.firebase.database.ChildEventListener;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.DatabaseError;
import edu.galileo.android.androidchat.chat.entities.ChatMessage;
import edu.galileo.android.androidchat.chat.events.ChatEvent;
@@ -56,7 +56,7 @@
public void onChildMoved(DataSnapshot dataSnapshot, String s) {}
@Override
- public void onCancelled(FirebaseError firebaseError) {}
+ public void onCancelled(DatabaseError firebaseError) {}
};
helper.getChatsReference(receiver).addChildEventListener(chatEventListener);
}
@@ -78,7 +78,7 @@
public void sendMessage(String msg) {
String keySender = helper.getAuthUserEmail().replace(".","_");
ChatMessage chatMessage = new ChatMessage(keySender, msg);
- Firebase chatsReference = helper.getChatsReference(receiver);
+ DatabaseReference chatsReference = helper.getChatsReference(receiver);
chatsReference.push().setValue(chatMessage);
}
Index: app/src/main/java/edu/galileo/android/androidchat/AndroidChatApplication.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/AndroidChatApplication.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/AndroidChatApplication.java (revision )
@@ -2,7 +2,7 @@
import android.app.Application;
-import com.firebase.client.Firebase;
+import com.google.firebase.database.FirebaseDatabase;
import edu.galileo.android.androidchat.lib.GlideImageLoader;
import edu.galileo.android.androidchat.lib.ImageLoader;
@@ -29,7 +29,6 @@
}
private void setupFirebase(){
- Firebase.setAndroidContext(this);
- Firebase.getDefaultConfig().setPersistenceEnabled(true);
+ FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
Index: app/src/main/java/edu/galileo/android/androidchat/addcontact/AddContactRepositoryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/addcontact/AddContactRepositoryImpl.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/addcontact/AddContactRepositoryImpl.java (revision )
@@ -1,9 +1,9 @@
package edu.galileo.android.androidchat.addcontact;
-import com.firebase.client.DataSnapshot;
-import com.firebase.client.Firebase;
-import com.firebase.client.FirebaseError;
-import com.firebase.client.ValueEventListener;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseError;
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.ValueEventListener;
import edu.galileo.android.androidchat.addcontact.events.AddContactEvent;
import edu.galileo.android.androidchat.contactlist.entities.User;
@@ -20,7 +20,7 @@
final String key = email.replace(".","_");
FirebaseHelper helper = FirebaseHelper.getInstance();
- final Firebase userReference = helper.getUserReference(email);
+ final DatabaseReference userReference = helper.getUserReference(email);
userReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
@@ -30,12 +30,12 @@
boolean online = user.isOnline();
FirebaseHelper helper = FirebaseHelper.getInstance();
- Firebase userContactsReference = helper.getMyContactsReference();
+ DatabaseReference userContactsReference = helper.getMyContactsReference();
userContactsReference.child(key).setValue(online);
String currentUserEmailKey = helper.getAuthUserEmail();
currentUserEmailKey = currentUserEmailKey.replace(".","_");
- Firebase reverseUserContactsReference = helper.getContactsReference(email);
+ DatabaseReference reverseUserContactsReference = helper.getContactsReference(email);
reverseUserContactsReference.child(currentUserEmailKey).setValue(true);
} else {
event.setError(true);
@@ -45,7 +45,7 @@
}
@Override
- public void onCancelled(FirebaseError firebaseError) {}
+ public void onCancelled(DatabaseError firebaseError) {}
});
}
}
Index: app/src/main/java/edu/galileo/android/androidchat/chat/entities/ChatMessage.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/src/main/java/edu/galileo/android/androidchat/chat/entities/ChatMessage.java (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/src/main/java/edu/galileo/android/androidchat/chat/entities/ChatMessage.java (revision )
@@ -1,15 +1,15 @@
package edu.galileo.android.androidchat.chat.entities;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.google.firebase.database.Exclude;
/**
* Created by ykro.
*/
-@JsonIgnoreProperties({"sentByMe"})
public class ChatMessage {
String msg;
String sender;
+ @Exclude
boolean sentByMe;
public ChatMessage(){}
Index: app/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/build.gradle (revision 6d05887547bb2e793e5bc7b6e386f71a1f617ac0)
+++ app/build.gradle (revision )
@@ -17,12 +17,13 @@
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
-
+ /*
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
+ */
}
dependencies {
@@ -34,9 +35,12 @@
compile "com.android.support:design:$rootProject.ext.supportLibraryVersion"
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
- compile "com.firebase:firebase-client-android:$rootProject.ext.firebaseClientVersion"
+ compile "com.google.firebase:firebase-database:$rootProject.ext.firebaseVersion"
+ compile "com.google.firebase:firebase-auth:$rootProject.ext.firebaseVersion"
compile "de.hdodenhof:circleimageview:$rootProject.ext.circleImageViewVersion"
compile "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
compile "com.github.bumptech.glide:glide:$rootProject.ext.glideVersion"
compile "org.greenrobot:eventbus:$rootProject.ext.eventbusVersion"
}
+
+apply plugin: 'com.google.gms.google-services'
\ No newline at end of file