use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class UserProfileFragment method refreshContactData.
public void refreshContactData() {
if (contact != null) {
Contact updateContact = baseContactService.getContactById(contact.getContactIds());
if (updateContact != null && (!TextUtils.isEmpty(contact.getImageURL())) && (!contact.getImageURL().equals(updateContact.getImageURL()))) {
contactImageLoader.loadImage(updateContact, contactImage);
}
if (!TextUtils.isEmpty(updateContact.getStatus())) {
status_cardView.setVisibility(View.VISIBLE);
status.setText(updateContact.getStatus());
}
if (!TextUtils.isEmpty(updateContact.getContactNumber())) {
phone_cardView.setVisibility(View.VISIBLE);
phone.setText(updateContact.getContactNumber());
}
if (updateContact != null && (!TextUtils.isEmpty(contact.getDisplayName())) && (!contact.getDisplayName().equals(updateContact.getDisplayName()))) {
name_cardView.setVisibility(View.VISIBLE);
name.setText(updateContact.getDisplayName());
reload();
}
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class UserProfileFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
baseContactService = new AppContactService(getActivity());
final Context context = getActivity().getApplicationContext();
contactImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) getContext())) {
@Override
protected Bitmap processBitmap(Object data) {
return baseContactService.downloadContactImage(context, (Contact) data);
}
};
contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_180_holo_light);
contactImageLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
contactImageLoader.setImageFadeIn(false);
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class AlUIService method deleteConversationThread.
/**
* This method deletes the conversation with a contact or channel.
*
* @param contact The contact object whose conversation thread is to be deleted
* @param channel The group object whose conversation thread is to be deleted
*/
public void deleteConversationThread(final Contact contact, final Channel channel) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context).setPositiveButton(R.string.delete_conversation, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlTask.execute(new DeleteConversationAsyncTask(new MobiComConversationService(context), contact, channel, null, context));
}
});
alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
String name = "";
if (channel != null) {
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
Contact withUserContact = contactService.getContactById(userId);
name = withUserContact.getDisplayName();
}
} else {
name = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId());
}
} else {
name = contact.getDisplayName();
}
alertDialog.setTitle(context.getString(R.string.dialog_delete_conversation_title).replace("[name]", name));
alertDialog.setMessage(context.getString(R.string.dialog_delete_conversation_confir).replace("[name]", name));
alertDialog.setCancelable(true);
alertDialog.create().show();
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageClientService method processMessage.
// Cleanup: private
public void processMessage(Message message, Handler handler, String userDisplayName) throws Exception {
boolean isBroadcast = (message.getMessageId() == null);
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
message.setSent(Boolean.TRUE);
message.setSendToDevice(Boolean.FALSE);
message.setSuUserKeyString(userPreferences.getSuUserKeyString());
message.processContactIds(context);
Contact contact = null;
Channel channel = null;
boolean isBroadcastOneByOneGroupType = false;
boolean isOpenGroup = false;
boolean skipMessage = false;
if (message.getGroupId() == null) {
contact = baseContactService.getContactById(message.getContactIds());
} else {
channel = ChannelService.getInstance(context).getChannel(message.getGroupId());
isOpenGroup = (Channel.GroupType.OPEN.getValue().equals(channel.getType()) && !message.hasAttachment());
isBroadcastOneByOneGroupType = Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType());
}
long messageId = -1;
List<String> fileKeys = new ArrayList<String>();
String keyString = null;
String oldMessageKey = null;
if (!isBroadcastOneByOneGroupType) {
keyString = UUID.randomUUID().toString();
oldMessageKey = keyString;
message.setKeyString(keyString);
message.setSentToServer(false);
} else {
message.setSentToServer(true);
}
if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
skipMessage = true;
}
if (!skipMessage && !isOpenGroup) {
messageId = messageDatabaseService.createMessage(message);
}
if (isBroadcast && !skipMessage) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
}
if (!isBroadcastOneByOneGroupType && message.isUploadRequired()) {
for (String filePath : message.getFilePaths()) {
FileMeta thumbnailFileMeta = null;
String mimeType = FileUtils.getMimeType(filePath);
if (mimeType != null && mimeType.startsWith("video")) {
thumbnailFileMeta = uploadVideoThumbnail(filePath, message.getCreatedAtTime(), oldMessageKey);
}
try {
String fileMetaResponse = new FileClientService(context).uploadBlobImage(filePath, handler, oldMessageKey);
if (fileMetaResponse == null) {
if (skipMessage) {
return;
}
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error while uploading");
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.sendToTarget();
}
if (!message.isContactMessage()) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
}
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
return;
}
if (ApplozicClient.getInstance(context).isS3StorageServiceEnabled()) {
if (!TextUtils.isEmpty(fileMetaResponse)) {
message.setFileMetas((FileMeta) GsonUtils.getObjectFromJson(fileMetaResponse, FileMeta.class));
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.getData().putString("error", null);
msg.sendToTarget();
}
}
} else {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(fileMetaResponse).getAsJsonObject();
if (jsonObject.has(FILE_META)) {
Gson gson = new Gson();
message.setFileMetas(gson.fromJson(jsonObject.get(FILE_META), FileMeta.class));
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.getData().putString("error", null);
msg.sendToTarget();
}
}
}
// update message file-meta with thumbnail data
if (thumbnailFileMeta != null) {
FileMeta messageFileMeta = message.getFileMetas();
if (!TextUtils.isEmpty(thumbnailFileMeta.getBlobKeyString())) {
messageFileMeta.setThumbnailBlobKey(thumbnailFileMeta.getBlobKeyString());
}
if (!TextUtils.isEmpty(thumbnailFileMeta.getThumbnailUrl())) {
messageFileMeta.setThumbnailUrl(thumbnailFileMeta.getThumbnailUrl());
}
message.setFileMetas(messageFileMeta);
}
} catch (Exception ex) {
Utils.printLog(context, TAG, "Error uploading file to server: " + filePath);
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.getData().putString("error", "Error uploading file to server: " + filePath);
msg.sendToTarget();
}
/* recentMessageSentToServer.remove(message);*/
if (!message.isContactMessage() && !skipMessage) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
}
if (!skipMessage) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
}
return;
}
}
if (messageId != -1 && !skipMessage) {
messageDatabaseService.updateMessageFileMetas(messageId, message);
}
}
Message newMessage = new Message();
newMessage.setTo(message.getTo());
newMessage.setKeyString(message.getKeyString());
newMessage.setMessage(message.getMessage());
newMessage.setFileMetas(message.getFileMetas());
newMessage.setCreatedAtTime(message.getCreatedAtTime());
newMessage.setRead(Boolean.TRUE);
newMessage.setDeviceKeyString(message.getDeviceKeyString());
newMessage.setSuUserKeyString(message.getSuUserKeyString());
newMessage.setSent(message.isSent());
newMessage.setType(message.getType());
newMessage.setTimeToLive(message.getTimeToLive());
newMessage.setSource(message.getSource());
newMessage.setScheduledAt(message.getScheduledAt());
newMessage.setStoreOnDevice(message.isStoreOnDevice());
newMessage.setDelivered(message.getDelivered());
newMessage.setStatus(message.getStatus());
newMessage.setMetadata(message.getMetadata());
newMessage.setSendToDevice(message.isSendToDevice());
newMessage.setContentType(message.getContentType());
newMessage.setConversationId(message.getConversationId());
if (message.getGroupId() != null) {
newMessage.setGroupId(message.getGroupId());
}
if (!TextUtils.isEmpty(message.getClientGroupId())) {
newMessage.setClientGroupId(message.getClientGroupId());
}
if (contact != null && !TextUtils.isEmpty(contact.getApplicationId())) {
newMessage.setApplicationId(contact.getApplicationId());
} else {
newMessage.setApplicationId(getApplicationKey(context));
}
try {
if (!isBroadcastOneByOneGroupType) {
String response = sendMessage(newMessage);
if (message.hasAttachment() && TextUtils.isEmpty(response) && !message.isContactMessage() && !skipMessage && !isOpenGroup) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error uploading file to server");
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.sendToTarget();
}
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
}
MessageResponse messageResponse = (MessageResponse) GsonUtils.getObjectFromJson(response, MessageResponse.class);
keyString = messageResponse.getMessageKey();
if (!TextUtils.isEmpty(keyString)) {
message.setSentMessageTimeAtServer(Long.parseLong(messageResponse.getCreatedAtTime()));
message.setConversationId(messageResponse.getConversationId());
message.setSentToServer(true);
message.setKeyString(keyString);
if (contact != null && !TextUtils.isEmpty(userDisplayName) && contact.isUserDisplayUpdateRequired()) {
UserService.getInstance(context).updateUserDisplayName(message.getTo(), userDisplayName);
}
}
if (!skipMessage && !isOpenGroup) {
messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
}
} else {
message.setSentMessageTimeAtServer(message.getCreatedAtTime());
messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
}
if (message.isSentToServer()) {
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.MESSAGE_SENT;
msg.getData().putString(MobiComKitConstants.MESSAGE_INTENT_EXTRA, message.getKeyString());
String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
msg.getData().putString(MobiComKitConstants.MESSAGE_JSON_INTENT_EXTRA, messageJson);
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.sendToTarget();
}
}
if (!TextUtils.isEmpty(keyString)) {
// Todo: Handle server message add failure due to internet disconnect.
} else {
// Todo: If message type is mtext, tell user that internet is not working, else send update with db id.
}
if (!skipMessage || isOpenGroup) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString(), message);
}
} catch (Exception e) {
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
msg.getData().putString("error", "Error uploading file");
msg.sendToTarget();
// handler.onCompleted(new ApplozicException("Error uploading file"));
}
}
/* if (recentMessageSentToServer.size() > 20) {
recentMessageSentToServer.subList(0, 10).clear();
}*/
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageServiceTest method testDeleteMessage.
@Test
public void testDeleteMessage() {
try {
Message message = (Message) GsonUtils.getObjectFromJson(MockConstants.Message, Message.class);
Mockito.when(messageDatabaseService.deleteMessage(any(Message.class), anyString())).thenReturn("checkMe");
Mockito.when(messageClientService.deleteMessage(any(Message.class), nullable(Contact.class))).thenReturn("success");
mobiComConversationService.deleteMessage(message, new Contact());
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteMessage(any(Message.class), nullable(String.class));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations