use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method onUpvoteClick.
@Override
public void onUpvoteClick(int p) {
// Log.d("vote" , "up : ");
// get correct chat msg with ith key from chatmessage helper
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference upvote_count = message_root.child("upvotes");
upvote_count.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
Log.d("Data", String.valueOf(currentData));
if (currentData.getValue() == null) {
currentData.setValue(1);
} else {
currentData.setValue((Long) currentData.getValue() + 1);
}
// we can also abort by calling Transaction.abort()
return Transaction.success(currentData);
}
// TODO:Error handle here
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method updateChatConversation.
private void updateChatConversation(DataSnapshot dataSnapshot) {
Iterator i = dataSnapshot.getChildren().iterator();
while (i.hasNext()) {
chat_id = dataSnapshot.getKey();
Log.d("STATE", "result : " + chat_id);
chat_msg = (String) ((DataSnapshot) i.next()).getValue();
chat_side = (String) ((DataSnapshot) i.next()).getValue();
chat_timestamp = (String) ((DataSnapshot) i.next()).getValue();
chat_username = (String) ((DataSnapshot) i.next()).getValue();
chat_downvote = (Long) ((DataSnapshot) i.next()).getValue();
chat_upvote = (Long) ((DataSnapshot) i.next()).getValue();
// gets previous msg of user's vote status
ChatMessageHelper msgId = (ChatMessageHelper) chatAdapter.getItemFromID(chat_id);
String chat_userVote = msgId.getUserVote();
Log.d("USERVOTE", "result : " + chat_userVote);
ChatMessageHelper msg = new ChatMessageHelper(chat_id, chat_side, chat_msg, chat_username, chat_upvote, chat_downvote, chat_timestamp, chat_userVote);
chatAdapter.update(msg, chat_id, true);
// chatAdapter.notifyDataSetChanged();
}
}
use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method appendChatConversation.
private void appendChatConversation(DataSnapshot dataSnapshot) {
Iterator i = dataSnapshot.getChildren().iterator();
Log.d("STATE", "pageData2 : " + dataSnapshot);
while (i.hasNext()) {
chat_id = dataSnapshot.getKey();
Log.d("STATE", "result : " + chat_id);
chat_msg = (String) ((DataSnapshot) i.next()).getValue();
chat_side = (String) ((DataSnapshot) i.next()).getValue();
chat_timestamp = (String) ((DataSnapshot) i.next()).getValue();
chat_username = (String) ((DataSnapshot) i.next()).getValue();
chat_downvote = (Long) ((DataSnapshot) i.next()).getValue();
chat_upvote = (Long) ((DataSnapshot) i.next()).getValue();
String chat_userVote;
chat_userVote = userVotes.get(chat_id);
Log.d("CHATVOTE", "result : " + chat_userVote);
ChatMessageHelper msg = new ChatMessageHelper(chat_id, chat_side, chat_msg, chat_username, chat_upvote, chat_downvote, chat_timestamp, chat_userVote);
chatAdapter.add(msg);
}
chatAdapter.notifyDataSetChanged();
recyclerView.scrollToPosition(chatAdapter.getItemCount() - 1);
}
use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method removeUpvote.
@Override
public void removeUpvote(int p) {
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference upvote_count = message_root.child("upvotes");
upvote_count.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
Log.d("Data", String.valueOf(currentData));
if (currentData.getValue() == null) {
currentData.setValue(0);
} else {
currentData.setValue((Long) currentData.getValue() - 1);
}
// we can also abort by calling Transaction.abort()
return Transaction.success(currentData);
}
// TODO:Error handle here
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
Aggregations