ProfileActivity.java
2.55 KB
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
package com.example.user.firebaseauthdemo;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class ProfileActivity extends AppCompatActivity implements View.OnClickListener{
private FirebaseAuth firebaseAuth;
private TextView textViewUserEmail;
private Button buttonLogout;
private DatabaseReference databaseReference;
private EditText editTextName, editTextAddress;
private Button buttonSave;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() == null){
finish();
startActivity(new Intent(this,LoginActivity.class));
}
databaseReference = FirebaseDatabase.getInstance().getReference();
editTextAddress = (EditText) findViewById(R.id.editTextAddress);
editTextName = (EditText)findViewById(R.id.editTextName);
buttonSave = (Button)findViewById(R.id.buttonSave);
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
textViewUserEmail.setText("Welcome " + user.getEmail());
buttonLogout = (Button)findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
buttonSave.setOnClickListener(this);
}
private void saveUserInformation(){
String name = editTextName.getText().toString().trim();
String add = editTextAddress.getText().toString().trim();
UserInformation userInformation = new UserInformation(name, add);
FirebaseUser user = firebaseAuth.getCurrentUser();
databaseReference.child(user.getUid()).setValue(userInformation);
Toast.makeText(this, "Information Saved...", Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View view) {
if(view == buttonLogout){
firebaseAuth.signOut();
finish();
startActivity(new Intent(this, LoginActivity.class));
}
if(view == buttonSave){
saveUserInformation();
}
}
}