Search in sources :

Example 31 with ChatMsg

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

the class XmppService method sendNotify.

@SuppressLint("NewApi")
private void sendNotify(Message msg, ChatMsg chat) {
    // Figure to push open the corresponding chat only
    boolean isOfflineMsg = false;
    String notifyTicker = "";
    if (msg.getMsgtype() == Message.MsgType.normalchat) {
        // Normal chat
        try {
            ChatMsg chatmsg = parseBody(msg);
            chatmsg.setMsgType(msg.getMsgtype());
            // Determine whether is talking to the user
            SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
            String chatuid = preferences.getString("chatuid", null);
            if (chatuid != null && chatuid.equals(chatmsg.getChatId())) {
                return;
            }
            if (// Only digital tip shielding group chat, don't push messages, and there is no sound and vibration
            chatmsg.getGroupMask()) {
                return;
            }
            switch(chatmsg.getType()) {
                case // The text
                0:
                    notifyTicker = chatmsg.getUsername() + ":" + chatmsg.getContent();
                    break;
                case // The picture
                1:
                    notifyTicker = getString(R.string.chat_notify_picture, chatmsg.getUsername());
                    break;
                case // voice
                2:
                    notifyTicker = getString(R.string.chat_notify_audio, chatmsg.getUsername());
                    break;
                case // gif
                3:
                    notifyTicker = getString(R.string.chat_notify_gif, chatmsg.getUsername());
                    break;
                case // Business card
                6:
                    notifyTicker = getString(R.string.chat_notify_card, chatmsg.getUsername(), chatmsg.getThirdName());
                    break;
                case // Share links
                13:
                    notifyTicker = getString(R.string.chat_notify_link, chatmsg.getUsername());
                    break;
                case // Micro video
                15:
                    notifyTicker = getString(R.string.chat_notify_small_video, chatmsg.getUsername());
                    break;
                case // file
                19:
                    notifyTicker = getString(R.string.chat_notify_file, chatmsg.getUsername());
                    break;
                default:
                    return;
            }
        } catch (Exception e) {
        }
    } else if (msg.getMsgtype() == Message.MsgType.system) {
        // System information
        try {
            ChatMsg sysmsg = parseBody(msg);
            sysmsg.setMsgType(msg.getMsgtype());
            switch(sysmsg.getType()) {
                case // Offline message
                -1:
                    if (!Utils.getIMEI(XmppService.this).equals(msg.getTo().split("/")[1])) {
                        return;
                    }
                    notifyTicker = sysmsg.getContent();
                    isOfflineMsg = true;
                    break;
                case // A friend request message
                0:
                    return;
                // no
                case 1:
                case // Friend, delete the message
                2:
                    return;
                case 12:
                case 13:
                    {
                        // Determine whether is the group chat
                        SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
                        String chatuid = preferences.getString("chatuid", null);
                        if (chatuid != null && chatuid.replace("group-", "").equals(sysmsg.getGroupId())) {
                            return;
                        }
                        if (!TextUtils.isEmpty(sysmsg.getInviteName())) {
                            notifyTicker = getString(R.string.chat_notify_invite, sysmsg.getInviteName(), sysmsg.getGroupName());
                        } else {
                            notifyTicker = getString(R.string.chat_notify_invited_join, sysmsg.getGroupName());
                        }
                        break;
                    }
                case 14:
                    {
                        SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
                        String chatuid = preferences.getString("chatuid", null);
                        if (chatuid != null && chatuid.replace("group-", "").equals(sysmsg.getGroupId())) {
                            return;
                        }
                        notifyTicker = getString(R.string.chat_notify_move_out, sysmsg.getGroupName());
                        break;
                    }
                case 15:
                    {
                        SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
                        String chatuid = preferences.getString("chatuid", null);
                        if (chatuid != null && chatuid.replace("group-", "").equals(sysmsg.getGroupId())) {
                            return;
                        }
                        if (TextUtils.isEmpty(sysmsg.getGroupName())) {
                            notifyTicker = getString(R.string.chat_notify_group_dissolve);
                        } else {
                            notifyTicker = getString(R.string.chat_notify_dissolution_of, sysmsg.getGroupName());
                        }
                        break;
                    }
                case 105:
                    notifyTicker = getString(R.string.chat_notify_have_join, sysmsg.getGroupName());
                    break;
                default:
                    return;
            }
        } catch (Exception e) {
        // TODO: handle exception
        }
    } else if (msg.getMsgtype() == Message.MsgType.groupchat) {
        // Group chat
        try {
            ChatMsg chatmsg = parseBody(msg);
            // Determine whether is the group chat
            SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
            String chatuid = preferences.getString("chatuid", null);
            if (chatuid != null && chatuid.replace("group-", "").equals(chatmsg.getGroupId())) {
                return;
            }
            if (// Only digital tip shielding group chat, don't push messages, and there is no sound and vibration
            chatmsg.getGroupMask()) {
                return;
            }
            switch(chatmsg.getType()) {
                case // The text
                0:
                    notifyTicker = chatmsg.getUsername() + ":" + chatmsg.getContent();
                    break;
                case // The picture
                1:
                    notifyTicker = getString(R.string.chat_notify_picture, chatmsg.getUsername());
                    break;
                case // voice
                2:
                    notifyTicker = getString(R.string.chat_notify_audio, chatmsg.getUsername());
                    break;
                case // gif
                3:
                    notifyTicker = getString(R.string.chat_notify_gif, chatmsg.getUsername());
                    break;
                case // Business card
                6:
                    notifyTicker = getString(R.string.chat_notify_card, chatmsg.getUsername(), chatmsg.getThirdName());
                    break;
                case // Share links
                13:
                    notifyTicker = getString(R.string.chat_notify_link, chatmsg.getUsername());
                    break;
                case // Micro video
                15:
                    notifyTicker = getString(R.string.chat_notify_small_video, chatmsg.getUsername());
                    break;
                case // file
                19:
                    notifyTicker = getString(R.string.chat_notify_file, chatmsg.getUsername());
                    break;
                default:
                    return;
            }
        } catch (Exception e) {
        // TODO: handle exception
        }
    } else if (msg.getMsgtype() == Message.MsgType.super_groupchat) {
        // Group chat
        try {
            ChatMsg chatmsg = parseBody(msg);
            // Determine whether is the group chat
            SharedPreferences preferences = getSharedPreferences("chatuid", MODE_PRIVATE);
            String chatuid = preferences.getString("chatuid", null);
            if (chatuid != null && chatuid.replace("superGroup-", "").equals(chatmsg.getGroupId())) {
                return;
            }
            if (// Only digital tip shielding group chat, don't push messages, and there is no sound and vibration
            chatmsg.getGroupMask()) {
                return;
            }
            switch(chatmsg.getType()) {
                case // text
                1000:
                    notifyTicker = chatmsg.getUsername() + ":" + chatmsg.getContent();
                    break;
                case // picture
                1001:
                    notifyTicker = getString(R.string.chat_notify_picture, chatmsg.getUsername());
                    break;
                case // voice
                1002:
                    notifyTicker = getString(R.string.chat_notify_audio, chatmsg.getUsername());
                    break;
                case // gif
                1003:
                    notifyTicker = getString(R.string.chat_notify_gif, chatmsg.getUsername());
                    break;
                case // card
                1006:
                    notifyTicker = getString(R.string.chat_notify_card, chatmsg.getUsername(), chatmsg.getThirdName());
                    break;
                case // share link
                1013:
                    notifyTicker = getString(R.string.chat_notify_link, chatmsg.getUsername());
                    break;
                case // video
                1015:
                    notifyTicker = getString(R.string.chat_notify_small_video, chatmsg.getUsername());
                    break;
                case // file
                1019:
                    notifyTicker = getString(R.string.chat_notify_file, chatmsg.getUsername());
                    break;
                // Compatibility groups across the domain name to send message does not display, such as red envelopes, red packets +, live, replay scene
                case 50001:
                case 50002:
                    notifyTicker = getString(R.string.chat_notify_two_hint, chatmsg.getUsername(), chatmsg.getContent());
                    break;
                default:
                    return;
            }
        } catch (Exception e) {
        // TODO: handle exception
        }
    } else {
        return;
    }
    String notifyContent = "";
    String notifyTitle = getString(R.string.app_name);
    Intent i = new Intent(XmppService.this, MainFragmentUI.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("isNewMsg", true);
    int notifyid = 0;
    if (isOfflineMsg) {
        notifyid = (int) (System.currentTimeMillis() / 1000);
        i.putExtra("isOfflineMsg", isOfflineMsg);
        i.putExtra("offlineContent", notifyTicker);
        XmppUtils.getInstance().destroy();
        stopSelf();
    } else {
        i.putExtra("msg", chat);
    }
    if (// General chat messages
    notifyid == 0) {
        notifyContent = notifyTicker;
    } else {
        notifyContent = notifyTicker;
    }
    PendingIntent contentIntent = PendingIntent.getActivity(XmppService.this, notifyid, i, PendingIntent.FLAG_UPDATE_CURRENT);
    Builder mBuilder = new Notification.Builder(XmppService.this).setContentIntent(contentIntent).setSmallIcon(R.drawable.notifyicon).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.logo)).setWhen(System.currentTimeMillis()).setTicker(notifyTicker).setContentTitle(notifyTitle).setContentText(notifyContent).setAutoCancel(true);
    boolean sound = MySharedPrefs.readBoolean(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.MSG_SOUND + NextApplication.myInfo.getLocalId());
    boolean vibration = MySharedPrefs.readBoolean(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.MSG_VIBRATION + NextApplication.myInfo.getLocalId());
    boolean isNoDisturb = MySharedPrefs.readBoolean(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.NO_DISURB_MODE);
    // Determine if the do not disturb mode period
    boolean isInTime = false;
    if (isNoDisturb) {
        int beginHour = MySharedPrefs.readInt1(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.NO_DISURB_MODE_BEGIN_TIME_HOUR);
        int beginMinute = MySharedPrefs.readInt1(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.NO_DISURB_MODE_BEGIN_TIME_MINUTE);
        int endHour = MySharedPrefs.readInt1(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.NO_DISURB_MODE_END_TIME_HOUR);
        int endMinute = MySharedPrefs.readInt1(XmppService.this, MySharedPrefs.FILE_USER, MySharedPrefs.NO_DISURB_MODE_END_TIME_MINUTE);
        if (beginHour == -1 || beginMinute == -1) {
            beginHour = 23;
            beginMinute = 0;
        }
        if (endHour == -1 || endMinute == -1) {
            endHour = 8;
            endMinute = 0;
        }
        if (beginHour > endHour || beginHour == endHour && beginMinute > endMinute) {
            endHour += 24;
        }
        Date date = new Date();
        int currentHour = date.getHours();
        int currentMin = date.getMinutes();
        if (currentHour > beginHour && currentHour < endHour) {
            isInTime = true;
        } else if (currentHour == beginHour && currentMin >= beginMinute) {
            if (beginHour == endHour) {
                if (currentMin <= endMinute) {
                    isInTime = true;
                }
            } else {
                if (currentHour < endHour) {
                    isInTime = true;
                }
            }
        } else if (currentHour == endHour && currentMin <= endMinute) {
            if (beginHour == endHour) {
                if (currentMin >= beginMinute) {
                    isInTime = true;
                }
            } else {
                if (currentHour > beginHour) {
                    isInTime = true;
                }
            }
        }
    }
    if (!isInTime) {
        if (sound && vibration) {
            mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        } else if (sound) {
            mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        } else if (vibration) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }
    }
    if (notifyid == 0) {
        notificationManager.cancel(0);
    }
    notificationManager.notify(notifyid, mBuilder.getNotification());
}
Also used : SharedPreferences(android.content.SharedPreferences) Builder(android.app.Notification.Builder) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Date(java.util.Date) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) SuppressLint(android.annotation.SuppressLint)

Example 32 with ChatMsg

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

the class GroupQuickMarkUI method shareToSmartMesh.

private void shareToSmartMesh() {
    try {
        String qrPath = BitmapUtils.uploadZxing(GroupQuickMarkUI.this, BitmapUtils.takeScreenShot(GroupQuickMarkUI.this), false, true);
        ArrayList<ChatMsg> list = new ArrayList<>();
        ChatMsg msg = new ChatMsg();
        msg.setType(1);
        msg.setContent(qrPath);
        msg.setLocalUrl(qrPath);
        msg.parseUserBaseVo(NextApplication.myInfo);
        list.add(msg);
        Intent intent = new Intent(GroupQuickMarkUI.this, ContactSelectedUI.class);
        intent.putExtra("msglist", list);
        startActivity(intent);
        Utils.openNewActivityAnim(GroupQuickMarkUI.this, false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) WriterException(com.google.zxing.WriterException) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 33 with ChatMsg

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

the class MsgTransListUI method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(MsgTransListUI.this, TransactionDetailActivity.class);
    ChatMsg chatmsg = mList.get(position);
    TransVo transVo = new TransVo();
    transVo.setTime(chatmsg.getCreateTime());
    transVo.setType(Integer.parseInt(chatmsg.getMode()));
    transVo.setTxBlockNumber(Integer.parseInt(chatmsg.getTxBlockNumber()));
    transVo.setFee(chatmsg.getFee());
    transVo.setValue(chatmsg.getMoney());
    transVo.setTxurl(chatmsg.getShareUrl());
    transVo.setTx(chatmsg.getNumber());
    transVo.setFromAddress(chatmsg.getFromAddress());
    transVo.setToAddress(chatmsg.getToAddress());
    transVo.setState(chatmsg.getInviteType() + 1);
    transVo.setNoticeType(chatmsg.getNoticeType());
    intent.putExtra("transVo", transVo);
    startActivity(intent);
}
Also used : Intent(android.content.Intent) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) TransVo(com.lingtuan.firefly.wallet.vo.TransVo)

