use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatActivity method onUpvoteClick.
//modify unblock functions here
@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 = root.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 ChatActivity method insertVote.
@Override
public void insertVote(int p, String prev_voted, String vote) {
String type = "insert_vote";
ChatFeaturesHandler chatFeaturesHandler = new ChatFeaturesHandler(getApplicationContext());
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_user = chatMessageHelper.getMessageUser();
Log.d("insertvote", type + chat_user + vote + prev_voted);
chatFeaturesHandler.execute(type, chat_user, vote, prev_voted);
}
use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatArrayAdapter method update.
public void update(ChatMessageHelper newObject, String chat_id) {
//get old chatmsg
int position = chatHash.get(chat_id);
//update oldmsg with newobject
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) getItem(position);
chatMessageHelper.setMessageDownvote(newObject.getMessageDownvote());
chatMessageHelper.setMessageUpvote(newObject.getMessageUpvote());
chatMessageHelper.setMessageText(newObject.getMessageText());
}
use of ingage.ingage20.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")) {
holder.bUpvote.setEnabled(false);
holder.bDownvote.setEnabled(true);
} else if (userVote.equals("down")) {
holder.bDownvote.setEnabled(false);
holder.bUpvote.setEnabled(true);
}
} else {
holder.bUpvote.setEnabled(true);
holder.bDownvote.setEnabled(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)) {
holder.bUpvote.setEnabled(false);
holder.bDownvote.setEnabled(true);
} else {
holder.bUpvote.setEnabled(true);
holder.bDownvote.setEnabled(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)) {
holder.bDownvote.setEnabled(false);
holder.bUpvote.setEnabled(true);
} else {
holder.bUpvote.setEnabled(true);
holder.bDownvote.setEnabled(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.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.
the class ChatArrayAdapter method getItemViewType.
@Override
public int getItemViewType(int position) {
// final Object dataObj = list.get(position);
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) getItem(position);
String name = chatMessageHelper.getMessageUser();
if (list.get(position).getSide().equals("agree")) {
if (name.equals(username))
return 0;
else
return 1;
} else if (list.get(position).getSide().equals("disagree")) {
if (name.equals(username))
return 2;
else
return 3;
}
return -1;
}
Aggregations