Search in sources :

Example 6 with EmployeeObject

use of aunguyen.quanlycongviec.Object.EmployeeObject in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class SelectEmployeeToJobActivity method getData.

private void getData() {
    Intent intent = getIntent();
    if (intent != null) {
        List<EmployeeObject> listEmployeeAdded = (List<EmployeeObject>) intent.getSerializableExtra("LIST_EMPLOYEE_ADDED");
        temp.addAll(listEmployees);
        // Loại bỏ bị trùng
        for (int i = 0; i < listEmployeeAdded.size(); i++) {
            EmployeeObject added = listEmployeeAdded.get(i);
            for (int j = 0; j < temp.size(); j++) {
                EmployeeObject employee = temp.get(j);
                if (added.getIdEmployee().equals(employee.getIdEmployee())) {
                    int posi = j - i;
                    listEmployees.remove(posi);
                    listCheck.remove(posi);
                    employeeAdapter.notifyDataSetChanged();
                    break;
                }
            }
        }
        progressDialog.dismiss();
    }
}
Also used : Intent(android.content.Intent) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with EmployeeObject

use of aunguyen.quanlycongviec.Object.EmployeeObject in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class SelectEmployeeToJobActivity method loadDataFromFireBase.

private void loadDataFromFireBase() {
    progressDialog = new ProgressDialog(this);
    progressDialog.show();
    SharedPreferences preferences = this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
    final String id = preferences.getString(Constant.PREFERENCE_KEY_ID, null);
    if (id != null) {
        DatabaseReference myRef = FirebaseDatabase.getInstance().getReference(Constant.NODE_NHAN_VIEN);
        myRef.addValueEventListener(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    EmployeeObject employeeObject = snapshot.getValue(EmployeeObject.class);
                    if (id.equals(employeeObject.getIdManage())) {
                        listEmployees.add(employeeObject);
                        listCheck.add(false);
                        employeeAdapter.notifyDataSetChanged();
                    }
                }
                getData();
            }

            @Override
            public void onCancelled(DatabaseError error) {
                Log.i("ABC", "Failed to read value.", error.toException());
            }
        });
    } else {
        progressDialog.dismiss();
        Log.i("ANTN", "ID Manage is null!");
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) SharedPreferences(android.content.SharedPreferences) DatabaseReference(com.google.firebase.database.DatabaseReference) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) ValueEventListener(com.google.firebase.database.ValueEventListener) ProgressDialog(android.app.ProgressDialog) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 8 with EmployeeObject

use of aunguyen.quanlycongviec.Object.EmployeeObject in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class SignUpActivity method signUp.

private void signUp() {
    final boolean[] isFirst = { true };
    final List<String> listDomain = new ArrayList<>();
    final String username = edtUsername.getText().toString();
    final String password = edtPassword.getText().toString();
    final String domain = edtDomain.getText().toString();
    final String fullName = edtFullName.getText().toString();
    final String phone = edtPhone.getText().toString();
    final String address = edtAddress.getText().toString();
    final DatabaseReference referenceDomain, referenceEmployee;
    referenceDomain = database.getReference(Constant.NODE_DOMAIN);
    referenceEmployee = database.getReference(Constant.NODE_NHAN_VIEN);
    // Check domain exist
    referenceDomain.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                String domain = snapshot.getValue(String.class);
                listDomain.add(domain);
            }
            if (listDomain.contains(domain) && isFirst[0]) {
                Toast.makeText(SignUpActivity.this, "Domain cua ban da ton tai!!!", Toast.LENGTH_SHORT).show();
                isFirst[0] = false;
            } else if (isFirst[0]) {
                if (!username.equals("") && !password.equals("") && !domain.equals("") && !fullName.equals("")) {
                    mAuth.createUserWithEmailAndPassword(username + domain, password).addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {

                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                FirebaseUser user = mAuth.getCurrentUser();
                                EmployeeObject employeeObject = new EmployeeObject();
                                employeeObject.setAccountType("0");
                                employeeObject.setIdEmployee(user.getUid());
                                employeeObject.setIdManage("");
                                employeeObject.setUsernameEmployee(username + domain);
                                if (!phone.equals("")) {
                                    employeeObject.setPhoneEmployee(phone);
                                } else {
                                    employeeObject.setPhoneEmployee("");
                                }
                                if (!address.equals("")) {
                                    employeeObject.setAddressEmployee(address);
                                } else {
                                    employeeObject.setAddressEmployee("");
                                }
                                employeeObject.setNameEmployee(fullName);
                                if (rdbMale.isChecked()) {
                                    employeeObject.setGenderEmployee("Nam");
                                    employeeObject.setUrlAvatar(Constant.URL_MALE);
                                } else {
                                    employeeObject.setGenderEmployee("Nu");
                                    employeeObject.setUrlAvatar(Constant.URL_FEMALE);
                                }
                                employeeObject.setBirthdayEmployee("01/01/1990");
                                referenceEmployee.child(user.getUid()).setValue(employeeObject);
                                referenceDomain.push().setValue(domain);
                                Toast.makeText(SignUpActivity.this, "Dang ky thanh cong!!!", Toast.LENGTH_SHORT).show();
                                isFirst[0] = false;
                                SharedPreferences preferences = SignUpActivity.this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putString(Constant.PREFERENCE_DOMAIN, domain);
                                editor.apply();
                                startActivity(new Intent(SignUpActivity.this, SignInActivity.class));
                            }
                        }
                    });
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) AuthResult(com.google.firebase.auth.AuthResult) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 9 with EmployeeObject

