diff --git a/android/app/src/main/java/com/chatman/AuthActivity.java b/android/app/src/main/java/com/chatman/AuthActivity.java index 00fe30d56838e03e4b3d4437e661b79593c78969..fb2ac41245de7aa8b0fc19ecd098469a44ce1ef4 100644 --- a/android/app/src/main/java/com/chatman/AuthActivity.java +++ b/android/app/src/main/java/com/chatman/AuthActivity.java @@ -105,7 +105,8 @@ public class AuthActivity extends AppCompatActivity { for (DataSnapshot ds : dataSnapshot.getChildren()) { User user = ds.getValue(User.class); if (user.getEmail().equals(email) && user.getPassword().equals(md5(password))) { - PreferencesHelper.setUserFirebaseKey(this, ds.getKey()); + PreferencesHelper.setUserFirebaseId(AuthActivity.this, user.getId()); + PreferencesHelper.setTokenKey(AuthActivity.this, user.getKey()); PreferencesHelper.setUserName(this, user.getName()); PreferencesHelper.setHasLogin(this, true); finish(); @@ -167,16 +168,16 @@ public class AuthActivity extends AppCompatActivity { FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { @Override public void onComplete(@NonNull Task<InstanceIdResult> task) { - String key = FirebaseHelper.dbUser.push().getKey(); + String idFirebase = FirebaseHelper.dbUser.push().getKey(); String instanceId = task.getResult().getToken(); User user; - user = new User(instanceId, name, email, md5(password)); - user.setKey(instanceId); - PreferencesHelper.setUserFirebaseKey(AuthActivity.this, key); + user = new User(instanceId, name, email, md5(password), idFirebase); + PreferencesHelper.setUserFirebaseId(AuthActivity.this, user.getId()); + PreferencesHelper.setTokenKey(AuthActivity.this, user.getKey()); PreferencesHelper.setUserName(AuthActivity.this, user.getName()); PreferencesHelper.setHasLogin(AuthActivity.this, true); - FirebaseHelper.dbUser.child(key).setValue(user); + FirebaseHelper.dbUser.child(idFirebase).setValue(user); finish(); startActivity(new Intent(AuthActivity.this, MainActivity.class)); } diff --git a/android/app/src/main/java/com/chatman/ProfileFragment.java b/android/app/src/main/java/com/chatman/ProfileFragment.java index 5fb4df341b789756476fc545dad8e4f2b51c4ed4..811676fda257047a1239b0bcee4d6776acceb424 100644 --- a/android/app/src/main/java/com/chatman/ProfileFragment.java +++ b/android/app/src/main/java/com/chatman/ProfileFragment.java @@ -72,7 +72,7 @@ public class ProfileFragment extends Fragment { { Intent intent; intent = new Intent(getContext(), AuthActivity.class); - PreferencesHelper.setUserFirebaseKey(getContext(), ""); + PreferencesHelper.setUserFirebaseId(getContext(), ""); PreferencesHelper.setUserName(getContext(),""); PreferencesHelper.setHasLogin(getContext(), false); getActivity().finish(); diff --git a/android/app/src/main/java/com/chatman/helper/PreferencesHelper.java b/android/app/src/main/java/com/chatman/helper/PreferencesHelper.java index ad0608739f20ec2396251add9a961b0cc2c6bf77..28720f6094901d449af20f362ed1d98800fe2951 100644 --- a/android/app/src/main/java/com/chatman/helper/PreferencesHelper.java +++ b/android/app/src/main/java/com/chatman/helper/PreferencesHelper.java @@ -47,7 +47,7 @@ public class PreferencesHelper { return preferences.getInt(key, 0); } - public static void setUserFirebaseKey(Context context, String value) { + public static void setUserFirebaseId(Context context, String value) { setStringPreferences(context, USER_FIREBASE_KEY, value); } @@ -72,7 +72,7 @@ public class PreferencesHelper { return getBooleanPreferences(context, HAS_LOGIN); } - public static void setToken(Context context, String string) { + public static void setTokenKey(Context context, String string) { setStringPreferences(context, TOKEN, string); } diff --git a/android/app/src/main/java/com/chatman/model/User.java b/android/app/src/main/java/com/chatman/model/User.java index 0d1b9ad26833373414b63b5722a326a30fa1970b..519a3becadf40a2fcb612104c771516911649b58 100644 --- a/android/app/src/main/java/com/chatman/model/User.java +++ b/android/app/src/main/java/com/chatman/model/User.java @@ -5,16 +5,18 @@ public class User { private String name; private String email; private String password; + private String id; public User() { } - public User(String key, String name, String email, String password) { + public User(String key, String name, String email, String password, String id) { this.key = key; this.name = name; this.email = email; this.password = password; + this.id = id; } public String getKey() { @@ -48,4 +50,12 @@ public class User { public void setPassword(String password) { this.password = password; } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } } diff --git a/android/app/src/main/java/com/chatman/service/PushNotificationService.java b/android/app/src/main/java/com/chatman/service/PushNotificationService.java index 58ee1a604eaa86b83df572d1f5054cae8b852828..bb0a750661ba4b90ce8e044f8245189d3dc5aaca 100644 --- a/android/app/src/main/java/com/chatman/service/PushNotificationService.java +++ b/android/app/src/main/java/com/chatman/service/PushNotificationService.java @@ -43,7 +43,7 @@ public class PushNotificationService extends FirebaseMessagingService { @Override public void onNewToken(String s) { super.onNewToken(s); - PreferencesHelper.setToken(this, s); + PreferencesHelper.setTokenKey(this, s); Log.d(TAG, "onNewToken: " + s); Log.d(TAG, "onNewToken: " + PreferencesHelper.getUserFirebaseKey(this)); }