Search in sources :

Example 6 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class HttpRequestUtils method addGlobalHeaders.

public void addGlobalHeaders(HttpURLConnection connection) {
    try {
        connection.setRequestProperty(APPLICATION_KEY_HEADER, MobiComKitClientService.getApplicationKey(context));
        connection.setRequestProperty(SOURCE_HEADER, SOURCE_HEADER_VALUE);
        connection.setRequestProperty(USERID_HEADER, USERID_HEADER_VALUE);
        connection.setRequestProperty(DEVICE_KEY_HEADER, MobiComUserPreference.getInstance(context).getDeviceKeyString());
        Short authenticationType = Short.valueOf(MobiComUserPreference.getInstance(context).getAuthenticationType());
        if (User.AuthenticationType.APPLOZIC.getValue() == authenticationType) {
            connection.setRequestProperty(ACCESS_TOKEN, MobiComUserPreference.getInstance(context).getPassword());
        }
        if (MobiComKitClientService.getAppModuleName(context) != null) {
            connection.setRequestProperty(APP_MODULE_NAME_KEY_HEADER, MobiComKitClientService.getAppModuleName(context));
        }
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (userPreferences.isRegistered()) {
            String userCredentials = getCredentials().getUserName() + ":" + String.valueOf(getCredentials().getPassword());
            String basicAuth = "Basic " + Base64.encodeToString(userCredentials.getBytes(), Base64.NO_WRAP);
            connection.setRequestProperty("Authorization", basicAuth);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Example 7 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method syncMessages.

public synchronized void syncMessages() {
    final MobiComUserPreference userpref = MobiComUserPreference.getInstance(context);
    Utils.printLog(context, TAG, "Starting syncMessages for lastSyncTime: " + userpref.getLastSyncTime());
    SyncMessageFeed syncMessageFeed = messageClientService.getMessageFeed(userpref.getLastSyncTime(), false);
    if (syncMessageFeed == null) {
        return;
    }
    if (syncMessageFeed != null && syncMessageFeed.getMessages() != null) {
        Utils.printLog(context, TAG, "Got sync response " + syncMessageFeed.getMessages().size() + " messages.");
        processUserDetailFromMessages(syncMessageFeed.getMessages());
    }
    // more valid, do it again and make the sync request again
    if (syncMessageFeed != null && syncMessageFeed.isRegIdInvalid() && Utils.hasFroyo()) {
        Utils.printLog(context, TAG, "Going to call GCM device registration");
    // Todo: Replace it with mobicomkit gcm registration
    // C2DMessaging.register(context);
    }
    if (syncMessageFeed != null && syncMessageFeed.getMessages() != null) {
        List<Message> messageList = syncMessageFeed.getMessages();
        for (final Message message : messageList) {
            if (Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType())) {
                ChannelService.getInstance(context).syncChannels();
                // Todo: fix this, what if there are mulitple messages.
                ChannelService.isUpdateTitle = true;
            }
            processMessage(message, message.getTo());
            MobiComUserPreference.getInstance(context).setLastInboxSyncTime(message.getCreatedAtTime());
        }
        updateDeliveredStatus(syncMessageFeed.getDeliveredMessageKeys());
        userpref.setLastSyncTime(String.valueOf(syncMessageFeed.getLastSyncTime()));
    }
}
Also used : PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) SyncMessageFeed(com.applozic.mobicomkit.sync.SyncMessageFeed)

Example 8 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getMessages.

public List<Message> getMessages(Long createdAt, String searchText) {
    String createdAtClause = "";
    if (createdAt != null && createdAt > 0) {
        createdAtClause = " and m1.createdAt < " + createdAt;
    }
    createdAtClause += " and m1.deleted = 0 ";
    String messageTypeClause = "";
    String messageTypeJoinClause = "";
    String searchCaluse = "";
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    if (!userPreferences.isDisplayCallRecordEnable()) {
        messageTypeClause = " and m1.type != " + Message.MessageType.CALL_INCOMING.getValue() + " and m1.type != " + Message.MessageType.CALL_OUTGOING.getValue();
        messageTypeJoinClause = " and m1.type = m2.type";
    }
    if (!TextUtils.isEmpty(searchText)) {
        searchCaluse += " and m1.message like '%" + searchText.replaceAll("'", "''") + "%' ";
    }
    String hiddenType = " and m1.messageContentType not in (" + Message.ContentType.HIDDEN.getValue() + "," + Message.ContentType.VIDEO_CALL_NOTIFICATION_MSG.getValue() + ") AND m1.hidden = 0 AND m1.replyMessage not in (" + Message.ReplyMessage.HIDE_MESSAGE.getValue() + ")";
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    /*final Cursor cursor = db.rawQuery("select * from sms where createdAt in " +
                "(select max(createdAt) from sms group by contactNumbers) order by createdAt desc", null);*/
    final Cursor cursor = db.rawQuery("select m1.* from sms m1 left outer join sms m2 on (m1.createdAt < m2.createdAt" + " and m1.channelKey = m2.channelKey and m1.contactNumbers = m2.contactNumbers and m1.deleted = m2.deleted and  m1.messageContentType = m2.messageContentType" + messageTypeJoinClause + " ) where m2.createdAt is null " + createdAtClause + searchCaluse + hiddenType + messageTypeClause + " order by m1.createdAt desc", null);
    /*final Cursor cursor = db.rawQuery("SELECT t1.* FROM sms t1" +
                "  JOIN (SELECT contactNumbers, MAX(createdAt) createdAt FROM sms GROUP BY contactNumbers) t2" +
                "  ON t1.contactNumbers = t2.contactNumbers AND t1.createdAt = t2.createdAt order by createdAt desc", null);*/
    List<Message> messageList = getLatestMessageList(cursor);
    dbHelper.close();
    return messageList;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Cursor(android.database.Cursor)

Example 9 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class RegisterUserClientService method updatePushNotificationId.

public RegistrationResponse updatePushNotificationId(final String pushNotificationId) throws Exception {
    MobiComUserPreference pref = MobiComUserPreference.getInstance(context);
    // Note: In case if gcm registration is done before login then only updating in pref
    RegistrationResponse registrationResponse = null;
    User user = getUserDetail();
    if (!TextUtils.isEmpty(pushNotificationId)) {
        pref.setDeviceRegistrationId(pushNotificationId);
    }
    user.setRegistrationId(pushNotificationId);
    if (pref.isRegistered()) {
        registrationResponse = updateRegisteredAccount(user);
    }
    return registrationResponse;
}
Also used : User(com.applozic.mobicomkit.api.account.user.User) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference)

Example 10 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class RegisterUserClientService method getUserDetail.

private User getUserDetail() {
    MobiComUserPreference pref = MobiComUserPreference.getInstance(context);
    User user = new User();
    user.setEmail(pref.getEmailIdValue());
    user.setUserId(pref.getUserId());
    user.setContactNumber(pref.getContactNumber());
    user.setDisplayName(pref.getDisplayName());
    user.setImageLink(pref.getImageLink());
    user.setRoleType(pref.getUserRoleType());
    return user;
}
Also used : User(com.applozic.mobicomkit.api.account.user.User) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference)

Aggregations

MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)33 Message (com.applozic.mobicomkit.api.conversation.Message)8 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 Gson (com.google.gson.Gson)5 Contact (com.applozic.mobicommons.people.contact.Contact)4 PersonalizedMessage (com.applozic.mobicommons.personalization.PersonalizedMessage)4 User (com.applozic.mobicomkit.api.account.user.User)3 Channel (com.applozic.mobicommons.people.channel.Channel)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 NonNull (android.support.annotation.NonNull)2 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)2 InvalidApplicationException (com.applozic.mobicomkit.exception.InvalidApplicationException)2 UnAuthoriseException (com.applozic.mobicomkit.exception.UnAuthoriseException)2 MessageResponse (com.applozic.mobicomkit.feed.MessageResponse)2 SyncMessageFeed (com.applozic.mobicomkit.sync.SyncMessageFeed)2 JsonParser (com.google.gson.JsonParser)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2