Search in sources :

Example 1 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, 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.ingage20.helpers.ChatMessageHelper)

Example 2 with ChatMessageHelper

use of ingage.ingage20.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) {
        }
    });
}
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 3 with ChatMessageHelper

use of ingage.ingage20.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.ingage20.helpers.ChatMessageHelper) SessionManager(ingage.ingage20.managers.SessionManager) ExecutionException(java.util.concurrent.ExecutionException) ChatFeaturesHandler(ingage.ingage20.handlers.ChatFeaturesHandler)

Example 4 with ChatMessageHelper

use of ingage.ingage20.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) {
        }
    });
}
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 5 with ChatMessageHelper

use of ingage.ingage20.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.ingage20.helpers.ChatMessageHelper) ChatFeaturesHandler(ingage.ingage20.handlers.ChatFeaturesHandler)

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