Guest User

Untitled

a guest
Dec 14th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. public class UserProfileActivity extends AppCompatActivity {
  2.  
  3. // Creating button.
  4. Button logout;
  5.  
  6. // Creating TextView.
  7. TextView userEmailShow, text, text2, text3, text4, text5, text6, text7;
  8.  
  9. // Creating FirebaseAuth.
  10. FirebaseAuth firebaseAuth;
  11. TextView ShowDataTextView;
  12. String NameHolder, NumberHolder;
  13. // Creating FirebaseAuth.
  14. FirebaseUser firebaseUser;
  15. Firebase firebase;
  16. public static final String Firebase_Server_URL = "https://gakusei-
  17. go.firebaseio.com/";
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_user_profile);
  23.  
  24. // Assigning ID's to button and TextView.
  25. logout = (Button) findViewById(R.id.logout);
  26. userEmailShow = (TextView) findViewById(R.id.user_email);
  27. text = (TextView)findViewById(R.id.textView);
  28. text2 = (TextView)findViewById(R.id.textView2);
  29. text3 = (TextView)findViewById(R.id.textView3);
  30. text4 = (TextView)findViewById(R.id.textView4);
  31. text5 = (TextView)findViewById(R.id.textView5);
  32. text6 = (TextView)findViewById(R.id.textView6);
  33. text7 = (TextView)findViewById(R.id.textView7);
  34.  
  35.  
  36.  
  37. // Adding FirebaseAuth instance to FirebaseAuth object.
  38. firebaseAuth = FirebaseAuth.getInstance();
  39.  
  40. // On activity start check whether there is user previously logged in or not.
  41. if (firebaseAuth.getCurrentUser() == null) {
  42.  
  43. // Finishing current Profile activity.
  44. finish();
  45.  
  46. // If user already not log in then Redirect to LoginActivity .
  47. Intent intent = new Intent(UserProfileActivity.this, LoginActivity.class);
  48. startActivity(intent);
  49.  
  50. // Showing toast message.
  51. Toast.makeText(UserProfileActivity.this, "Please log in to continue", Toast.LENGTH_LONG).show();
  52.  
  53. }
  54.  
  55. // Adding firebaseAuth current user info into firebaseUser object.
  56. firebaseUser = firebaseAuth.getCurrentUser();
  57.  
  58. // Getting logged in user email from firebaseUser.getEmail() method and set into TextView.
  59. userEmailShow.setText("Welcome " + firebaseUser.getEmail());
  60. firebase.child("Student").addListenerForSingleValueEvent(new ValueEventListener() {
  61. @Override
  62. public void onDataChange(DataSnapshot MainSnapshot) {
  63.  
  64. Student student = MainSnapshot.getValue(Student.class);
  65.  
  66. // Adding name and phone number of student into string that is coming from server.
  67.  
  68. String pname = student.getPname();
  69. String pnum = student.getPhonenumber();
  70. String sname = student.getStudentname();
  71. String email = student.getEmail();
  72. String dorm = student.getDorm();
  73. String password = student.getPassword();
  74. String clas = student.getStudentclass();
  75.  
  76. text.setText(pname);
  77. text2.setText(pnum);
  78. text3.setText(sname);
  79. text4.setText(email);
  80. text5.setText(dorm);
  81. text6.setText(password);
  82. text7.setText(clas);
  83. }
  84.  
  85. @Override
  86. public void onCancelled(FirebaseError firebaseError) {
  87. System.out.println("Data Access Failed" + firebaseError.getMessage());
  88. }
  89. });
Add Comment
Please, Sign In to add comment