Advertisement
Guest User

Untitled

a guest
May 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.45 KB | None | 0 0
  1. package com.rayen.testfirebase.activities;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.os.Bundle;
  8. import android.support.annotation.NonNull;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.ProgressBar;
  14. import android.widget.Toast;
  15.  
  16. import com.google.firebase.auth.FirebaseAuth;
  17. import com.google.firebase.database.DataSnapshot;
  18. import com.google.firebase.database.DatabaseError;
  19. import com.google.firebase.database.DatabaseReference;
  20. import com.google.firebase.database.FirebaseDatabase;
  21. import com.google.firebase.database.Query;
  22. import com.google.firebase.database.ValueEventListener;
  23. import com.rayen.testfirebase.R;
  24. import com.rayen.testfirebase.models.Employe;
  25.  
  26. import java.util.HashMap;
  27.  
  28. public class LoginActivity extends AppCompatActivity {
  29.     ProgressBar loginProgress;
  30.     DatabaseReference databaseEmploye;
  31.     boolean login;
  32.     HashMap<String, String> hash;
  33.     private EditText login_matricule;
  34.     private EditText login_password;
  35.     private Button login_button;
  36.     private int counter = 5;
  37.     FirebaseAuth firebaseAuth ;
  38.  
  39.  
  40.     public void login() {
  41.         final String mlogin_matricule = login_matricule.getText().toString();
  42.         final String mlogin_password = login_password.getText().toString();
  43.         Query loginquery = FirebaseDatabase.getInstance().getReference().child("Employe").orderByChild("matriculeEmploye").equalTo(login_matricule.getText().toString().trim());
  44.         loginquery.addListenerForSingleValueEvent(new ValueEventListener() {
  45.             @SuppressLint("ResourceType")
  46.             @Override
  47.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  48.                 if (dataSnapshot.getChildrenCount() > 0) {
  49.                     for (DataSnapshot data :
  50.                             dataSnapshot.getChildren()) {
  51.                         Employe e = data.getValue(Employe.class);
  52.  
  53.                         if (e.getPassEmploye().equals(login_password.getText().toString())) {
  54.                            
  55.                             if (e.getIsAdmin() == 1) {
  56.                                 session.setLoggedin(true,Integer.ParseInt(login_matricule.getText().toString(),"Admin");
  57.                                 Intent intent = new Intent(LoginActivity.this, EmployesActivity.class);
  58.                                 startActivity(intent);
  59.                                 finish();
  60.                             } else if (e.getSrvcEmploye().equals("Maintenance")) {
  61.                                 session.setLoggedin(true,Integer.ParseInt(login_matricule.getText().toString(),"Maintenance");
  62.                                 Intent intent = new Intent(LoginActivity.this, AddReclamationActivity.class);
  63.                                 startActivity(intent);
  64.                                 finish();
  65.                             } else {
  66.                                 session.setLoggedin(true,Integer.ParseInt(login_matricule.getText().toString(),"Demandeur");
  67.                                 Intent intent = new Intent(LoginActivity.this, DemandeurActivity.class);
  68.                                 startActivity(intent);
  69.                                 finish();
  70.                             }
  71.                         } else {
  72.                             Toast.makeText(LoginActivity.this, "mot de passe incorrecte!!!", Toast.LENGTH_SHORT).show();
  73.                         }
  74.                         return;
  75.                     }
  76.                 } else {
  77.                     Toast.makeText(LoginActivity.this, "utilisateur non trouvé!!!", Toast.LENGTH_SHORT).show();
  78.                 }
  79.  
  80.             }
  81.  
  82.             @Override
  83.             public void onCancelled(@NonNull DatabaseError databaseError) {
  84.  
  85.             }
  86.         });
  87.  
  88.         ;
  89.     }
  90.  
  91.     public void checkEntries() {
  92.         if ((login_matricule.getText().toString().isEmpty()) || (login_password.getText().toString().isEmpty())) {
  93.             Toast.makeText(this, "matricule et mot de passe sont vide !!! ", Toast.LENGTH_SHORT).show();
  94.  
  95.  
  96.         } else {
  97.             login();
  98.         }
  99.  
  100.     }
  101.  
  102.     @Override
  103.     protected void onCreate(Bundle savedInstanceState) {
  104.         super.onCreate(savedInstanceState);
  105.         setContentView(R.layout.activity_login);
  106.         session = new session(getApplicationContext());
  107.         login_matricule = (EditText) findViewById(R.id.login_matricule);
  108.         login_password = (EditText) findViewById(R.id.login_password);
  109.         login_button = (Button) findViewById(R.id.login_button);
  110.         loginProgress = findViewById(R.id.login_progress);
  111.         loginProgress.setVisibility(View.INVISIBLE);
  112.         databaseEmploye = FirebaseDatabase.getInstance().getReference("Employe");
  113.  
  114.         hash = new HashMap<>();
  115.         login_button.setOnClickListener(new View.OnClickListener() {
  116.             @SuppressLint("ResourceType")
  117.             @Override
  118.             public void onClick(View v) {
  119.                 checkEntries();
  120.  
  121.  
  122.             }
  123.         });
  124.         Runnable progressRunnable = new Runnable() {
  125.  
  126.             @Override
  127.             public void run() {
  128.                 loginProgress.setVisibility(View.INVISIBLE);
  129.                 login_button.setVisibility(View.VISIBLE);
  130.             }
  131.         };
  132.         android.os.Handler pdCanceller = new android.os.Handler();
  133.         pdCanceller.postDelayed(progressRunnable, 3000);
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement