use of com.applozic.mobicomkit.api.conversation.MessageBuilder in project Applozic-Android-SDK by AppLozic.
the class AlAttachmentOptions method handleAttachmentOptionsResult.
public static void handleAttachmentOptionsResult(int requestCode, int resultCode, Intent intent, Activity activity, String userId, Integer groupId) {
try {
MessageBuilder messageBuilder = new MessageBuilder(activity);
if (groupId == null && userId != null) {
messageBuilder.setTo(userId);
} else if (userId == null && groupId != null) {
messageBuilder.setGroupId(groupId);
}
if ((requestCode == REQUEST_CODE_ATTACH_PHOTO || requestCode == REQUEST_CODE_TAKE_PHOTO) && resultCode == Activity.RESULT_OK) {
Uri selectedFileUri = (intent == null ? null : intent.getData());
if (selectedFileUri == null) {
selectedFileUri = bundle.getParcelable("imageUri");
String selectedFilePath = bundle.getString("imagePath");
if (selectedFilePath != null) {
messageBuilder.setFilePath(bundle.getString("imagePath")).setContentType(Message.ContentType.ATTACHMENT.getValue()).send();
bundle = null;
}
}
String absoluteFilePath = getFilePath(selectedFileUri, activity);
MediaScannerConnection.scanFile(activity, new String[] { absoluteFilePath }, null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
}
});
}
if (requestCode == REQUEST_CODE_CONTACT_GROUP_SELECTION && resultCode == Activity.RESULT_OK) {
// checkForStartNewConversation(intent);
}
if (requestCode == REQUEST_CODE_CAPTURE_VIDEO_ACTIVITY && resultCode == Activity.RESULT_OK) {
String selectedFilePath = bundle.getString("videoPath");
if (selectedFilePath != null) {
messageBuilder.setFilePath(bundle.getString("videoPath")).setContentType(Message.ContentType.VIDEO_MSG.getValue()).send();
bundle = null;
}
}
if (requestCode == REQUEST_MULTI_ATTCAHMENT && resultCode == Activity.RESULT_OK) {
ArrayList<Uri> attachmentList = intent.getParcelableArrayListExtra(MULTISELECT_SELECTED_FILES);
String messageText = intent.getStringExtra(MULTISELECT_MESSAGE);
for (Uri info : attachmentList) {
messageBuilder.setFilePath(info.toString()).setMessage(messageText).setContentType(Message.ContentType.ATTACHMENT.getValue()).send();
}
}
if (requestCode == MultimediaOptionFragment.REQUEST_CODE_SEND_LOCATION && resultCode == Activity.RESULT_OK) {
Double latitude = intent.getDoubleExtra("latitude", 0);
Double longitude = intent.getDoubleExtra("longitude", 0);
// TODO: put your location(lat/lon ) in constructor.
LocationInfo info = new LocationInfo(latitude, longitude);
String locationInfo = GsonUtils.getJsonFromObject(info, LocationInfo.class);
messageBuilder.setMessage(locationInfo).setContentType(Message.ContentType.LOCATION.getValue()).send();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicomkit.api.conversation.MessageBuilder in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method sendOpenGroupMessage.
public void sendOpenGroupMessage(String messageText) {
attachReplyCancelLayout.setVisibility(View.GONE);
replayRelativeLayout.setVisibility(View.GONE);
attachmentLayout.setVisibility(View.GONE);
Map<String, String> messageMetaData = new HashMap<>();
if (this.messageMetaData != null && !this.messageMetaData.isEmpty()) {
messageMetaData.putAll(this.messageMetaData);
}
MessageBuilder messageBuilder = new MessageBuilder(getActivity()).setMessage(messageText).setMetadata(messageMetaData).setGroupId(channel.getKey());
if (!TextUtils.isEmpty(filePath)) {
messageBuilder.setContentType(Message.ContentType.ATTACHMENT.getValue());
messageBuilder.setFilePath(filePath);
filePath = null;
}
messageBuilder.send(new MediaUploadProgressHandler() {
@Override
public void onUploadStarted(ApplozicException e, String oldMessageKey) {
}
@Override
public void onProgressUpdate(int percentage, ApplozicException e, String oldMessageKey) {
}
@Override
public void onCancelled(ApplozicException e, String oldMessageKey) {
}
@Override
public void onCompleted(ApplozicException e, String oldMessageKey) {
}
@Override
public void onSent(Message message, String oldMessageKey) {
Message messageToBeReplied = new Message();
messageToBeReplied.setKeyString(oldMessageKey);
int indexOfObject = messageList.indexOf(messageToBeReplied);
if (indexOfObject != -1) {
messageList.set(indexOfObject, message);
recyclerDetailConversationAdapter.notifyItemChanged(indexOfObject);
}
}
});
this.messageMetaData = null;
}
Aggregations