Search in sources :

Example 46 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChattingManager method setCardInfo.

public void setCardInfo(UserBaseVo cardVo) {
    boolean successed = true;
    if (uid.equals(Constants.APP_EVERYONE)) {
        ChatMsg msg = XmppMessageUtil.getInstance().sendCard(uid, userName, avatarUrl, cardVo.getShowName(), cardVo.getSightml(), cardVo.getThumb(), cardVo.getLocalId(), isGroup, isSend);
        if (appNetService != null) {
            WifiPeopleVO cardInfo = new WifiPeopleVO();
            cardInfo.setLocalId(cardVo.getLocalId());
            cardInfo.setUsername(cardVo.getUsername());
            cardInfo.setSightml(cardVo.getSightml());
            String path;
            if (cardVo.getThumb().startsWith("http") || cardVo.getThumb().startsWith("www")) {
                path = NextApplication.mImageLoader.getDiscCache().get(cardVo.getThumb()).getPath();
            } else {
                path = cardVo.getThumb();
            }
            cardInfo.setThumb(path);
            successed = appNetService.handleSendCard(cardInfo, true, uid, msg.getMessageId());
        }
        if (msg.getSend() == 0 && !successed) {
            msg.setSend(0);
        }
        mAdapter.addChatMsg(msg, true);
    } else if (isGroup) {
        ChatMsg msg = XmppMessageUtil.getInstance().sendCard(uid, userName, avatarUrl, cardVo.getShowName(), cardVo.getSightml(), cardVo.getThumb(), cardVo.getLocalId(), isGroup, isSend);
        mAdapter.addChatMsg(msg, true);
    } else {
        boolean foundPeople = false;
        if (appNetService != null && appNetService.getwifiPeopleList() != null) {
            for (// All users need to traverse, find out the corresponding touid users
            WifiPeopleVO vo : // All users need to traverse, find out the corresponding touid users
            appNetService.getwifiPeopleList()) {
                if (uid.equals(vo.getLocalId())) {
                    foundPeople = true;
                    break;
                }
            }
        }
        if (// With no net with no net send messages
        foundPeople) {
            WifiPeopleVO cardInfo = new WifiPeopleVO();
            cardInfo.setLocalId(cardVo.getLocalId());
            cardInfo.setUsername(cardVo.getUsername());
            cardInfo.setSightml(cardVo.getSightml());
            String path;
            if (cardVo.getThumb().startsWith("http") || cardVo.getThumb().startsWith("www")) {
                path = NextApplication.mImageLoader.getDiscCache().get(cardVo.getThumb()).getPath();
            } else {
                path = cardVo.getThumb();
            }
            cardInfo.setThumb(path);
            ChatMsg msg = new ChatMsg();
            msg.setType(6);
            msg.setThirdId(cardInfo.getLocalId());
            msg.setThirdImage(cardInfo.getThumb());
            msg.setThirdName(cardInfo.getUserName());
            msg.setCardSign(cardInfo.getSightml());
            msg.setOffLineMsg(true);
            msg.setSend(1);
            msg.setMessageId(UUID.randomUUID().toString());
            msg.setMsgTime(System.currentTimeMillis() / 1000);
            msg.setShowTime(FinalUserDataBase.getInstance().isOffLineShowTime(uid, msg.getMsgTime()));
            successed = appNetService.handleSendCard(cardInfo, false, uid, msg.getMessageId());
            if (!successed) {
                msg.setSend(0);
            }
            mAdapter.addChatMsg(msg, true);
            FinalUserDataBase.getInstance().saveChatMsg(msg, uid, userName, avatarUrl);
        } else {
            ChatMsg msg = XmppMessageUtil.getInstance().sendCard(uid, userName, avatarUrl, cardVo.getShowName(), cardVo.getSightml(), cardVo.getThumb(), cardVo.getLocalId(), isGroup, isSend);
            mAdapter.addChatMsg(msg, true);
        }
    }
    listView.setSelection(mAdapter.getCount());
}
Also used : WifiPeopleVO(com.lingtuan.firefly.offline.vo.WifiPeopleVO) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 47 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChattingManager method createImageChatMsg.

/**
 * Create photo chat entity class
 */
