Search in sources :

Example 6 with ChatMessageHelper

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

the class ChatFragment method onAvatarClick.

// inserts vote in mysql database
@Override
public void onAvatarClick(int p) {
    ChatFeaturesHandler chatFeaturesHandler = new ChatFeaturesHandler(getContext());
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
    String user = chatMessageHelper.getMessageUser();
    // Log.d("AvatarClick", chatMessageHelper.getMessageUser());
    chatActivity.startProfileActivity(user);
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper) ChatFeaturesHandler(ingage.ingage.handlers.ChatFeaturesHandler)

Example 7 with ChatMessageHelper

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

the class ChatFragment method insertVote.

@Override
public void insertVote(int p, String prev_voted, String vote) {
    String type = "insert_vote";
    ChatFeaturesHandler chatFeaturesHandler = new ChatFeaturesHandler(getContext());
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
    // sets user's vote to memory
    chatMessageHelper.setUserVote(vote);
    // username is messageBy
    String messageBy = chatMessageHelper.getMessageUser();
    Log.d("insertvote", type + vote + prev_voted);
    String chat_id = chatMessageHelper.getMessageID();
    String chat_side = chatMessageHelper.getSide();
    HashMap<String, String> chat = chatRoomManager.getUserDetails();
    String thread_id = chat.get(ChatRoomManager.THREAD_ID);
    session = new SessionManager(getContext());
    HashMap<String, String> user = session.getUserDetails();
    // chatuser is current user of app
    String chat_user = user.get(SessionManager.KEY_NAME);
    // insert vote into target user profile and own profile
    Log.d("insertvote", chat_user);
    String result = "";
    try {
        result = chatFeaturesHandler.execute(type, messageBy, thread_id, prev_voted, chat_id, vote, chat_side, chat_user).get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
// Log.d("insertvote", result);
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper) SessionManager(ingage.ingage.managers.SessionManager) ExecutionException(java.util.concurrent.ExecutionException) ChatFeaturesHandler(ingage.ingage.handlers.ChatFeaturesHandler)

Example 8 with ChatMessageHelper

use of ingage.ingage.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) {
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage.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 9 with ChatMessageHelper

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

the class ChatArrayAdapter method update.

public void update(ChatMessageHelper newObject, String chat_id, boolean updateBind) {
    // get old chatmsg
    int position = chatHash.get(chat_id);
    Log.d("UPvote state: ", " upvote called");
    // update oldmsg with newobject
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) getItem(position);
    chatMessageHelper.setMessageDownvote(newObject.getMessageDownvote());
    chatMessageHelper.setMessageUpvote(newObject.getMessageUpvote());
    chatMessageHelper.setMessageText(newObject.getMessageText());
    chatMessageHelper.setMessageTime(newObject.getMessageTime());
    voteBind = updateBind;
    notifyDataSetChanged();
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper)

Example 10 with ChatMessageHelper

use of ingage.ingage.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.ingage.helpers.ChatMessageHelper)

Aggregations

ChatMessageHelper (ingage.ingage.helpers.ChatMessageHelper)11 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 ChatFeaturesHandler (ingage.ingage.handlers.ChatFeaturesHandler)2 Iterator (java.util.Iterator)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SessionManager (ingage.ingage.managers.SessionManager)1 ExecutionException (java.util.concurrent.ExecutionException)1