Update PostActivity

In Postactivity we implement the method-stub doPost():

public void doPost() {

        // TODO: Add checkings before posting
        Map<String, Object> postMap = new HashMap<>();
        postMap.put("uid", mCurrentUser.getUid());
        postMap.put("author", mCurrentUser.getEmail());
        postMap.put("title", mPostTitle.getText().toString());
        postMap.put("body", mPostBody.getText().toString());
        postMap.put("timestamp", ServerValue.TIMESTAMP);

        mDatabase = FirebaseDatabase.getInstance().getReference("Posts/");
        mDatabase.push().setValue(postMap);

}

Exercise

Add some checks, before writing to the database, e.g.: title or body muss be non empty.

results matching ""

    No results matching ""