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);
}
}
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();
}
}
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);
}
}
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) {
}
});
}
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) {
}
});
}
Aggregations