use of ingage.ingage.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.ingage.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method onDownvoteClick.
@Override
public void onDownvoteClick(int p) {
// Log.d("vote" , "down : ");
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference downvote_count = message_root.child("downvotes");
downvote_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.ingage.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatArrayAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ChatArrayAdapter.ChatViewHolder holder, final int position) {
final ChatMessageHelper chatMessageHelper = (ChatMessageHelper) this.getItem(position);
holder.bind(position);
String userVote = "";
userVote = chatMessageHelper.getUserVote();
// side = chatMessageHelper.getSide();
if (userVote != null) {
if (userVote.equals("up")) {
toggleVote(holder.bUpvote, selectedColorAgree, false);
toggleVote(holder.bDownvote, unselectedColor, true);
} else if (userVote.equals("down")) {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, selectedColorDisagree, false);
}
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
if (holder.avatar.getDrawable() == null) {
Log.d("Upvote state: ", " no avatar");
holder.downloadAvatar();
}
holder.bUpvote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onUpvoteClick(position);
// MAKE boolean LOL
String prev_voted = "false", vote = "up";
// check if previously voted
if (chatMessageHelper.getUserVote() != null) {
if (chatMessageHelper.getUserVote().equals("down")) {
prev_voted = "true";
itemClickCallback.removeDownvote(position);
}
// remove previous downvote
}
// set user vote to up
chatMessageHelper.setUserVote(vote);
if (chatMessageHelper.getUserVote().equals(vote)) {
toggleVote(holder.bUpvote, selectedColorAgree, false);
toggleVote(holder.bDownvote, unselectedColor, true);
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
// insert into user profile
itemClickCallback.insertVote(position, prev_voted, vote);
}
});
holder.bDownvote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onDownvoteClick(position);
// MAKE boolean LOL
String prev_voted = "false", vote = "down";
// check if previously voted
if (chatMessageHelper.getUserVote() != null) {
if (chatMessageHelper.getUserVote().equals("up")) {
prev_voted = "true";
itemClickCallback.removeUpvote(position);
}
// remove previous downvote
}
chatMessageHelper.setUserVote(vote);
if (chatMessageHelper.getUserVote().equals(vote)) {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, selectedColorDisagree, false);
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
// insert into user profile
itemClickCallback.insertVote(position, prev_voted, vote);
}
});
holder.avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onAvatarClick(position);
}
});
}
use of ingage.ingage.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatFragment method removeDownvote.
@Override
public void removeDownvote(int p) {
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference downvote_count = message_root.child("downvotes");
downvote_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) {
}
});
}
use of ingage.ingage.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) {
}
});
}
Aggregations