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();
}
}
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()));
}
}
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;
}
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;
}
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;
}
Aggregations