Guest User

Untitled

a guest
Apr 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. final String admin_id = textInputEditTextAdminID.getText().toString();
  2. final String myPin = textInputEditTextPin.getText().toString();
  3.  
  4. //displays the progressDialog with a title when logging admin in
  5. progressDialog = ProgressDialog.show(AdminLoginActivity.this, "Logging In...", null, true, true);
  6. progressDialog.setMessage("Please wait");
  7.  
  8.  
  9. adminRef.child(admin_id).addValueEventListener(new ValueEventListener() {
  10. @Override
  11. public void onDataChange(DataSnapshot dataSnapshot) {
  12. if (dataSnapshot.exists()) {
  13. Admin admin = dataSnapshot.getValue(Admin.class);
  14. if (myPin.equals(admin.getPin())) {
  15. final Timer timer = new Timer();
  16. timer.schedule(new TimerTask() {
  17. public void run() {
  18. progressDialog.dismiss(); //dismisses the alertDialog
  19. timer.cancel(); //this will cancel the timer of the system
  20. }
  21. }, 5000); // the timer will count 5 seconds....
  22. clearTextFields();
  23. Toast.makeText(AdminLoginActivity.this, "You have Successfully Logged In...", Toast.LENGTH_LONG).show();
  24. // Admin admin = new Admin();
  25. //Intent intentPanel = new Intent(AdminLoginActivity.this, AdminPanel.class);
  26. //startActivity(intentPanel);
  27.  
  28. Intent intent_manageAdminAccount = new Intent(AdminLoginActivity.this, ManageAccount.class);
  29. intent_manageAdminAccount.putExtra("admin_id", admin.getAdmin_id());
  30. intent_manageAdminAccount.putExtra("pin", admin.getPin());
  31. intent_manageAdminAccount.putExtra("key", admin.getAdmin_id());
  32. startActivity(intent_manageAdminAccount);
  33.  
  34. /*if(intent_manageAdminAccunt.hasExtra("admin_id")
  35. && intent_manageAdminAccunt.hasExtra("pin")
  36. && intent_manageAdminAccunt.hasExtra("key"))
  37. {
  38. Intent intentPanel = new Intent(AdminLoginActivity.this, AdminPanel.class);
  39. startActivity(intentPanel);
  40. }*/
  41.  
  42.  
  43. // AdminLoginActivity.this.finish();
  44.  
  45. Intent intentPanel = new Intent(AdminLoginActivity.this, AdminPanel.class);
  46. startActivity(intentPanel);
  47. // AdminLoginActivity.this.finish();
  48.  
  49. }
  50. else {
  51. final Timer timer = new Timer();
  52. timer.schedule(new TimerTask() {
  53. public void run() {
  54. progressDialog.dismiss(); //dismisses the alertDialog
  55. timer.cancel(); //this will cancel the timer of the system
  56. }
  57. }, 3000); // the timer will count 3 seconds....
  58. clearTextFields();
  59. Toast.makeText(AdminLoginActivity.this, "Incorrect Admin ID or Pin...", Toast.LENGTH_LONG).show();
  60. }
  61.  
  62. } else {
  63. final Timer timer = new Timer();
  64. timer.schedule(new TimerTask() {
  65. public void run() {
  66. progressDialog.dismiss(); //dismisses the alertDialog
  67. timer.cancel(); //this will cancel the timer of the system
  68. }
  69. }, 3000); // the timer will count 3 seconds....
  70. clearTextFields();
  71. Toast.makeText(AdminLoginActivity.this, "Admin does not exist in database!!", Toast.LENGTH_LONG).show();
  72. }
  73.  
  74. }
  75.  
  76. @Override
  77. public void onCancelled(DatabaseError databaseError) {
  78. Toast.makeText(AdminLoginActivity.this, databaseError.toException().toString(), Toast.LENGTH_LONG).show();
  79. }
  80. });
  81.  
  82. }
Add Comment
Please, Sign In to add comment