Search in sources :

Example 56 with ValueEventListener

use of com.google.firebase.database.ValueEventListener 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 ValueEventListener

use of com.google.firebase.database.ValueEventListener 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 ValueEventListener

use of com.google.firebase.database.ValueEventListener 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 59 with ValueEventListener

use of com.google.firebase.database.ValueEventListener 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)

Example 60 with ValueEventListener

use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.

the class MyRequestDetail method onCreateView.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mAuth = FirebaseAuth.getInstance();
    user = mAuth.getCurrentUser();
    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            request = null;
        } else {
            request = extras.getString("request");
        }
    }
    if (request != null && !request.isEmpty()) {
        FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(request).addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                BloodRequest data = dataSnapshot.getValue(BloodRequest.class);
                TextView mName = (TextView) findViewById(R.id.name);
                mName.setText(data.name);
                TextView mTime = (TextView) findViewById(R.id.time);
                String date = DateFormat.getDateInstance().format(new Date(data.date));
                mTime.setText(date);
                TextView mLocation = (TextView) findViewById(R.id.location);
                mLocation.setText(data.location);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }
    View rootView = inflater.inflate(R.layout.fragment_my_request_details, container, false);
    db = FirebaseDatabase.getInstance().getReference().child("donations");
    fetchData();
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.respondent_list_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new RecycleMarginDecoration(this));
    mAdapter = new RespondentListDataAdapter(users, this);
    mRecyclerView.setAdapter(mAdapter);
    return rootView;
}
Also used : RespondentListDataAdapter(com.jexapps.bloodhub.m_UI.RespondentListDataAdapter) Bundle(android.os.Bundle) DataSnapshot(com.google.firebase.database.DataSnapshot) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Date(java.util.Date) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) DatabaseError(com.google.firebase.database.DatabaseError) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest)

Aggregations

DataSnapshot (com.google.firebase.database.DataSnapshot)211 ValueEventListener (com.google.firebase.database.ValueEventListener)211 DatabaseError (com.google.firebase.database.DatabaseError)210 DatabaseReference (com.google.firebase.database.DatabaseReference)62 View (android.view.View)47 Intent (android.content.Intent)43 TextView (android.widget.TextView)30 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)24 RecyclerView (android.support.v7.widget.RecyclerView)20 FirebaseUser (com.google.firebase.auth.FirebaseUser)20 HashMap (java.util.HashMap)20 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)19 Bundle (android.os.Bundle)16 ImageView (android.widget.ImageView)15 ArrayList (java.util.ArrayList)15 User (com.jexapps.bloodhub.m_Model.User)11 Map (java.util.Map)11 Date (java.util.Date)10 Query (com.google.firebase.database.Query)9 User (com.polito.mad17.madmax.entities.User)9