Java Code Examples for com.google.firebase.database.DatabaseReference#removeValue()

The following examples show how to use com.google.firebase.database.DatabaseReference#removeValue() . 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: DriverMapActivity.java    From UberClone with MIT License 6 votes vote down vote up
private void endRide(){
    mRideStatus.setText("picked customer");
    erasePolylines();

    String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
    DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(userId).child("customerRequest");
    driverRef.removeValue();

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest");
    GeoFire geoFire = new GeoFire(ref);
    geoFire.removeLocation(customerId);
    customerId="";
    rideDistance = 0;

    if(pickupMarker != null){
        pickupMarker.remove();
    }
    if (assignedCustomerPickupLocationRefListener != null){
        assignedCustomerPickupLocationRef.removeEventListener(assignedCustomerPickupLocationRefListener);
    }
    mCustomerInfo.setVisibility(View.GONE);
    mCustomerName.setText("");
    mCustomerPhone.setText("");
    mCustomerDestination.setText("Destination: --");
    mCustomerProfileImage.setImageResource(R.mipmap.ic_default_user);
}
 
Example 2
Source File: ChatManager.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
private void deleteInstanceId() {

        DatabaseReference root;
        if (StringUtils.isValid(Configuration.firebaseUrl)) {
            root = FirebaseDatabase.getInstance().getReferenceFromUrl(Configuration.firebaseUrl);
        } else {
            root = FirebaseDatabase.getInstance().getReference();
        }

        String token = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG_TOKEN, "ChatManager.deleteInstanceId: token ==  " + token);

        // remove the instanceId for the logged user
        DatabaseReference firebaseUsersPath = root
                .child("apps/" + ChatManager.Configuration.appId + "/users/" +
                        loggedUser.getId() + "/instances/" + token);
        firebaseUsersPath.removeValue();

        try {
            FirebaseInstanceId.getInstance().deleteInstanceId();
        } catch (IOException e) {
            Log.e(DEBUG_LOGIN, "cannot delete instanceId. " + e.getMessage());
            return;
        }
    }
 
Example 3
Source File: ConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
public void deleteConversation(final String conversationId, final ConversationsListener conversationsListener) {

        // the node of the conversation with conversationId
        DatabaseReference nodeConversation = conversationsNode.child(conversationId);

        nodeConversation.removeValue(new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {

                if (databaseError == null) {
                    deleteConversationFromMemory(conversationId);
                    conversationsListener.onConversationRemoved(null);
                } else {
                    conversationsListener.onConversationRemoved(new ChatRuntimeException(databaseError.toException()));
                }
            }
        });
    }
 
Example 4
Source File: ArchivedConversationsHandler.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
public void deleteConversation(final String conversationId, final ConversationsListener conversationsListener) {

        // the node of the conversation with conversationId
        DatabaseReference nodeConversation = conversationsNode.child(conversationId);

        nodeConversation.removeValue(new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {

                if (databaseError == null) {
                    deleteConversationFromMemory(conversationId);
                    conversationsListener.onConversationRemoved(null);
                } else {
                    conversationsListener.onConversationRemoved(new ChatRuntimeException(databaseError.toException()));
                }
            }
        });
    }
 
Example 5
Source File: ChatAuthentication.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
private void deleteInstanceId(String userId) {

        DatabaseReference root;
        if (StringUtils.isValid(ChatManager.Configuration.firebaseUrl)) {
            root = FirebaseDatabase.getInstance().getReferenceFromUrl(ChatManager.Configuration.firebaseUrl);
        } else {
            root = FirebaseDatabase.getInstance().getReference();
        }

        String token = FirebaseInstanceId.getInstance().getToken();
        Log.d(DEBUG_LOGIN, "ChatAuthentication.deleteInstanceId: token ==  " + token);

        // remove the instanceId for the logged user
        DatabaseReference firebaseUsersPath = root
                .child("apps/" + ChatManager.Configuration.appId + "/users/" +
                        userId + "/instances/" + token);
        firebaseUsersPath.removeValue();

        try {
            FirebaseInstanceId.getInstance().deleteInstanceId();
        } catch (IOException e) {
            Log.e(DEBUG_LOGIN, "cannot delete instanceId. " + e.getMessage());
            return;
        }
    }
 
Example 6
Source File: DataTestIT.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveCallbackIsHit()
    throws ExecutionException, TimeoutException, InterruptedException, TestFailure {
  final DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  WriteFuture writeFuture = new WriteFuture(ref, 42);
  writeFuture.timedGet();

  ReadFuture readFuture = new ReadFuture(ref, new ReadFuture.CompletionCondition() {
    @Override
    public boolean isComplete(List<EventRecord> events) {
      return events.get(events.size() - 1).getSnapshot().getValue() == null;
    }
  });

  final Semaphore callbackHit = new Semaphore(0);
  ref.removeValue(new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError error, DatabaseReference callbackRef) {
      assertEquals(ref, callbackRef);
      callbackHit.release(1);
    }
  });

  readFuture.timedGet();
  assertTrue(callbackHit.tryAcquire(1, TestUtils.TEST_TIMEOUT_MILLIS, MILLISECONDS));
  // We test the value in the completion condition
}
 
