Search in sources :

Example 56 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class MainActivity 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_CONG_VIEC);
        myRef.addValueEventListener(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    JobObject jobObject = snapshot.getValue(JobObject.class);
                    if (id.equals(jobObject.getIdManageJob())) {
                        listJobs.add(jobObject);
                        jobAdapter.notifyDataSetChanged();
                    }
                }
                progressDialog.dismiss();
            }

            @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) ValueEventListener(com.google.firebase.database.ValueEventListener) ProgressDialog(android.app.ProgressDialog) DataSnapshot(com.google.firebase.database.DataSnapshot) JobObject(aunguyen.quanlycongviec.Object.JobObject)

Example 57 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class ManageMyEmployeesActivity method loadData.

private void loadData() {
    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(getResources().getString(R.string.dialog));
    progressDialog.show();
    SharedPreferences preferences = this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
    final String id = preferences.getString(Constant.PREFERENCE_KEY_ID, null);
    Log.i("ANTN", "ID: " + id);
    if (id != null) {
        DatabaseReference myRef = database.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())) {
                        listEmployee.add(employeeObject);
                        employeeAdapter.notifyDataSetChanged();
                    }
                }
                progressDialog.dismiss();
            }

            @Override
            public void onCancelled(DatabaseError error) {
                progressDialog.dismiss();
            }
        });
    }
}
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 58 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.

the class AddJobActivity method addJob.

private void addJob() {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setTitle(getResources().getString(R.string.dialog));
    String title = edtTitle.getText().toString();
    String description = edtDescription.getText().toString();
    String timeStart = tvStart.getText().toString();
    String timeEnd = tvEnd.getText().toString();
    if (!title.equals("") && !description.equals("") && !timeStart.equals(getResources().getString(R.string.job_start)) && !timeEnd.equals(getResources().getString(R.string.job_end)) && listEmployees.size() > 0) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        Date date = new Date();
        String now = dateFormat.format(date);
        if (compareDate(now, timeStart) && compareDate(timeStart, timeEnd)) {
            FirebaseDatabase database = FirebaseDatabase.getInstance();
            DatabaseReference reference = database.getReference().child(Constant.NODE_CONG_VIEC);
            String idJob = reference.push().getKey();
            SharedPreferences preferences = getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
            String idManage = preferences.getString(Constant.PREFERENCE_KEY_ID, "");
            List<String> listIdMember = new ArrayList();
            for (EmployeeObject object : listEmployees) {
                listIdMember.add(object.getIdEmployee());
            }
            JobObject jobObject = new JobObject();
            jobObject.setIdJob(idJob);
            jobObject.setIdManageJob(idManage);
            jobObject.setTitleJob(title);
            jobObject.setDescriptionJob(description);
            jobObject.setStartDateJob(timeStart);
            jobObject.setEndDateJob(timeEnd);
            jobObject.setStatusJob(Constant.NOT_RECEIVED);
            jobObject.setListIdMember(listIdMember);
            dialog.show();
            reference.child(idJob).setValue(jobObject).addOnSuccessListener(new OnSuccessListener<Void>() {

                @Override
                public void onSuccess(Void aVoid) {
                    dialog.dismiss();
                    Toast.makeText(AddJobActivity.this, "Success!", Toast.LENGTH_SHORT).show();
                }
            });
        } else {
            Toast.makeText(this, "Date is fail!", Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(this, "Data is empty!", Toast.LENGTH_SHORT).show();
    }
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) ProgressDialog(android.app.ProgressDialog) Date(java.util.Date) JobObject(aunguyen.quanlycongviec.Object.JobObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 59 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project HikingApp by wickhama.

the class Database method getTrailMetadata.

public void getTrailMetadata(final String trailID, final MetadataListener DBlistener) {
    // DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference rootRef = myRef;
    DatabaseReference ref = rootRef.child("Trails");
    ValueEventListener eventListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Trail.Metadata metadata = dataSnapshot.child(trailID).child("metadata").getValue(Trail.Metadata.class);
            DBlistener.onMetadata(metadata);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
    ref.addListenerForSingleValueEvent(eventListener);
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 60 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project HikingApp by wickhama.

the class Database method getTrail.

public void getTrail(final String trailID, final DataTrailListener DBlistener) {
    // DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference rootRef = myRef;
    DatabaseReference ref = rootRef.child("Trails");
    ValueEventListener eventListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            DBlistener.onDataTrail(dataSnapshot.child(trailID).getValue(Trail.class));
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
    ref.addListenerForSingleValueEvent(eventListener);
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

DatabaseReference (com.google.firebase.database.DatabaseReference)157 DatabaseError (com.google.firebase.database.DatabaseError)95 DataSnapshot (com.google.firebase.database.DataSnapshot)87 ValueEventListener (com.google.firebase.database.ValueEventListener)61 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)50 HashMap (java.util.HashMap)24 View (android.view.View)18 MutableData (com.google.firebase.database.MutableData)17 Transaction (com.google.firebase.database.Transaction)17 Intent (android.content.Intent)16 FirebaseUser (com.google.firebase.auth.FirebaseUser)13 ArrayList (java.util.ArrayList)12 TextView (android.widget.TextView)11 Query (com.google.firebase.database.Query)11 Map (java.util.Map)11 ProgressDialog (android.app.ProgressDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ChildEventListener (com.google.firebase.database.ChildEventListener)9 SharedPreferences (android.content.SharedPreferences)8 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8