private ChatMsg createImageChatMsg(String uid, String content, String uName, String avatarUrl, String cover, boolean isGroup, boolean isSend) {
    ChatMsg chatMsg = new ChatMsg();
    chatMsg.setType(1);
    // 
    chatMsg.setContent(content);
    chatMsg.setLocalUrl(content);
    chatMsg.setCover(cover);
    chatMsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
    String jid = uid + "@" + XmppUtils.SERVER_NAME;
    if (isGroup) {
        jid = uid.replace("group-", "") + "@group." + XmppUtils.SERVER_NAME;
    }
    Message msg = new Message(jid, Type.chat);
    chatMsg.setMessageId(msg.getPacketID());
    if (isGroup) {
        // 
        msg.setMsgtype(MsgType.groupchat);
        chatMsg.setChatId(uid);
        chatMsg.setGroup(isGroup);
        chatMsg.setSource(NextApplication.mContext.getString(R.string.app_name));
        chatMsg.setUserfrom(mContext.getString(R.string.app_name));
        chatMsg.setUsersource(XmppUtils.SERVER_NAME);
        msg.setBody(chatMsg.toGroupChatJsonObject());
    } else {
        chatMsg.setSource(mContext.getString(R.string.app_name));
        msg.setBody(chatMsg.toChatJsonObject());
    }
    chatMsg.setMsgTime(System.currentTimeMillis() / 1000);
    if (isSend) {
        chatMsg.setSend(2);
    }
    FinalUserDataBase.getInstance().saveChatMsg(chatMsg, uid, uName, avatarUrl);
    chatMsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
    if (isSend) {
        Bundle bundle = new Bundle();
        bundle.putInt("type", 2);
        bundle.putString("uid", uid);
        bundle.putString("username", uName);
        bundle.putString("avatarurl", avatarUrl);
        bundle.putSerializable("chatmsg", chatMsg);
        Utils.intentService(mContext, LoadDataService.class, LoadDataService.ACTION_FILE_UPLOAD_CHAT, LoadDataService.ACTION_FILE_UPLOAD_CHAT, bundle);
    }
    return chatMsg;
}
Also used : Message(org.jivesoftware.smack.packet.Message) Bundle(android.os.Bundle) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 48 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChattingManager method sendImgMethod.

/**
 * Sending pictures method
 * @param picturePath Image path
 */
private void sendImgMethod(String picturePath) {
    float density = mContext.getResources().getDisplayMetrics().density;
    // mContext.getResources().getDisplayMetrics().widthPixels;
    int screenWidth = Constants.MAX_IMAGE_WIDTH;
    // mContext.getResources().getDisplayMetrics().heightPixels;
    int screenHeight = Constants.MAX_IMAGE_HEIGHT;
    int width = (int) (120 * density);
    Bitmap bmp = BitmapUtils.getimage(picturePath, width, width, 10);
    Bitmap bmpUpload = BitmapUtils.getimage(picturePath, screenWidth, screenHeight, Constants.MAX_KB);
    BitmapUtils.saveBitmap2SD(bmp, 10, false);
    String uploadPath = BitmapUtils.saveBitmap2SD(bmpUpload, screenWidth, true).getPath();
    String url = uploadPath;
    boolean successed = true;
    if (uid.equals(Constants.APP_EVERYONE)) {
        ChatMsg msg = createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
        if (appNetService != null) {
            successed = appNetService.handleSendPicutre(url, true, uid, msg.getMessageId());
        }
        if (msg.getSend() == 0 && !successed) {
            msg.setSend(0);
        }
        mAdapter.addChatMsg(msg, true);
    } else if (uid.equals(Constants.APP_MESH)) {
        // send mesh picture
        ChatMsg msg = createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
        mAdapter.addChatMsg(msg, true);
    } else if (isGroup) {
        ChatMsg msg = createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
        mAdapter.addChatMsg(msg, true);
    } else {
        boolean foundPeople = false;
        if (appNetService != null && appNetService.getwifiPeopleList() != null) {
            for (// All users need to traverse, find out the corresponding touid users
            WifiPeopleVO vo : // All users need to traverse, find out the corresponding touid users
            appNetService.getwifiPeopleList()) {
                if (uid.equals(vo.getLocalId())) {
                    foundPeople = true;
                    break;
                }
            }
        }
        if (// With no net with no net send messages
        foundPeople) {
            ChatMsg msg = new ChatMsg();
            msg.setType(1);
            msg.setContent(url);
            msg.setLocalUrl(url);
            msg.setCover(BitmapUtils.BitmapToBase64String(bmp));
            msg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
            msg.setChatId(uid);
            msg.setOffLineMsg(true);
            msg.setSend(1);
            msg.setMessageId(UUID.randomUUID().toString());
            msg.setMsgTime(System.currentTimeMillis() / 1000);
            msg.setShowTime(FinalUserDataBase.getInstance().isOffLineShowTime(uid, msg.getMsgTime()));
            successed = appNetService.handleSendPicutre(url, false, uid, msg.getMessageId());
            if (!successed) {
                msg.setSend(0);
            }
            mAdapter.addChatMsg(msg, true);
            FinalUserDataBase.getInstance().saveChatMsg(msg, uid, userName, avatarUrl);
        } else {
            ChatMsg msg = createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
            mAdapter.addChatMsg(msg, true);
        }
    }
    listView.setSelection(mAdapter.getCount());
    if (bmp != null && !bmp.isRecycled()) {
        bmp.recycle();
    }
    if (bmpUpload != null && !bmpUpload.isRecycled()) {
        bmpUpload.recycle();
    }
}
Also used : Bitmap(android.graphics.Bitmap) WifiPeopleVO(com.lingtuan.firefly.offline.vo.WifiPeopleVO) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 49 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChattingUI method initData.

