Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <activity android:name=".ui.MapCustomActivity"></activity>
- <activity android:name=".ui.LoginActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- public class LoginActivity extends AppCompatActivity implements
- View.OnClickListener
- {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- mEmail = findViewById(R.id.email);
- mPassword = findViewById(R.id.password);
- mProgressBar = findViewById(R.id.progressBar);
- setupFirebaseAuth();
- findViewById(R.id.email_sign_in_button).setOnClickListener(this);
- findViewById(R.id.link_register).setOnClickListener(this);
- hideSoftKeyboard();
- }
- private void showDialog(){
- mProgressBar.setVisibility(View.VISIBLE);
- }
- private void hideDialog(){
- if(mProgressBar.getVisibility() == View.VISIBLE){
- mProgressBar.setVisibility(View.INVISIBLE);
- }
- }
- private void setupFirebaseAuth(){
- Log.d(TAG, "setupFirebaseAuth: started.");
- mAuthListener = new FirebaseAuth.AuthStateListener() {
- @Override
- public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
- FirebaseUser user = firebaseAuth.getCurrentUser();
- //user = null;
- if (user != null) {
- Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
- Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getEmail());
- Toast.makeText(LoginActivity.this, "Authenticated with: " + user.getEmail(), Toast.LENGTH_SHORT).show();
- FirebaseFirestore db = FirebaseFirestore.getInstance();
- FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
- .setTimestampsInSnapshotsEnabled(true)
- .build();
- db.setFirestoreSettings(settings);
- DocumentReference userRef = db.collection(getString(R.string.collection_users))
- .document(user.getUid());
- userRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
- @Override
- public void onComplete(@NonNull Task<DocumentSnapshot> task) {
- if(task.isSuccessful()){
- Log.d(TAG, "onComplete: successfully set the user client." + task.getResult());
- User user = task.getResult().toObject(User.class);
- ((UserClient)(getApplicationContext())).setUser(user);
- }
- }
- });
- Intent intent = new Intent(LoginActivity.this, MapCustomActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- finish();
- } else {
- // User is signed out
- Log.d(TAG, "onAuthStateChanged:signed_out");
- }
- // ...
- }
- };
- }
- public class MapCustomActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_map_custom);
- photoview2 = (ImageView) findViewById(R.id.limerickMapImageView);
- mAvatarImage = (ImageView) findViewById(R.id.imageChooseAvatar);
- photoview2.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- ImageView view = (ImageView) v;
- view.bringToFront();
- viewTransformation(view, event);
- return true;
- }
- });
- retrieveProfileImage();
- }
- private void retrieveProfileImage(){
- RequestOptions requestOptions = new RequestOptions()
- .error(R.drawable.cwm_logo)
- .placeholder(R.drawable.cwm_logo);
- int avatar = 0;
- try{
- avatar = Integer.parseInt(((UserClient)getApplicationContext()).getUser().getAvatar());
- }catch (NumberFormatException e){
- Log.e(TAG, "retrieveProfileImage: no avatar image. Setting default. " + e.getMessage() );
- }
- Glide.with(MapCustomActivity.this)
- .setDefaultRequestOptions(requestOptions)
- .load(avatar)
- .into(mAvatarImage);
- }
- private User user = null;
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement