Search in sources :

Example 6 with Message

use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getPendingDeleteMessages.

public List<Message> getPendingDeleteMessages() {
    String structuredNameWhere = "";
    List<String> structuredNameParamsList = new ArrayList<String>();
    structuredNameWhere += "sentToServer = ? and deleted = ?";
    structuredNameParamsList.add("1");
    structuredNameParamsList.add("1");
    Cursor cursor = dbHelper.getWritableDatabase().query("sms", null, structuredNameWhere, structuredNameParamsList.toArray(new String[structuredNameParamsList.size()]), null, null, "createdAt asc");
    List<Message> messageList = getMessageList(cursor);
    return messageList;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with Message

use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getPendingMessages.

public List<Message> getPendingMessages() {
    String structuredNameWhere = "";
    List<String> structuredNameParamsList = new ArrayList<String>();
    structuredNameWhere += "sentToServer = ? and canceled = ? and deleted = ?";
    structuredNameParamsList.add("0");
    structuredNameParamsList.add("0");
    structuredNameParamsList.add("0");
    Cursor cursor = dbHelper.getWritableDatabase().query("sms", null, structuredNameWhere, structuredNameParamsList.toArray(new String[structuredNameParamsList.size()]), null, null, "createdAt asc");
    List<Message> messageList = getMessageList(cursor);
    dbHelper.close();
    return messageList;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 8 with Message

use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getScheduledMessages.

public List<Message> getScheduledMessages(Long time) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (!DBUtils.isTableExists(db, MobiComDatabaseHelper.SCHEDULE_SMS_TABLE_NAME)) {
        dbHelper.close();
        return new ArrayList<Message>();
    }
    List<Message> messages = new ArrayList<Message>();
    Cursor cursor;
    if (time != null) {
        cursor = db.query(MobiComDatabaseHelper.SCHEDULE_SMS_TABLE_NAME, null, MobiComDatabaseHelper.TIMESTAMP + " <= ?", new String[] { time + "" }, null, null, null);
    } else {
        cursor = db.query(MobiComDatabaseHelper.SCHEDULE_SMS_TABLE_NAME, null, null, null, null, null, null);
    }
    cursor.moveToFirst();
    if (cursor.getCount() > 0) {
        do {
            String createdTime = cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.TIMESTAMP));
            // SMS Creation From DB......
            Message message = new Message();
            message.setCreatedAtTime(Long.valueOf(createdTime));
            message.setScheduledAt(cursor.getLong(cursor.getColumnIndex(MobiComDatabaseHelper.TIMESTAMP)));
            message.setMessage(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.SMS)));
            message.setType(cursor.getShort(cursor.getColumnIndex(MobiComDatabaseHelper.SMS_TYPE)));
            message.setSource(cursor.getShort(cursor.getColumnIndex("source")));
            message.setContactIds(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CONTACTID)));
            message.setTo(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.TO_FIELD)));
            message.setKeyString(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.SMS_KEY_STRING)));
            message.setStoreOnDevice("1".equals(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.STORE_ON_DEVICE_COLUMN))));
            if (cursor.getColumnIndex(MobiComDatabaseHelper.TIME_TO_LIVE) != -1) {
                int timeToLive = cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.TIME_TO_LIVE));
                message.setTimeToLive(timeToLive == 0 ? null : timeToLive);
            }
            messages.add(message);
        } while (cursor.moveToNext());
    }
    cursor.close();
    dbHelper.close();
    return messages;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 9 with Message

use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getLatestMessageForChannel.