@Override
protected void initData() {
    if (uid.equals(Constants.APP_EVERYONE)) {
        setTitle(getString(R.string.everyone));
        chattingSet.setVisibility(View.GONE);
        mMeshPhoto.setVisibility(View.GONE);
    } else if (uid.equals(Constants.APP_MESH)) {
        setTitle(getString(R.string.wifimesh));
        chattingSet.setImageResource(R.drawable.icon_friend_info);
        chattingSet.setVisibility(View.VISIBLE);
        mMeshPhoto.setVisibility(View.VISIBLE);
    } else {
        setTitle(userName);
        chattingSet.setImageResource(R.drawable.icon_friend_info);
        chattingSet.setVisibility(View.VISIBLE);
        mMeshPhoto.setVisibility(View.GONE);
    }
    if (uid.equals(Constants.APP_EVERYONE) || isGroup) {
        mFile.setVisibility(View.GONE);
    } else if (uid.equals(Constants.APP_MESH)) {
        chattingBottomRela.setVisibility(View.GONE);
    } else {
        mFile.setVisibility(View.VISIBLE);
    }
    swipeLayout.setColorSchemeResources(R.color.black);
    // Remove notification bar
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
    ChattingManager.getInstance(this).destory();
    chattingManager = ChattingManager.getInstance(this);
    if (NextApplication.myInfo != null) {
        int openSmartMesh = MySharedPrefs.readInt1(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_NO_NETWORK_COMMUNICATION + NextApplication.myInfo.getLocalId());
        if (openSmartMesh == 1) {
            bindService(new Intent(this, AppNetService.class), serviceConn, BIND_AUTO_CREATE);
        }
    }
    // message broadcast distribution
    IntentFilter filter = new IntentFilter(XmppAction.ACTION_MESSAGE_LISTENER);
    // message list broadcast distribution
    filter.addAction(XmppAction.ACTION_OFFLINE_MESSAGE_LIST_LISTENER);
    // message update broadcast distribution
    filter.addAction(XmppAction.ACTION_MESSAGE_UPDATE_LISTENER);
    // message update kick
    filter.addAction(XmppAction.ACTION_MESSAGE_GROUP_KICK_LISTENER);
    // message sending pictures percentage
    filter.addAction(XmppAction.ACTION_MESSAGE_IMAGE_PERCENT);
    // More pictures to send
    filter.addAction(Constants.ACTION_CHATTING_FRIEND_NOTE);
    // More pictures to send
    filter.addAction(XmppAction.ACTION_ENTER_EVERYONE_LISTENER);
    // chat
    filter.addAction(Constants.MSG_REPORT_SEND_MSG_RESULT);
    filter.addAction(Constants.MSG_REPORT_SEND_MSG_PROGRESS);
    filter.addAction(Constants.MSG_REPORT_START_RECV_FILE);
    filter.addAction(Constants.MSG_REPORT_CANCEL_SEND_FILE);
    filter.addAction(Constants.MSG_REPORT_CANCEL_RECV_FILE);
    msgReceiverListener = new MsgReceiverListener();
    registerReceiver(msgReceiverListener, filter);
    // Choose picture sends the message
    IntentFilter filterVideo = new IntentFilter(Constants.ACTION_CHATTING_PHOTO_LIST);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filterVideo);
    XmppMessageUtil.getInstance().setGroupDismiss(isDismissGroup);
    XmppMessageUtil.getInstance().setGroupKick(isKickGroup);
    chattingManager.setGroup(isGroup);
    chattingManager.setSend(!(isDismissGroup || isKickGroup));
    chattingManager.setmInputContent(mInputContent);
    List<ChatMsg> mList = FinalUserDataBase.getInstance().getChatMsgListByChatId(uid, 0, 20);
    for (int i = 0; i < mList.size(); i++) {
        ChatMsg vo = mList.get(i);
        if (vo.getType() == 1010 && vo.getUnread() == 1) {
            vo.setUnread(0);
            FinalUserDataBase.getInstance().updateChatMsgUrneadBymessageId(vo.getMessageId());
        }
    }
    unreadStartIndex = (mList.size() - unread) > 0 ? (mList.size() - unread) : 0;
    if (unread > mList.size()) {
        unreadOffset = unread - mList.size();
    }
    if (unread > 0) {
        showunreadNum();
    }
    for (ChatMsg msg : mList) {
        if (// Is sending images, voice, video because of the need to upload, is if it is sent every time into the state, send again
        msg.getSend() == 2) {
            if (// The picture
            msg.getType() == 1) {
                XmppMessageUtil.getInstance().reSend(3, msg);
            } else if (// voice
            msg.getType() == 2) {
                XmppMessageUtil.getInstance().reSend(11, msg);
            }
        }
    }
    mAdapter = new ChatAdapter(mList, this, this, listView);
    int source = 1;
    String sourcid = uid;
    if (isGroup) {
        source = 2;
        sourcid = uid.replace("group-", "");
    }
    mAdapter.setChatType(source, sourcid);
    mAdapter.setInputEditText(mInputContent, chattingManager);
    mAdapter.setGroup(isGroup);
    mAdapter.setKickDismiss(isKickGroup, isDismissGroup);
    chattingManager.setUserInfo(userName, avatarUrl, uid, mAdapter, listView);
    listView.setAdapter(mAdapter);
    listView.setSelection(mList.size());
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            finishTempActivity();
        }
    }, 100);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (isDismissGroup || isKickGroup) {
                showToast(isDismissGroup ? getString(R.string.discuss_group_dismiss) : getString(R.string.discuss_group_kick));
            }
        }
    }, 500);
}
Also used : IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) AppNetService(com.lingtuan.firefly.offline.AppNetService) Handler(android.os.Handler) Intent(android.content.Intent) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) ChatAdapter(com.lingtuan.firefly.chat.adapter.ChatAdapter)