Example 34 with ChatMsg

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

the class MsgTransListUI method onItemLongClick.

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
    MyDialogFragment mdf = new MyDialogFragment(MyDialogFragment.DIALOG_LIST, R.array.delete_trans_array);
    mdf.setItemClickCallback(new MyDialogFragment.ItemClickCallback() {

        @Override
        public void itemClickCallback(int which) {
            ChatMsg msg = mList.get(position);
            FinalUserDataBase.getInstance().deleteChatEventTransByMessageId(msg.getMessageId());
            MyToast.showToast(MsgTransListUI.this, getString(R.string.delete_success));
            mList.remove(position);
            mAdapter.updateList(mList);
        }
    });
    mdf.show(getSupportFragmentManager(), "mdf");
    return true;
}
Also used : MyDialogFragment(com.lingtuan.firefly.util.MyDialogFragment) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 35 with ChatMsg

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

the class XmppMessageUtil method sendText.

/**
 * Send a text message
 */
public ChatMsg sendText(String uid, String content, boolean isAtGroupAll, String at, String uName, String avatarUrl, boolean isGroup, boolean isSend) {
    ChatMsg chatMsg = new ChatMsg();
    chatMsg.setType(0);
    chatMsg.setContent(content);
    chatMsg.setAtGroupIds(at);
    chatMsg.setIsAtGroupAll(isAtGroupAll);
    return send(uid, uName, avatarUrl, chatMsg, true, isGroup, isSend);
}
Also used : 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