Search in sources :

Example 6 with ChatMessageHelper

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) {
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage20.helpers.ChatMessageHelper) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.google.firebase.database.Transaction) DatabaseReference(com.google.firebase.database.DatabaseReference) MutableData(com.google.firebase.database.MutableData) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 7 with ChatMessageHelper

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);
}
Also used : ChatMessageHelper(ingage.ingage20.helpers.ChatMessageHelper) ChatFeaturesHandler(ingage.ingage20.handlers.ChatFeaturesHandler)

Example 8 with ChatMessageHelper

use of ingage.ingage20.helpers.ChatMessageHelper in project iNGAGE by davis123123.

the class ChatArrayAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ChatArrayAdapter.ChatViewHolder holder, int position) {
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) this.getItem(position);
    //side = chatMessageHelper.getSide();
    holder.bind(position);
}
Also used : ChatMessageHelper(ingage.ingage20.helpers.ChatMessageHelper)

Example 9 with ChatMessageHelper

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());
}
Also used : ChatMessageHelper(ingage.ingage20.helpers.ChatMessageHelper)

Aggregations

ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)9 DataSnapshot (com.google.firebase.database.DataSnapshot)6 DatabaseError (com.google.firebase.database.DatabaseError)4 DatabaseReference (com.google.firebase.database.DatabaseReference)4 MutableData (com.google.firebase.database.MutableData)4 Transaction (com.google.firebase.database.Transaction)4 Iterator (java.util.Iterator)2 ChatFeaturesHandler (ingage.ingage20.handlers.ChatFeaturesHandler)1