Search in sources :

Example 1 with Query

use of com.google.firebase.database.Query in project FirebaseUI-Android by firebase.

the class FirebaseIndexArray method onChildAdded.

@Override
public void onChildAdded(DataSnapshot keySnapshot, String previousChildKey) {
    super.setOnChangedListener(null);
    super.onChildAdded(keySnapshot, previousChildKey);
    super.setOnChangedListener(mListener);
    Query ref = mQuery.getRef().child(keySnapshot.getKey());
    mRefs.put(ref, ref.addValueEventListener(new DataRefListener()));
}
Also used : Query(com.google.firebase.database.Query)

Example 2 with Query

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

the class SalesReportAdapter method updateStatus.

public void updateStatus(Long date) {
    // Update status
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("salesreportrequest");
    Query query = ref.orderByChild("requestdate").equalTo(date);
    query.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot snapshot) {
            for (DataSnapshot child : snapshot.getChildren()) {
                child.getRef().child("requeststatus").setValue(1);
            }
        }

        @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) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 3 with Query

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

the class DeleteProductFragment method deleteProduct.

public void deleteProduct() {
    Query data;
    for (int i = 0; i < deleteAdapter.getItemCount(); i++) {
        data = databaseProducts.orderByChild("name").equalTo(productArrayList.get(i).getName());
        final Product product2 = productArrayList.get(i);
        data.addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot productSnapshot : dataSnapshot.getChildren()) {
                    if (merchant.getUid().equals(product2.getTokoId()) && product2.isChecked())
                        productSnapshot.getRef().removeValue();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Query(com.google.firebase.database.Query) Product(com.example.asus.onlinecanteen.model.Product) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 4 with Query

use of com.google.firebase.database.Query in project Grupp by tmoronta1208.

the class UserSearchActivity method searchUser.

private void searchUser(String query) {
    Query userSearchQuery;
    if (query.contains("@")) {
        userSearchQuery = searchUserRef.orderByChild("email").startAt(query).endAt(query + "\uf8ff");
    } else {
        userSearchQuery = searchUserRef.orderByChild("first_name").startAt(query).endAt(query + "\uf8ff");
    }
    FirebaseRecyclerAdapter<PublicUser, UserSearchViewHolder> contactsListAdapter = new FirebaseRecyclerAdapter<PublicUser, UserSearchViewHolder>(PublicUser.class, R.layout.add_contact_itemview, UserSearchViewHolder.class, userSearchQuery) {

        @Override
        protected void populateViewHolder(final UserSearchViewHolder viewHolder, final PublicUser model, int position) {
            final String contactID = getRef(position).getKey();
            final String email = model.getEmail();
            final String first = model.getFirst_name();
            final String last = model.getLast_name();
            final String icon = model.getUser_icon().getIcon_url();
            final String zipCode = model.getZip_code();
            // final int radius = model.getRadius();
            viewHolder.setEmail(email);
            viewHolder.setFullName(first, last);
            viewHolder.setIcon(icon);
            viewHolder.addContactButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String radiusString = "20";
                    addToContactList(contactID, viewHolder.addContactButton, first, last, email, icon, radiusString, zipCode);
                }
            });
        }
    };
    searchContactsRecyclerView.setAdapter(contactsListAdapter);
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) Query(com.google.firebase.database.Query) FirebaseRecyclerAdapter(com.firebase.ui.database.FirebaseRecyclerAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 5 with Query

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

Aggregations

Query (com.google.firebase.database.Query)21 DatabaseReference (com.google.firebase.database.DatabaseReference)11 DataSnapshot (com.google.firebase.database.DataSnapshot)10 DatabaseError (com.google.firebase.database.DatabaseError)10 ValueEventListener (com.google.firebase.database.ValueEventListener)8 View (android.view.View)7 RecyclerView (android.support.v7.widget.RecyclerView)6 Intent (android.content.Intent)4 HashMap (java.util.HashMap)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 TextView (android.widget.TextView)3 Product (com.example.asus.onlinecanteen.model.Product)3 ChildEventListener (com.google.firebase.database.ChildEventListener)3 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)3 FirebaseRecyclerAdapter (com.firebase.ui.database.FirebaseRecyclerAdapter)2 ArrayList (java.util.ArrayList)2 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1