com.google.firebase.firestore.FirebaseFirestore Java Examples
The following examples show how to use
com.google.firebase.firestore.FirebaseFirestore.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocSnippets.java From snippets-android with Apache License 2.0 | 6 votes |
public void offlineListen(FirebaseFirestore db) { // [START offline_listen] db.collection("cities").whereEqualTo("state", "CA") .addSnapshotListener(MetadataChanges.INCLUDE, new EventListener<QuerySnapshot>() { @Override public void onEvent(@Nullable QuerySnapshot querySnapshot, @Nullable FirebaseFirestoreException e) { if (e != null) { Log.w(TAG, "Listen error", e); return; } for (DocumentChange change : querySnapshot.getDocumentChanges()) { if (change.getType() == Type.ADDED) { Log.d(TAG, "New city:" + change.getDocument().getData()); } String source = querySnapshot.getMetadata().isFromCache() ? "local cache" : "server"; Log.d(TAG, "Data fetched from " + source); } } }); // [END offline_listen] }
Example #2
Source File: ConversationManagerTest.java From NaviBee with GNU General Public License v3.0 | 6 votes |
@Before public void setUp() throws Exception { conversationManager = new ConversationManager(); // create static mocks mFirebaseFunction = mock(FirebaseFunctions.class); PowerMockito.mockStatic(FirebaseFunctions.class); mFirebaseFirestore = mock(FirebaseFirestore.class); PowerMockito.mockStatic(FirebaseFirestore.class); // configure mock expected interaction when(FirebaseFunctions.getInstance()).thenReturn(mFirebaseFunction); when(FirebaseFirestore.getInstance()).thenReturn(mFirebaseFirestore); }
Example #3
Source File: FriendRequests.java From Hify with MIT License | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mFirestore = FirebaseFirestore.getInstance(); mAuth = FirebaseAuth.getInstance(); mRequestView = view.findViewById(R.id.recyclerView); refreshLayout=view.findViewById(R.id.refreshLayout); requestList = new ArrayList<>(); requestAdapter = new FriendRequestAdapter(requestList, view.getContext()); mRequestView.setItemAnimator(new DefaultItemAnimator()); mRequestView.setLayoutManager(new LinearLayoutManager(view.getContext(), VERTICAL, false)); mRequestView.addItemDecoration(new DividerItemDecoration(view.getContext(),DividerItemDecoration.VERTICAL)); mRequestView.setHasFixedSize(true); mRequestView.setAdapter(requestAdapter); refreshLayout.setOnRefreshListener(this::getUsers); getUsers(); }
Example #4
Source File: EventsActivity.java From NaviBee with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_events); uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); db = FirebaseFirestore.getInstance(); // loading events.add(new EventRVIndefiniteProgressBar()); eventIdMap = new HashMap<>(); // set up recycler view recyclerView = (RecyclerView)findViewById(R.id.events_recycler_view); viewManager = new LinearLayoutManager(this); viewAdapter = new EventsRVAdaptor(events); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(viewManager); recyclerView.setAdapter(viewAdapter); loadEvents(); }
Example #5
Source File: MapPresenter.java From ridesharing-android with MIT License | 6 votes |
public MapPresenter(Context context, V view, S state) { mContext = context.getApplicationContext() == null ? context : context.getApplicationContext(); mView = view; mState = state; mapPadding = mContext.getResources().getDimensionPixelSize(R.dimen.map_padding); Places.initialize(mContext, MainActivity.GOOGLE_API_KEY); mapConfig = MapUtils.getBuilder(context).build(); hyperTrackViews = HyperTrackViews.getInstance(mContext, HyperTrackUtils.getPubKey(context)); locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); db = FirebaseFirestore.getInstance(); List<Place.Field> fields = Arrays.asList( Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS, Place.Field.ADDRESS_COMPONENTS ); autocompleteIntentBuilder = new Autocomplete.IntentBuilder( AutocompleteActivityMode.OVERLAY, fields); }
Example #6
Source File: FirestoreTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Test public void setShouldFailWithPermissionDenied() throws Exception { FirebaseAuth auth = FirebaseAuth.getInstance(); FirebaseFirestore firestore = FirebaseFirestore.getInstance(); auth.signOut(); Thread.sleep(1000); // TODO(allisonbm92): Introduce a better means to reduce flakes. DocumentReference doc = firestore.collection("restaurants").document(TestId.create()); try { HashMap<String, Object> data = new HashMap<>(); data.put("popularity", 5000L); Task<?> setTask = doc.set(new HashMap<>(data)); Throwable failure = Tasks2.waitForFailure(setTask); FirebaseFirestoreException ex = (FirebaseFirestoreException) failure; assertThat(ex.getCode()).isEqualTo(FirebaseFirestoreException.Code.PERMISSION_DENIED); } finally { Tasks2.waitBestEffort(doc.delete()); } }
Example #7
Source File: ThreadFragmentPresenter.java From demo-firebase-android with The Unlicense | 6 votes |
@Inject public ThreadFragmentPresenter(Context context, DataReceivedInteractor<Message> messageReceivedInteractor, OnMessageSentInteractor onMessageSentInteractor, GetMessagesInteractor getMessagesInteractor, VirgilRx virgilRx, SearchCardsInteractor searchCardsInteractor, UserManager userManager, VirgilHelper virgilHelper, FirebaseFirestore firestore, RoomDb roomDb) { this.context = context; this.messageReceivedInteractor = messageReceivedInteractor; this.onMessageSentInteractor = onMessageSentInteractor; this.virgilRx = virgilRx; this.searchCardsInteractor = searchCardsInteractor; this.userManager = userManager; this.virgilHelper = virgilHelper; this.firestore = firestore; this.getMessagesInteractor = getMessagesInteractor; this.roomDb = roomDb; compositeDisposable = new CompositeDisposable(); }
Example #8
Source File: FirestorePagingActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_firestore_paging); ButterKnife.bind(this); mFirestore = FirebaseFirestore.getInstance(); mItemsCollection = mFirestore.collection("items"); setUpAdapter(); }
Example #9
Source File: GndApplicationModule.java From ground-android with Apache License 2.0 | 5 votes |
@Provides @Singleton static FirebaseFirestore firebaseFirestore(FirebaseFirestoreSettings settings) { FirebaseFirestore firestore = FirebaseFirestore.getInstance(); firestore.setFirestoreSettings(settings); FirebaseFirestore.setLoggingEnabled(Config.FIRESTORE_LOGGING_ENABLED); return firestore; }
Example #10
Source File: MainActivity.java From startup-os with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FirebaseFirestore db = FirebaseFirestore.getInstance(); }
Example #11
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_main); findViewById(R.id.button_write).setOnClickListener(this); findViewById(R.id.button_smoketest).setOnClickListener(this); findViewById(R.id.button_delete_all).setOnClickListener(this); mFirestore = FirebaseFirestore.getInstance(); new SolutionRateLimiting().startUpdates(); }
Example #12
Source File: IntegrationTestUtil.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
public static void enableNetwork(FirebaseFirestore firestore) { if (!firestoreStatus.get(firestore)) { waitFor(firestore.enableNetwork()); // Wait for the client to connect. waitFor(firestore.collection("unknown").document().delete()); firestoreStatus.put(firestore, true); } }
Example #13
Source File: IntegrationTestUtil.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
public static void tearDown() { try { for (FirebaseFirestore firestore : firestoreStatus.keySet()) { Task<Void> result = firestore.terminate(); waitFor(result); } } finally { firestoreStatus.clear(); } }
Example #14
Source File: ThreadsListFragmentPresenter.java From demo-firebase-android with The Unlicense | 5 votes |
@Inject public ThreadsListFragmentPresenter(FirebaseFirestore firebaseFirestore, FirebaseAuth firebaseAuth, VirgilHelper virgilHelper, DataReceivedInteractor<List<DefaultChatThread>> onDataReceivedInteractor, CompleteInteractor<ThreadListFragmentPresenterReturnTypes> completeInteractor) { this.firebaseFirestore = firebaseFirestore; this.firebaseAuth = firebaseAuth; this.virgilHelper = virgilHelper; this.onDataReceivedInteractor = onDataReceivedInteractor; this.completeInteractor = completeInteractor; compositeDisposable = new CompositeDisposable(); }
Example #15
Source File: FirestoreTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void setShouldTriggerListenerWithNewlySetData() throws Exception { FirebaseAuth auth = FirebaseAuth.getInstance(); FirebaseFirestore firestore = FirebaseFirestore.getInstance(); auth.signOut(); Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password"); Tasks2.waitForSuccess(signInTask); DocumentReference doc = firestore.collection("restaurants").document(TestId.create()); SnapshotListener listener = new SnapshotListener(); ListenerRegistration registration = doc.addSnapshotListener(listener); try { HashMap<String, Object> data = new HashMap<>(); data.put("location", "Google NYC"); Task<?> setTask = doc.set(new HashMap<>(data)); Task<DocumentSnapshot> snapshotTask = listener.toTask(); Tasks2.waitForSuccess(setTask); Tasks2.waitForSuccess(snapshotTask); DocumentSnapshot result = snapshotTask.getResult(); assertThat(result.getData()).isEqualTo(data); } finally { registration.remove(); Tasks2.waitBestEffort(doc.delete()); } }
Example #16
Source File: EmulatorSuite.java From snippets-android with Apache License 2.0 | 5 votes |
public void emulatorSettings() { // [START fs_emulator_connect] // 10.0.2.2 is the special IP address to connect to the 'localhost' of // the host computer from an Android emulator. FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder() .setHost("10.0.2.2:8080") .setSslEnabled(false) .setPersistenceEnabled(false) .build(); FirebaseFirestore firestore = FirebaseFirestore.getInstance(); firestore.setFirestoreSettings(settings); // [END fs_emulator_connect] }
Example #17
Source File: MessageImageAdapter.java From Hify with MIT License | 5 votes |
@NonNull @Override public MessageImageAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { mFirestore=FirebaseFirestore.getInstance(); View view=LayoutInflater.from(context).inflate(R.layout.message_text_item,parent,false); return new ViewHolder(view); }
Example #18
Source File: SendMessage.java From Hify with MIT License | 5 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); firestore = FirebaseFirestore.getInstance(); mAuth = FirebaseAuth.getInstance(); mRecyclerView = view.findViewById(R.id.messageList); refreshLayout=view.findViewById(R.id.refreshLayout); usersList = new ArrayList<>(); usersAdapter = new UsersAdapter(usersList, view.getContext()); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); mRecyclerView.setHasFixedSize(true); mRecyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), DividerItemDecoration.VERTICAL)); mRecyclerView.setAdapter(usersAdapter); refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { usersList.clear(); usersAdapter.notifyDataSetChanged(); startListening(); } }); usersList.clear(); usersAdapter.notifyDataSetChanged(); startListening(); }
Example #19
Source File: UtilModule.java From demo-firebase-android with The Unlicense | 5 votes |
@Provides FirebaseFirestore provideFirebaseFirestore() { FirebaseFirestore firestore = FirebaseFirestore.getInstance(); FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder() .setTimestampsInSnapshotsEnabled(true) .build(); firestore.setFirestoreSettings(settings); return firestore; }
Example #20
Source File: PostsAdapter.java From Hify with MIT License | 5 votes |
@NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { FirebaseAuth mAuth = FirebaseAuth.getInstance(); mFirestore = FirebaseFirestore.getInstance(); mCurrentUser = mAuth.getCurrentUser(); View view= LayoutInflater.from(context).inflate(R.layout.item_feed_post,parent,false); return new ViewHolder(view); }
Example #21
Source File: DeviceLocationDataStore.java From Track-My-Location with GNU General Public License v3.0 | 5 votes |
public DeviceLocationDataStore() { mUser = FirebaseAuth.getInstance().getCurrentUser(); if (mUser == null) return; mUserDocRef = FirebaseFirestore.getInstance() .collection("users") .document(mUser.getUid()); }
Example #22
Source File: DeviceLocationDataStore.java From Track-My-Location with GNU General Public License v3.0 | 5 votes |
public Observable<SharedLocation> getSharedLocationUpdate(String devId) { DocumentReference docRef = FirebaseFirestore.getInstance() .collection("shared_locations") .document(devId); return RxFirestore.getDocument(docRef) .map(documentSnapshot -> documentSnapshot.toObject(SharedLocation.class)); }
Example #23
Source File: DeviceLocationDataStore.java From Track-My-Location with GNU General Public License v3.0 | 5 votes |
private void saveToFirebase(SharedLocation sharedLocation) { Log.v(TAG, "Update shared location to firebase " + sharedLocation.toString()); mShareLocDocRef = FirebaseFirestore.getInstance() .collection("shared_locations") .document(sharedLocation.getDevId()); mShareLocDocRef .set(sharedLocation) .addOnSuccessListener(aVoid -> Log.v(TAG, "Firestore: Location Update Success")) .addOnFailureListener(e -> Log.v(TAG, "Firestore: Location Update Failure")); }
Example #24
Source File: NotificationBroadcastReceiver.java From NaviBee with GNU General Public License v3.0 | 5 votes |
private void sendMessageByConvId(String convId, String type, CharSequence content) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) return; String uid = user.getUid(); Conversation.Message message = new Conversation.Message(content.toString(), uid, new Date(), type); FirebaseFirestore.getInstance() .collection("conversations") .document(convId) .collection("messages") .add(message); }
Example #25
Source File: Conversation.java From NaviBee with GNU General Public License v3.0 | 5 votes |
public Conversation(String id, Date readTimestamp, Date createTimestamp) { conversationId = id; this.readTimestamp = readTimestamp; this.createTimestamp = createTimestamp; this.uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); db = FirebaseFirestore.getInstance(); listen(); }
Example #26
Source File: RealTimeLocationDisplayActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
private void update(boolean timer) { if (googleMap == null) return; if (location != null) { long oneAgo = System.currentTimeMillis() - EXPIRE_TIME; if (lastUpdate.getTime() < oneAgo) { if (marker != null) { marker.remove(); } } else { if (marker == null) { marker = googleMap.addMarker(new MarkerOptions().position(location)); googleMap.moveCamera(CameraUpdateFactory.newLatLng(location)); googleMap.moveCamera(CameraUpdateFactory.zoomTo(DEFAULT_ZOOM_LEVEL)); marker.setIcon(BitmapDescriptorFactory.fromBitmap(new IconGenerator(this).makeIcon(userName))); } else { marker.setPosition(location); } } } if (timer && myLocation!=null) { // update my location Map<String, Object> data = new HashMap<>(); data.put("latitude", myLocation.latitude); data.put("longitude", myLocation.longitude); data.put("time", Timestamp.now()); FirebaseFirestore.getInstance() .collection("conversations") .document(conv.conversationId) .collection("realtimeLocations") .document(FirebaseAuth.getInstance().getUid()).set(data); } }
Example #27
Source File: RealTimeLocationDisplayActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
@Override protected void onDestroy() { mapView.onDestroy(); updateTimer.cancel(); updateTimer.purge(); listener.remove(); FirebaseFirestore.getInstance() .collection("conversations") .document(conv.conversationId) .collection("realtimeLocations") .document(FirebaseAuth.getInstance().getUid()).delete(); super.onDestroy(); }
Example #28
Source File: ConversationManager.java From NaviBee with GNU General Public License v3.0 | 5 votes |
public static void init() { instance = new ConversationManager(); instance.uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); instance.db = FirebaseFirestore.getInstance(); instance.listenPrivateConv(); instance.listenGroupConv(); }
Example #29
Source File: UserInfoManagerTest.java From NaviBee with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() { // create static mock mFirebaseAuth = mock(FirebaseAuth.class); PowerMockito.mockStatic(FirebaseAuth.class); mFirebaseFirestore = mock(FirebaseFirestore.class); PowerMockito.mockStatic(FirebaseFirestore.class); // configure mock expected interaction when(FirebaseAuth.getInstance()).thenReturn(mFirebaseAuth); when(FirebaseFirestore.getInstance()).thenReturn(mFirebaseFirestore); }
Example #30
Source File: CategoryRepository.java From triviums with MIT License | 5 votes |
@Inject public CategoryRepository(ApiService apiService, FirebaseFirestore firestore, UserProfile userProfile) { this.apiService = apiService; this.firestore = firestore; this.userProfile = userProfile; }