Example 7
Source File: CustomerMapActivity.java    From UberClone with MIT License 5 votes vote down vote up
private void endRide(){
    requestBol = false;
    geoQuery.removeAllListeners();
    driverLocationRef.removeEventListener(driverLocationRefListener);
    driveHasEndedRef.removeEventListener(driveHasEndedRefListener);

    if (driverFoundID != null){
        DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverFoundID).child("customerRequest");
        driverRef.removeValue();
        driverFoundID = null;

    }
    driverFound = false;
    radius = 1;
    String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest");
    GeoFire geoFire = new GeoFire(ref);
    geoFire.removeLocation(userId);

    if(pickupMarker != null){
        pickupMarker.remove();
    }
    if (mDriverMarker != null){
        mDriverMarker.remove();
    }
    mRequest.setText("call Uber");

    mDriverInfo.setVisibility(View.GONE);
    mDriverName.setText("");
    mDriverPhone.setText("");
    mDriverCar.setText("Destination: --");
    mDriverProfileImage.setImageResource(R.mipmap.ic_default_user);
}
 
Example 8
Source File: Appointment.java    From Walk-In-Clinic-Android-App with MIT License 5 votes vote down vote up
public boolean deleteAppointment(Booking booking){
    try {
        DatabaseReference dR = databaseBookings.child(booking.getId());
        dR.removeValue();
        return true;
    }catch(Exception e){
        return false;
    }
}
 
Example 9
Source File: Administrator.java    From Walk-In-Clinic-Android-App with MIT License 5 votes vote down vote up
/**
 * Deletes all bookings from clinic
 * @param id patient id
 * @return bool if succesful
 */
public boolean deletePatientBookings(String id){
    updateBookings();
    for(Booking b: bookings){
        if(b.getPatientId().equals(id)){
            DatabaseReference dR = FirebaseDatabase.getInstance().getReference("bookings").child(b.getId());
            dR.removeValue();
        }
    }

    return true;
}
 
Example 10
Source File: Administrator.java    From Walk-In-Clinic-Android-App with MIT License 5 votes vote down vote up
/**
 * Deletes all bookings from clinic
 * @param id walk in clinic id
 * @return bool if succesful
 */
public boolean deleteClinicBookings(String id){
    updateBookings();

    for(Booking b: bookings){
        if(b.getWalkInId().equals(id)){
            DatabaseReference dR = FirebaseDatabase.getInstance().getReference("bookings").child(b.getId());
            dR.removeValue();
        }
    }

    return true;
}
 
Example 11
Source File: Administrator.java    From Walk-In-Clinic-Android-App with MIT License 5 votes vote down vote up
/**
 * Deletes a user from the database based on their ID
 * @param id of user to delete
 * @return bool if successful
 */
public boolean deleteUser(String id){
    DatabaseReference dR = FirebaseDatabase.getInstance().getReference("users").child(id);
    dR.removeValue();
    return true;
}
 
Example 12
Source File: ProfileInteractor.java    From social-app-android with Apache License 2.0 4 votes vote down vote up
public void removeRegistrationToken(String token, String userId) {
    DatabaseReference databaseReference = ApplicationHelper.getDatabaseHelper().getDatabaseReference();
    DatabaseReference tokenRef = databaseReference.child(DatabaseHelper.PROFILES_DB_KEY).child(userId).child("notificationTokens").child(token);
    Task<Void> task = tokenRef.removeValue();
    task.addOnCompleteListener(task1 -> LogUtil.logDebug(TAG, "removeRegistrationToken, success: " + task1.isSuccessful()));
}
 
Example 13
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 4 votes vote down vote up
public Task<Void> removePost(Post post) {
    DatabaseReference postRef = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY).child(post.getId());
    return postRef.removeValue();
}
 
Example 14
Source File: FirebaseHelpers.java    From cannonball-android with Apache License 2.0 4 votes vote down vote up
public static Task<Void> deletePoem(String key) {
    String userId = getUserId();
    DatabaseReference newPoemRef = FirebaseDatabase.getInstance().getReference(userId).child(key);

    return newPoemRef.removeValue();
}
 
Example 15
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 4 votes vote down vote up
public Task<Void> removePost(Post post) {
    DatabaseReference postRef = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY).child(post.getId());
    return postRef.removeValue();
}
 
Example 16
Source File: ProfileInteractor.java    From social-app-android with Apache License 2.0 4 votes vote down vote up
public void removeRegistrationToken(String token, String userId) {
    DatabaseReference databaseReference = ApplicationHelper.getDatabaseHelper().getDatabaseReference();
    DatabaseReference tokenRef = databaseReference.child(DatabaseHelper.PROFILES_DB_KEY).child(userId).child("notificationTokens").child(token);
    Task<Void> task = tokenRef.removeValue();
    task.addOnCompleteListener(task1 -> LogUtil.logDebug(TAG, "removeRegistrationToken, success: " + task1.isSuccessful()));
}
 
Example 17
Source File: Administrator.java    From Walk-In-Clinic-Android-App with MIT License 4 votes vote down vote up
/**
 * Deletes a clinic from the database based on its ID
 * @param id of clinic to delete
 * @return bool if successful
 */
public boolean deleteWalkIn(String id){
    DatabaseReference dR = FirebaseDatabase.getInstance().getReference("clinics").child(id);
    dR.removeValue();
    return true;
}