Search in sources :

Example 11 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 12 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 13 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)

Example 14 with ChatMessageHelper

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);
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage20.helpers.ChatMessageHelper) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 15 with ChatMessageHelper

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

Aggregations

ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)19 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)8 DatabaseReference (com.google.firebase.database.DatabaseReference)8 MutableData (com.google.firebase.database.MutableData)8 Transaction (com.google.firebase.database.Transaction)8 Iterator (java.util.Iterator)4 ChatFeaturesHandler (ingage.ingage20.handlers.ChatFeaturesHandler)3 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SessionManager (ingage.ingage20.managers.SessionManager)1 ExecutionException (java.util.concurrent.ExecutionException)1