Example 50 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChattingUI method hideunreadNum.

private void hideunreadNum(final boolean gotoTop) {
    hasHideunreadNum = true;
    if (gotoTop) {
        if (unreadOffset > 0) {
            List<ChatMsg> mList = FinalUserDataBase.getInstance().getChatMsgListByChatId(uid, 0, unreadOffset + mAdapter.getCount());
            for (int i = 0; i < mList.size(); i++) {
                ChatMsg vo = mList.get(i);
                if (vo.getType() == 1010 && vo.getUnread() == 1) {
                    vo.setUnread(0);
                    FinalUserDataBase.getInstance().updateChatMsgUrneadBymessageId(vo.getMessageId());
                }
            }
            mAdapter.resetSource(mList);
        }
        ChatMsg msg = new ChatMsg();
        msg.setType(12);
        msg.setContent(getString(R.string.chatting_new_message));
        mAdapter.insertSystemChatMsg(unreadStartIndex, msg);
        listView.setSelection(unreadStartIndex + 1);
    }
    final int width = unreadNum.getWidth();
    Animation transanimOut = new Animation() {

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            {
                RelativeLayout.LayoutParams lp = (android.widget.RelativeLayout.LayoutParams) unreadNum.getLayoutParams();
                lp.setMargins(0, Utils.dip2px(ChattingUI.this, 50), -(int) (width * interpolatedTime), 0);
                unreadNum.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    transanimOut.setDuration(300);
    transanimOut.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            unreadNum.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    unreadNum.startAnimation(transanimOut);
}
Also used : Transformation(android.view.animation.Transformation) RelativeLayout(android.widget.RelativeLayout) Animation(android.view.animation.Animation) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Aggregations

ChatMsg (com.lingtuan.firefly.vo.ChatMsg)61 Bundle (android.os.Bundle)17 Intent (android.content.Intent)12 ArrayList (java.util.ArrayList)11 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)9 Cursor (android.database.Cursor)8 SuppressLint (android.annotation.SuppressLint)6 WifiPeopleVO (com.lingtuan.firefly.offline.vo.WifiPeopleVO)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 GroupMemberAvatarVo (com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo)4 PendingIntent (android.app.PendingIntent)3 TextView (android.widget.TextView)3 MyDialogFragment (com.lingtuan.firefly.util.MyDialogFragment)3 LoginThread (com.lingtuan.firefly.xmpp.LoginThread)3 File (java.io.File)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 Message (android.os.Message)2 Editable (android.text.Editable)2