Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <activity android:name=".ui.MapCustomActivity"></activity>
  2. <activity android:name=".ui.LoginActivity">
  3. <intent-filter>
  4. <action android:name="android.intent.action.MAIN" />
  5.  
  6. <category android:name="android.intent.category.LAUNCHER" />
  7. </intent-filter>
  8. </activity>
  9.  
  10. public class LoginActivity extends AppCompatActivity implements
  11. View.OnClickListener
  12. {
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_login);
  17. mEmail = findViewById(R.id.email);
  18. mPassword = findViewById(R.id.password);
  19. mProgressBar = findViewById(R.id.progressBar);
  20.  
  21. setupFirebaseAuth();
  22. findViewById(R.id.email_sign_in_button).setOnClickListener(this);
  23. findViewById(R.id.link_register).setOnClickListener(this);
  24.  
  25. hideSoftKeyboard();
  26. }
  27.  
  28.  
  29.  
  30.  
  31. private void showDialog(){
  32. mProgressBar.setVisibility(View.VISIBLE);
  33.  
  34. }
  35.  
  36. private void hideDialog(){
  37. if(mProgressBar.getVisibility() == View.VISIBLE){
  38. mProgressBar.setVisibility(View.INVISIBLE);
  39. }
  40. }
  41.  
  42.  
  43.  
  44.  
  45. private void setupFirebaseAuth(){
  46. Log.d(TAG, "setupFirebaseAuth: started.");
  47.  
  48. mAuthListener = new FirebaseAuth.AuthStateListener() {
  49. @Override
  50. public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  51. FirebaseUser user = firebaseAuth.getCurrentUser();
  52. //user = null;
  53. if (user != null) {
  54. Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
  55. Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getEmail());
  56. Toast.makeText(LoginActivity.this, "Authenticated with: " + user.getEmail(), Toast.LENGTH_SHORT).show();
  57.  
  58. FirebaseFirestore db = FirebaseFirestore.getInstance();
  59. FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
  60. .setTimestampsInSnapshotsEnabled(true)
  61. .build();
  62. db.setFirestoreSettings(settings);
  63.  
  64. DocumentReference userRef = db.collection(getString(R.string.collection_users))
  65. .document(user.getUid());
  66.  
  67. userRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
  68. @Override
  69. public void onComplete(@NonNull Task<DocumentSnapshot> task) {
  70. if(task.isSuccessful()){
  71. Log.d(TAG, "onComplete: successfully set the user client." + task.getResult());
  72. User user = task.getResult().toObject(User.class);
  73. ((UserClient)(getApplicationContext())).setUser(user);
  74. }
  75. }
  76. });
  77.  
  78. Intent intent = new Intent(LoginActivity.this, MapCustomActivity.class);
  79. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  80. startActivity(intent);
  81. finish();
  82.  
  83. } else {
  84. // User is signed out
  85. Log.d(TAG, "onAuthStateChanged:signed_out");
  86. }
  87. // ...
  88. }
  89. };
  90. }
  91.  
  92. public class MapCustomActivity extends AppCompatActivity {
  93.  
  94. @Override
  95. protected void onCreate(Bundle savedInstanceState) {
  96. super.onCreate(savedInstanceState);
  97. requestWindowFeature(Window.FEATURE_NO_TITLE);
  98. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  99. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  100.  
  101. setContentView(R.layout.activity_map_custom);
  102.  
  103. photoview2 = (ImageView) findViewById(R.id.limerickMapImageView);
  104. mAvatarImage = (ImageView) findViewById(R.id.imageChooseAvatar);
  105.  
  106. photoview2.setOnTouchListener(new View.OnTouchListener() {
  107. @Override
  108. public boolean onTouch(View v, MotionEvent event) {
  109. ImageView view = (ImageView) v;
  110. view.bringToFront();
  111. viewTransformation(view, event);
  112. return true;
  113. }
  114. });
  115. retrieveProfileImage();
  116.  
  117. }
  118. private void retrieveProfileImage(){
  119. RequestOptions requestOptions = new RequestOptions()
  120. .error(R.drawable.cwm_logo)
  121. .placeholder(R.drawable.cwm_logo);
  122.  
  123. int avatar = 0;
  124.  
  125. try{
  126.  
  127. avatar = Integer.parseInt(((UserClient)getApplicationContext()).getUser().getAvatar());
  128. }catch (NumberFormatException e){
  129. Log.e(TAG, "retrieveProfileImage: no avatar image. Setting default. " + e.getMessage() );
  130. }
  131.  
  132. Glide.with(MapCustomActivity.this)
  133. .setDefaultRequestOptions(requestOptions)
  134. .load(avatar)
  135. .into(mAvatarImage);
  136. }
  137.  
  138. private User user = null;
  139.  
  140. public User getUser() {
  141. return user;
  142. }
  143.  
  144. public void setUser(User user) {
  145. this.user = user;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement