forked from kev5/GoMeet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteToFireBase.java
More file actions
42 lines (34 loc) · 1.37 KB
/
writeToFireBase.java
File metadata and controls
42 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.example.meetgo;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
/**
* Created by nanto on 10/28/2017.
*/
public class writeToFireBase {
private FirebaseUser user;
private FirebaseDatabase database;
private DatabaseReference writepostRef;
private DatabaseReference userRef;
public writeToFireBase(){
this.user = FirebaseAuth.getInstance().getCurrentUser();
this.database = FirebaseDatabase.getInstance();
this.writepostRef = this.database.getReference("posts");
this.userRef = this.database.getReference("users");
}
public void writePosts(String postID, Post post){
this.writepostRef.child(postID).setValue(post);
}
public void likePost(String postID){
DatabaseReference commentPostRef = this.writepostRef.child(postID);
commentPostRef.child("likes").push().setValue(this.user.getUid());
}
public void dislikePost(String postID){
DatabaseReference commentPostRef = this.writepostRef.child(postID);
commentPostRef.child("dislikes").push().setValue(this.user.getUid());
}
public void loginUser(){
this.userRef.child(user.getUid()).setValue("on");
}
}