private List<Message> getLatestMessageForChannel(Integer channelKey, String clientGroupId) {
    String clauseString = null;
    if (channelKey != null && channelKey != 0) {
        clauseString = " channelKey = " + "'" + channelKey + "'";
    } else if (!TextUtils.isEmpty(clientGroupId)) {
        clauseString = " clientGroupId = " + "'" + clientGroupId + "'";
    }
    List<Message> messages = new ArrayList<Message>();
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    Cursor cursor = db.rawQuery("select * from sms where " + clauseString + " order by createdAt desc limit 1", null);
    if (cursor.moveToFirst()) {
        messages = MessageDatabaseService.getMessageList(cursor);
    }
    cursor.close();
    dbHelper.close();
    return messages;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 10 with Message

use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method sendMessage.

public void sendMessage(String message, Map<String, String> messageMetaData, FileMeta fileMetas, String fileMetaKeyStrings, short messageContentType) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
    Message messageToSend = new Message();
    if (channel != null) {
        messageToSend.setGroupId(channel.getKey());
        if (!TextUtils.isEmpty(channel.getClientGroupId())) {
            messageToSend.setClientGroupId(channel.getClientGroupId());
        }
    /*   List<String> contactIds = new ArrayList<String>();
            List<String> toList = new ArrayList<String>();
            for (Contact contact : channel.getContacts()) {
                if (!TextUtils.isEmpty(contact.getContactNumber())) {
                    toList.add(contact.getContactNumber());
                    contactIds.add(contact.getFormattedContactNumber());
                }
            }
            messageToSend.setTo(TextUtils.join(",", toList));
            messageToSend.setContactIds(TextUtils.join(",", contactIds));*/
    } else {
        messageToSend.setTo(contact.getContactIds());
        messageToSend.setContactIds(contact.getContactIds());
    }
    messageToSend.setRead(Boolean.TRUE);
    messageToSend.setStoreOnDevice(Boolean.TRUE);
    if (messageToSend.getCreatedAtTime() == null) {
        messageToSend.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
    }
    if (currentConversationId != null && currentConversationId != 0) {
        messageToSend.setConversationId(currentConversationId);
    }
    messageToSend.setSendToDevice(Boolean.FALSE);
    messageToSend.setType(sendType.getSelectedItemId() == 1 ? Message.MessageType.MT_OUTBOX.getValue() : Message.MessageType.OUTBOX.getValue());
    messageToSend.setTimeToLive(getTimeToLive());
    messageToSend.setMessage(message);
    messageToSend.setDeviceKeyString(userPreferences.getDeviceKeyString());
    messageToSend.setScheduledAt(scheduledTimeHolder.getTimestamp());
    messageToSend.setSource(Message.Source.MT_MOBILE_APP.getValue());
    if (!TextUtils.isEmpty(filePath)) {
        List<String> filePaths = new ArrayList<String>();
        filePaths.add(filePath);
        messageToSend.setFilePaths(filePaths);
        if (messageContentType == Message.ContentType.AUDIO_MSG.getValue() || messageContentType == Message.ContentType.CONTACT_MSG.getValue() || messageContentType == Message.ContentType.VIDEO_MSG.getValue()) {
            messageToSend.setContentType(messageContentType);
        } else {
            messageToSend.setContentType(Message.ContentType.ATTACHMENT.getValue());
        }
    } else {
        messageToSend.setContentType(messageContentType);
    }
    messageToSend.setFileMetaKeyStrings(fileMetaKeyStrings);
    messageToSend.setFileMetas(fileMetas);
    if (!TextUtils.isEmpty(ApplozicClient.getInstance(getActivity()).getMessageMetaData())) {
        Type mapType = new TypeToken<Map<String, String>>() {
        }.getType();
        Map<String, String> messageMetaDataMap = null;
        try {
            messageMetaDataMap = new Gson().fromJson(ApplozicClient.getInstance(getActivity()).getMessageMetaData(), mapType);
            messageToSend.setMetadata(messageMetaDataMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        messageToSend.setMetadata(this.messageMetaData);
    }
    conversationService.sendMessage(messageToSend, messageIntentClass);
    if (replayRelativeLayout != null) {
        replayRelativeLayout.setVisibility(View.GONE);
    }
    if (selfDestructMessageSpinner != null) {
        selfDestructMessageSpinner.setSelection(0);
    }
    attachmentLayout.setVisibility(View.GONE);
    if (channel != null && channel.getType() != null && Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType())) {
        sendBroadcastMessage(message, filePath);
    }
    this.messageMetaData = null;
    filePath = null;
}
Also used : Type(java.lang.reflect.Type) Message(com.applozic.mobicomkit.api.conversation.Message) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Message (com.applozic.mobicomkit.api.conversation.Message)55 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Contact (com.applozic.mobicommons.people.contact.Contact)11 Cursor (android.database.Cursor)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)8 Uri (android.net.Uri)7 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)7 File (java.io.File)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 Context (android.content.Context)5 View (android.view.View)5 MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)5 Channel (com.applozic.mobicommons.people.channel.Channel)5 Configuration (android.content.res.Configuration)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Collections.disjoint (java.util.Collections.disjoint)4 Bitmap (android.graphics.Bitmap)3 RecyclerView (android.support.v7.widget.RecyclerView)3