Search in sources :

Example 46 with DatabaseReference

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

the class TempUserActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_PHOTO_PICKER) {
        try {
            final Uri uri = data.getData();
            UserIcon test = new UserIcon("hello");
            iconRef.setValue(test, new DatabaseReference.CompletionListener() {

                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    if (databaseError == null) {
                        StorageReference storage = FirebaseStorage.getInstance().getReference(USER_ICON).child(currentUserId).child(uri.getLastPathSegment());
                        storage.putFile(uri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                                if (task.isSuccessful()) {
                                    UserIcon test = new UserIcon(task.getResult().getMetadata().getDownloadUrl().toString());
                                    iconRef.setValue(test);
                                    CurrentUserPost.getInstance().postProfilePictoPublicUser(test);
                                }
                            }
                        });
                    }
                }
            });
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) UploadTask(com.google.firebase.storage.UploadTask) DatabaseError(com.google.firebase.database.DatabaseError) StorageReference(com.google.firebase.storage.StorageReference) DatabaseReference(com.google.firebase.database.DatabaseReference) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) NonNull(android.support.annotation.NonNull) Uri(android.net.Uri)

Example 47 with DatabaseReference

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

the class ContactListFragment method onCreateView.

/* public static ContactListFragment newInstance(String title) {
        ContactListFragment fragment = new ContactListFragment();
        Bundle args = new Bundle();
        args.putString("title", title);
        fragment.setArguments(args);
        return fragment;
    }*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_contactlist, container, false);
    searchView = view.findViewById(R.id.search_bar_cl);
    searchView.setHint("Name, #Grupptag, Email");
    searchView.setHintTextColor(getActivity().getResources().getColor(R.color.hintcolor));
    String currentUserId = CurrentUser.getInstance().getUserID();
    DatabaseReference contactsRef = FirebaseDatabase.getInstance().getReference().child(USER_CONTACTS).child(currentUserId);
    recyclerView = view.findViewById(R.id.contact_list_rec);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayout = new LinearLayoutManager(view.getContext());
    contactListAdapter = new ContactListAdapter(PublicUserDetails.class, R.layout.contact_item_view, ContactListViewHolder.class, contactsRef);
    /**
     *ajoxe:
     * after modifying the adapter, set the list as friendsUserList
     * contactListAdapter = new ContactListAdapter(friendsUserList, getContext());
     */
    recyclerView.setAdapter(contactListAdapter);
    recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getContext()));
    recyclerView.setLayoutManager(linearLayout);
    return view;
}
Also used : SimpleDividerItemDecoration(com.example.c4q.capstone.utils.SimpleDividerItemDecoration) ContactListAdapter(com.example.c4q.capstone.userinterface.user.userprofilefragments.userprofilecontroller.ContactListAdapter) DatabaseReference(com.google.firebase.database.DatabaseReference) PublicUserDetails(com.example.c4q.capstone.database.publicuserdata.PublicUserDetails) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ContactListViewHolder(com.example.c4q.capstone.userinterface.user.userprofilefragments.userprofileviews.ContactListViewHolder)

Example 48 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project geofire-java by firebase.

the class GeoFireIT method locationWorksWithLongs.

@Test
public void locationWorksWithLongs() throws InterruptedException, ExecutionException, TimeoutException {
    GeoFire geoFire = geoFireTestingRule.newTestGeoFire();
    DatabaseReference databaseReference = geoFire.getDatabaseRefForKey("loc");
    final Semaphore semaphore = new Semaphore(0);
    databaseReference.setValue(new HashMap<String, Object>() {

        {
            put("l", Arrays.asList(1L, 2L));
            // this is wrong but we don't care in this test
            put("g", "7zzzzzzzzz");
        }
    }, "7zzzzzzzzz", new DatabaseReference.CompletionListener() {

        @Override
        public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
            semaphore.release();
        }
    });
    semaphore.tryAcquire(geoFireTestingRule.timeout, TimeUnit.SECONDS);
    TestCallback testCallback = new TestCallback();
    geoFire.getLocation("loc", testCallback);
    Assert.assertEquals(TestCallback.location("loc", 1, 2), testCallback.getCallbackValue());
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) TestCallback(com.firebase.geofire.testing.TestCallback) Test(org.junit.Test)

Example 49 with DatabaseReference

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

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

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