use of aunguyen.quanlycongviec.Object.EmployeeObject in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class AddEmployeeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull EmployeeViewHolder holder, final int position) {
    EmployeeObject employeeObject = employeeObjectList.get(position);
    holder.tvNameEmployee.setText(employeeObject.getNameEmployee());
    Glide.with(context).load(employeeObject.getUrlAvatar()).into(holder.imgAvatar);
}
Also used : EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject)

Example 10 with EmployeeObject

use of aunguyen.quanlycongviec.Object.EmployeeObject in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class AddEmployeeActivity method signUp.

private void signUp() {
    SharedPreferences preferences = AddEmployeeActivity.this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
    final String id = preferences.getString(Constant.PREFERENCE_KEY_ID, null);
    final String domain = preferences.getString(Constant.PREFERENCE_DOMAIN, null);
    final String username = edtUsername.getText().toString();
    final String password = edtPassword.getText().toString();
    final String fullName = edtFullName.getText().toString();
    final String phone = edtPhone.getText().toString();
    final String address = edtAddress.getText().toString();
    final DatabaseReference referenceEmployee;
    referenceEmployee = databaseEmployee.getReference(Constant.NODE_NHAN_VIEN);
    if (!username.equals("") && !password.equals("") && !fullName.equals("")) {
        mAuth.createUserWithEmailAndPassword(username + domain, password).addOnCompleteListener(AddEmployeeActivity.this, new OnCompleteListener<AuthResult>() {

            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    FirebaseUser user = mAuth.getCurrentUser();
                    EmployeeObject employeeObject = new EmployeeObject();
                    if (rdbAdmin.isChecked()) {
                        employeeObject.setAccountType("0");
                    } else {
                        employeeObject.setAccountType("1");
                    }
                    employeeObject.setIdEmployee(user.getUid());
                    employeeObject.setIdManage(id);
                    employeeObject.setUsernameEmployee(username + domain);
                    if (!phone.equals("")) {
                        employeeObject.setPhoneEmployee(phone);
                    } else {
                        employeeObject.setPhoneEmployee("");
                    }
                    if (!address.equals("")) {
                        employeeObject.setAddressEmployee(address);
                    } else {
                        employeeObject.setAddressEmployee("");
                    }
                    employeeObject.setNameEmployee(fullName);
                    if (rdbMale.isChecked()) {
                        employeeObject.setGenderEmployee("Nam");
                        employeeObject.setUrlAvatar(Constant.URL_MALE);
                    } else {
                        employeeObject.setGenderEmployee("Nu");
                        employeeObject.setUrlAvatar(Constant.URL_FEMALE);
                    }
                    employeeObject.setBirthdayEmployee("01/01/1990");
                    referenceEmployee.child(user.getUid()).setValue(employeeObject);
                    Toast.makeText(AddEmployeeActivity.this, "Dang ky thanh cong!!!", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) DatabaseReference(com.google.firebase.database.DatabaseReference) AuthResult(com.google.firebase.auth.AuthResult) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

EmployeeObject (aunguyen.quanlycongviec.Object.EmployeeObject)11 SharedPreferences (android.content.SharedPreferences)6 DatabaseReference (com.google.firebase.database.DatabaseReference)6 DataSnapshot (com.google.firebase.database.DataSnapshot)4 DatabaseError (com.google.firebase.database.DatabaseError)4 ValueEventListener (com.google.firebase.database.ValueEventListener)4 ArrayList (java.util.ArrayList)4 ProgressDialog (android.app.ProgressDialog)3 Intent (android.content.Intent)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AuthResult (com.google.firebase.auth.AuthResult)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2 CardView (android.support.v7.widget.CardView)1 JobObject (aunguyen.quanlycongviec.Object.JobObject)1 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1