-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileActivity.java
78 lines (65 loc) · 2.93 KB
/
ProfileActivity.java
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
package com.example.pet1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
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.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class ProfileActivity extends AppCompatActivity {
private FirebaseUser user;
private DatabaseReference reference;
private String userID;
private Button logout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
logout = (Button) findViewById(R.id.singOut);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(ProfileActivity.this,MainActivity.class));
}
});
user = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("Users");
userID = user.getUid();
final TextView greetingTextView = (TextView) findViewById(R.id.merhaba);
final TextView fullNameTextView = (TextView) findViewById(R.id.fullName);
final TextView emailTextView = (TextView) findViewById(R.id.emailAddress);
final TextView ageTextView = (TextView) findViewById(R.id.age);
final TextView numberTextView = (TextView) findViewById(R.id.number);
reference.child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
User userProfile = snapshot.getValue(User.class);
if(userProfile != null){
String fullname = userProfile.fullname;
String email = userProfile.email;
String age = userProfile.age;
String number = userProfile.number;
greetingTextView.setText("Merhaba," + fullname + "!");
fullNameTextView.setText(fullname);
emailTextView.setText(email);
ageTextView.setText(age);
numberTextView.setText(number);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(ProfileActivity.this,"Bir hata oluştu!",Toast.LENGTH_LONG).show();
}
});
}
}