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