Search in sources :

Example 6 with ChildEventListener

use of com.google.firebase.database.ChildEventListener in project OnlineCanteen by josephgunawan97.

the class AdminVerifyStoreActivity method attachDatabaseReadListener.

private void attachDatabaseReadListener() {
    if (EventListener == null) {
        EventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                String storeString = dataSnapshot.getValue().toString();
                Log.d("TEST", storeString);
                if (storeString.equals("UNVERIFIED_STORE"))
                    adapter.addTopUp(dataSnapshot.getKey());
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                String storeString = dataSnapshot.getValue().toString();
                Log.d("TEST", storeString);
                if (storeString.equals("UNVERIFIED_STORE"))
                    adapter.addTopUp(dataSnapshot.getKey());
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        };
        FirebaseDatabase.getInstance().getReference("role").addChildEventListener(EventListener);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 7 with ChildEventListener

use of com.google.firebase.database.ChildEventListener in project EC2018App by Manan-YMCA.

the class DashboardSliderFragment1 method attachDatabaseListener.

private void attachDatabaseListener() {
    if (mChildEventListener == null) {
        mChildEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                WhatsNewModel w = dataSnapshot.getValue(WhatsNewModel.class);
                whatsnewarraylist.add(w);
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                try {
                    WhatsNewModel w = dataSnapshot.getValue(WhatsNewModel.class);
                    whatsnewarraylist.add(w);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
                WhatsNewModel w = dataSnapshot.getValue(WhatsNewModel.class);
                whatsnewarraylist.remove(w);
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        };
        mDatabaseReference.addChildEventListener(mChildEventListener);
        updateUI();
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) WhatsNewModel(com.manan.dev.ec2018app.Models.WhatsNewModel) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 8 with ChildEventListener

use of com.google.firebase.database.ChildEventListener in project EC2018App by Manan-YMCA.

the class StandUpFragment method attachDatabaseListener.

private void attachDatabaseListener() {
    if (mChildEventListener == null) {
        mChildEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                if (dataSnapshot.getKey().equals("hassrath")) {
                    BrixxEventModel w = dataSnapshot.getValue(BrixxEventModel.class);
                    // Toast.makeText(mContext,dataSnapshot.getValue().toString(),Toast.LENGTH_SHORT).show();
                    updateUI(w);
                }
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                try {
                    if (dataSnapshot.getKey().equals("hassrath")) {
                        BrixxEventModel w = dataSnapshot.getValue(BrixxEventModel.class);
                        updateUI(w);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        };
        mDatabaseReference.addChildEventListener(mChildEventListener);
    }
}
Also used : BrixxEventModel(com.manan.dev.ec2018app.Models.BrixxEventModel) DatabaseError(com.google.firebase.database.DatabaseError) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 9 with ChildEventListener

use of com.google.firebase.database.ChildEventListener in project Lets-Chat by kshitiz1007.

the class ChatActivity method loadMoreMessages.

// ---ON REFRESHING 10 MORE MESSAGES WILL LOAD----
private void loadMoreMessages() {
    DatabaseReference messageRef = mRootReference.child("messages").child(mCurrentUserId).child(mChatUser);
    Query messageQuery = messageRef.orderByKey().endAt(mLastKey).limitToLast(10);
    messageQuery.addChildEventListener(new ChildEventListener() {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Messages message = (Messages) dataSnapshot.getValue(Messages.class);
            String messageKey = dataSnapshot.getKey();
            if (!mPrevKey.equals(messageKey)) {
                messagesList.add(itemPos++, message);
            } else {
                mPrevKey = mLastKey;
            }
            if (itemPos == 1) {
                String mMessageKey = dataSnapshot.getKey();
                mLastKey = mMessageKey;
            }
            mMessageAdapter.notifyDataSetChanged();
            mSwipeRefreshLayout.setRefreshing(false);
            mLinearLayoutManager.scrollToPositionWithOffset(10, 0);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 10 with ChildEventListener

use of com.google.firebase.database.ChildEventListener in project Lets-Chat by kshitiz1007.

the class ChatActivity method loadMessages.

// ---FIRST 10 MESSAGES WILL LOAD ON START----
private void loadMessages() {
    DatabaseReference messageRef = mRootReference.child("messages").child(mCurrentUserId).child(mChatUser);
    Query messageQuery = messageRef.limitToLast(mCurrentPage * TOTAL_ITEM_TO_LOAD);
    messageQuery.addChildEventListener(new ChildEventListener() {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Messages messages = (Messages) dataSnapshot.getValue(Messages.class);
            itemPos++;
            if (itemPos == 1) {
                String mMessageKey = dataSnapshot.getKey();
                mLastKey = mMessageKey;
                mPrevKey = mMessageKey;
            }
            messagesList.add(messages);
            mMessageAdapter.notifyDataSetChanged();
            mMessagesList.scrollToPosition(messagesList.size() - 1);
            mSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

ChildEventListener (com.google.firebase.database.ChildEventListener)38 DataSnapshot (com.google.firebase.database.DataSnapshot)38 DatabaseError (com.google.firebase.database.DatabaseError)38 DatabaseReference (com.google.firebase.database.DatabaseReference)11 Intent (android.content.Intent)7 View (android.view.View)5 Product (com.example.asus.onlinecanteen.model.Product)5 Map (java.util.Map)5 ListView (android.widget.ListView)4 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)4 BrixxEventModel (com.manan.dev.ec2018app.Models.BrixxEventModel)4 TextView (android.widget.TextView)3 Transaction (com.example.asus.onlinecanteen.model.Transaction)3 LatLng (com.google.android.gms.maps.model.LatLng)3 Query (com.google.firebase.database.Query)3 HashMap (java.util.HashMap)3 AlertDialog (android.support.v7.app.AlertDialog)2 Button (android.widget.Button)2 ImageView (android.widget.ImageView)2 RadioButton (android.widget.RadioButton)2