@Override public Comment addCommentAsync(String commentText, String postId) { startCheckingIfPostExists(postId); Firebase newCommentRef = commentsFirebaseRef.push(); if (!finishCheckingIfPostExists()) { newCommentRef.removeValue(); throw new IllegalArgumentException("Post being commented on does " + "not exist."); } String newCommentId = newCommentRef.getKey(); long timestamp = new Date().getTime(); int zeroDownvotes = 0; Comment newComment = new Comment( newCommentId, postId, getLoggedInUserId(), commentText, timestamp, zeroDownvotes); newCommentRef.setValue(newComment); return newComment; }
@Override protected void onPause() { super.onPause(); // Save read flag intentAnswer.saveInBackground(); if (newMessageListener != null) { messagesRef.removeEventListener(newMessageListener); } if (chatStatusListener != null) { friendTypingRef.removeEventListener(chatStatusListener); } if (onlineStatusListener != null) { friendOnlineRef.removeEventListener(onlineStatusListener); } if (userTypingRef != null) { userTypingRef.setValue(false); } if (receiver != null) { unregisterReceiver(receiver); } ActionLog.log("paused intent answer activity"); AppEventsLogger.deactivateApp(this); }
@Override public void onAuthenticated(AuthData authData) { // User newUser = new User(firstName, lastName, email, authData.getUid()); Firebase child = firebaseRef.child("Consumers").child("TEST"); child.setValue(new User(firstName, lastName, email, authData.getUid())); }
@Override public String create(Path entity) { Firebase newPushRef = ref.push(); String id = newPushRef.getName(); Firebase childRef = ref.child(id); childRef.setValue(entity.getPath()); return id; }
public Firebase saveNewGame(Location location) { final Firebase ref = LaserTagApplication.firebaseReference.child("games").push(); ref.setValue(this); // stores GeoFire Location with key LaserTagApplication.geoFire.setLocation( ref.getKey(), new GeoLocation(location.getLatitude(), location.getLongitude())); return ref; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_33955548); Firebase.setAndroidContext(this); Firebase ref = new Firebase("https://docs-examples.firebaseio.com/android/saving-data/fireblog"); Firebase alanRef = ref.child("users").child("alanisawesome"); User alan = new User("Alan Turing", 1912); alanRef.setValue(alan); }
private boolean saveUrl() { if (UserHelper.userStillLoggedIn(userCreds.getExpireDate())) { try { Firebase ref = new Firebase( "https://yeah-url-extension.firebaseio.com/" + userCreds.getUserId() + "/urlcollector"); Firebase urlRef = ref.push(); List<UrlItem> urlItemList = new ArrayList<>(1); UrlItem urlItem = new UrlItem(); urlItem.setId(1); urlItem.setTimestamp(String.valueOf(Math.round(new Date().getTime() / 1000.0))); urlItem.setTime( new SimpleDateFormat("HH:mm:ss", Locale.GERMANY).format(System.currentTimeMillis())); urlItem.setDate( new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(System.currentTimeMillis())); urlItem.setKeywords(etKeywordsUrl.getText().toString()); urlItem.setValue(tvUrl.getText().toString()); urlItem.setObjId(urlRef.getKey()); urlItemList.add(urlItem); urlRef.setValue( urlItemList, new Firebase.CompletionListener() { @Override public void onComplete(FirebaseError firebaseError, Firebase firebase) { if (firebaseError != null) { Utilities.buildToast( AddUrlActivity.this, "Url saving failed: " + firebaseError.getMessage(), Toast.LENGTH_LONG); } else { Utilities.buildToast( AddUrlActivity.this, "Url saved successfully!", Toast.LENGTH_LONG); } } }); } catch (Exception e) { Utilities.buildToast(this, "Add Url failed! Error: " + e.getMessage(), Toast.LENGTH_LONG); return false; } } else { Utilities.buildToast(this, "User is not logged in!", Toast.LENGTH_LONG); startActivity(new Intent(AddUrlActivity.this, MainActivity.class)); } return true; }
@Override public Comment downvoteComment(String commentId) { Firebase commentFirebaseRef = newFirebaseRefForComment(commentId); FirebaseSyncRequester<Comment> commentRequester = new FirebaseSyncRequester<>(commentFirebaseRef, Comment.class); Comment downvotedComment = null; if (commentRequester.exists()) { downvotedComment = newDownvotedComment(commentRequester.get()); commentFirebaseRef.setValue(newDownvotedComment(downvotedComment)); } else { throw new IllegalArgumentException("Comment with id " + commentId + " does not exist"); } return downvotedComment; }
@Override public void main() throws InterruptedException { /* Initialize our hardware variables. Note that the strings used here as parameters * to 'get' must correspond to the names you assigned during the robot configuration * step you did in the FTC Robot Controller app on the phone. */ // this.color = this.hardwareMap.colorSensor.get("colorSensor"); Firebase firebaseRef = new Firebase("https://9523-2015.firebaseio.com/"); // Wait for the game to start waitForStart(); // Go go gadget robot! firebaseRef.setValue("hello world"); Thread.sleep(5000); }
private void saveChatRoom(ChatRoom chatRoom) { List<Chat> chatList = new ArrayList<>(15); for (int i = 0; i < 15; i++) { Chat chat = new Chat(); chat.setTimeStamp(i); chat.setUserId(App.user.getId()); chat.setText("Chat #" + i); chatList.add(chat); } chatRoom.setChatList(chatList); Firebase chatRef = rootRef.child(chatRoom.getId()); chatRef.setValue(chatRoom); Log.d(TAG, "Chat saved"); }
public void save() { Data data = new Data(); data.setIndex1_elapsedTime(elapsedTime()); data.setIndex4_noRightPerStage(noRWPerStage(true)); data.setIndex2_noWrongPerStage(noRWPerStage(false)); data.setIndex5_noRight(noRW(true)); data.setIndex3_noWrong(noRW(false)); data.setIndex9_noRightPerPlayerPerStage(noRWPerPlayerPerStage(true)); data.setIndex11_noWrongPerPlayerPerStage(noRWPerPlayerPerStage(false)); data.setIndex10_noRightPerPlayer(noRWPerPlayer(true)); data.setIndex12_noWrongPerPlayer(noRWPerPlayer(false)); data.setIndex6_playerContributionPerStage(playerContributionPerStage()); data.setIndex7_balancePerStage(balancePerStage()); data.setIndex8_playerContributionStabilityPerStage(playerContributionStabilityPerStage()); data.setHistory(history); data.setRatios(); fbRef.setValue(data); }
@Override public Comment addCommentSync(String commentText, String postId) { startCheckingIfPostExists(postId); Firebase newCommentRef = commentsFirebaseRef.push(); if (!finishCheckingIfPostExists()) { newCommentRef.removeValue(); throw new IllegalArgumentException("Post being commented on does " + "not exist."); } String newCommentId = newCommentRef.getKey(); long timestamp = new Date().getTime(); int zeroDownvotes = 0; Comment newComment = new Comment( newCommentId, postId, getLoggedInUserId(), commentText, timestamp, zeroDownvotes); final CountDownLatch latch = new CountDownLatch(1); newCommentRef.setValue( newComment, new Firebase.CompletionListener() { @Override public void onComplete(FirebaseError firebaseError, Firebase firebase) { latch.countDown(); } }); try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } return newComment; }
// Agrega el alumno a la base de datos. private void agregarAlumno(String key, Alumno alumno) { Firebase ref = (new Firebase(App.getUidAlumnosUrl())).child(key); ref.setValue(alumno); }
@Override public void update(Path entity) { Firebase childRef = ref.child(entity.transientGetId()); childRef.setValue(entity); }