use of com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method onItemClick.
@Override
public boolean onItemClick(int position, MenuItem item) {
if (messageList.size() <= position) {
return true;
}
Message message = messageList.get(position);
if (message.isTempDateType() || message.isCustom()) {
return true;
}
switch(item.getItemId()) {
case 0:
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(message.getMessage());
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText(getContext().getString(R.string.copied_message), message.getMessage());
clipboard.setPrimaryClip(clip);
}
break;
case 1:
conversationUIService.startContactActivityForResult(message, null);
break;
case 2:
Message messageToResend = new Message(message);
// messageToResend.setCreatedAtTime(new Date().getTime());
messageToResend.setCreatedAtTime(System.currentTimeMillis() + MobiComUserPreference.getInstance(getActivity()).getDeviceTimeOffset());
conversationService.sendMessage(messageToResend, messageIntentClass);
break;
case 3:
String messageKeyString = message.getKeyString();
new DeleteConversationAsyncTask(conversationService, message, contact).execute();
deleteMessageFromDeviceList(messageKeyString);
break;
case 4:
String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
conversationUIService.startMessageInfoFragment(messageJson);
break;
case 5:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (message.getFilePaths() != null) {
Uri shareUri = null;
if (Utils.hasNougat()) {
shareUri = FileProvider.getUriForFile(getActivity(), Utils.getMetaDataValue(getActivity(), MobiComKitConstants.PACKAGE_NAME) + ".provider", new File(message.getFilePaths().get(0)));
} else {
shareUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
}
shareIntent.setDataAndType(shareUri, "text/x-vcard");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri);
if (!TextUtils.isEmpty(message.getMessage())) {
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
}
shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0))));
} else {
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
shareIntent.setType("text/plain");
}
startActivity(Intent.createChooser(shareIntent, getString(R.string.send_message_to)));
break;
case 6:
try {
Configuration config = getActivity().getResources().getConfiguration();
messageMetaData = new HashMap<>();
String displayName;
if (message.getGroupId() != null) {
if (MobiComUserPreference.getInstance(getActivity()).getUserId().equals(message.getContactIds()) || TextUtils.isEmpty(message.getContactIds())) {
displayName = getString(R.string.you_string);
} else {
displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
}
} else {
if (message.isTypeOutbox()) {
displayName = getString(R.string.you_string);
} else {
displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
}
}
nameTextView.setText(displayName);
if (message.hasAttachment()) {
FileMeta fileMeta = message.getFileMetas();
imageViewForAttachmentType.setVisibility(VISIBLE);
if (fileMeta.getContentType().contains("image")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_image_camera_alt);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.photo_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
imageThumbnailLoader.loadImage(message, galleryImageView);
} else if (fileMeta.getContentType().contains("video")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_video);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
imageViewForAttachmentType.setScaleX(-1);
}
}
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.video_string));
} else {
messageTextView.setText(message.getMessage());
}
if (message.getFilePaths() != null && message.getFilePaths().size() > 0) {
if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) {
galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
} else {
imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
galleryImageView.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
}
}
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
} else if (fileMeta.getContentType().contains("audio")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_music_note);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.audio_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
} else if (message.isContactMessage()) {
MobiComVCFParser parser = new MobiComVCFParser();
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
try {
VCFContactData data = parser.parseCVFContactData(message.getFilePaths().get(0));
if (data != null) {
messageTextView.setText(getString(R.string.contact_string));
messageTextView.append(" " + data.getName());
}
} catch (Exception e) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
messageTextView.setText(getString(R.string.contact_string));
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
} else {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_attachment);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.attachment_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
}
imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), R.color.apploizc_lite_gray_color));
} else if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
imageViewForAttachmentType.setVisibility(VISIBLE);
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
messageTextView.setText(getString(R.string.al_location_string));
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), R.color.apploizc_lite_gray_color));
messageImageLoader.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
messageImageLoader.loadImage(LocationUtils.loadStaticMap(message.getMessage()), galleryImageView);
} else {
imageViewForAttachmentType.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
galleryImageView.setVisibility(View.GONE);
messageTextView.setText(message.getMessage());
}
messageMetaData.put(Message.MetaDataType.AL_REPLY.getValue(), message.getKeyString());
if (messageMetaData != null && !messageMetaData.isEmpty()) {
String replyMessageKey = messageMetaData.get(Message.MetaDataType.AL_REPLY.getValue());
if (!TextUtils.isEmpty(replyMessageKey)) {
messageDatabaseService.updateMessageReplyType(replyMessageKey, Message.ReplyMessage.REPLY_MESSAGE.getValue());
}
}
attachReplyCancelLayout.setVisibility(VISIBLE);
replayRelativeLayout.setVisibility(VISIBLE);
} catch (Exception e) {
}
break;
}
return true;
}
use of com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
int position = positionInSmsList;
if (messageList.size() <= position) {
return true;
}
Message message = messageList.get(position);
if (message.isTempDateType() || message.isCustom()) {
return true;
}
switch(item.getItemId()) {
case 0:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(message.getMessage());
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText(getContext().getString(R.string.copied_message), message.getMessage());
clipboard.setPrimaryClip(clip);
}
break;
case 1:
conversationUIService.startContactActivityForResult(message, null);
break;
case 2:
Message messageToResend = new Message(message);
// messageToResend.setCreatedAtTime(new Date().getTime());
messageToResend.setCreatedAtTime(System.currentTimeMillis() + MobiComUserPreference.getInstance(getActivity()).getDeviceTimeOffset());
conversationService.sendMessage(messageToResend, messageIntentClass);
break;
case 3:
String messageKeyString = message.getKeyString();
new DeleteConversationAsyncTask(conversationService, message, contact).execute();
deleteMessageFromDeviceList(messageKeyString);
break;
case 4:
String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
conversationUIService.startMessageInfoFragment(messageJson);
break;
case 5:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (message.getFilePaths() != null) {
Uri shareUri = null;
if (Utils.hasNougat()) {
shareUri = FileProvider.getUriForFile(getActivity(), Utils.getMetaDataValue(getActivity(), MobiComKitConstants.PACKAGE_NAME) + ".provider", new File(message.getFilePaths().get(0)));
} else {
shareUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
}
shareIntent.setDataAndType(shareUri, "text/x-vcard");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri);
if (!TextUtils.isEmpty(message.getMessage())) {
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
}
shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0))));
} else {
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
shareIntent.setType("text/plain");
}
startActivity(Intent.createChooser(shareIntent, getString(R.string.send_message_to)));
break;
case 6:
try {
Configuration config = getActivity().getResources().getConfiguration();
messageMetaData = new HashMap<>();
String displayName;
if (message.getGroupId() != null) {
if (MobiComUserPreference.getInstance(getActivity()).getUserId().equals(message.getContactIds()) || TextUtils.isEmpty(message.getContactIds())) {
displayName = getString(R.string.you_string);
} else {
displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
}
} else {
if (message.isTypeOutbox()) {
displayName = getString(R.string.you_string);
} else {
displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
}
}
nameTextView.setText(displayName);
if (message.hasAttachment()) {
FileMeta fileMeta = message.getFileMetas();
imageViewForAttachmentType.setVisibility(VISIBLE);
if (fileMeta.getContentType().contains("image")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_image_camera_alt);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.photo_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
imageThumbnailLoader.loadImage(message, galleryImageView);
} else if (fileMeta.getContentType().contains("video")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_video);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
imageViewForAttachmentType.setScaleX(-1);
}
}
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.video_string));
} else {
messageTextView.setText(message.getMessage());
}
if (message.getFilePaths() != null && message.getFilePaths().size() > 0) {
if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) {
galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
} else {
imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
galleryImageView.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
}
}
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
} else if (fileMeta.getContentType().contains("audio")) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_music_note);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.audio_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
} else if (message.isContactMessage()) {
MobiComVCFParser parser = new MobiComVCFParser();
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
try {
VCFContactData data = parser.parseCVFContactData(message.getFilePaths().get(0));
if (data != null) {
messageTextView.setText(getString(R.string.contact_string));
messageTextView.append(" " + data.getName());
}
} catch (Exception e) {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
messageTextView.setText(getString(R.string.contact_string));
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
} else {
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_attachment);
if (TextUtils.isEmpty(message.getMessage())) {
messageTextView.setText(getString(R.string.attachment_string));
} else {
messageTextView.setText(message.getMessage());
}
galleryImageView.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
}
imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), R.color.apploizc_lite_gray_color));
} else if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
imageViewForAttachmentType.setVisibility(VISIBLE);
galleryImageView.setVisibility(VISIBLE);
imageViewRLayout.setVisibility(VISIBLE);
messageTextView.setText(getString(R.string.al_location_string));
imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), R.color.apploizc_lite_gray_color));
messageImageLoader.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
messageImageLoader.loadImage(LocationUtils.loadStaticMap(message.getMessage()), galleryImageView);
} else {
imageViewForAttachmentType.setVisibility(View.GONE);
imageViewRLayout.setVisibility(View.GONE);
galleryImageView.setVisibility(View.GONE);
messageTextView.setText(message.getMessage());
}
messageMetaData.put(Message.MetaDataType.AL_REPLY.getValue(), message.getKeyString());
if (messageMetaData != null && !messageMetaData.isEmpty()) {
String replyMessageKey = messageMetaData.get(Message.MetaDataType.AL_REPLY.getValue());
if (!TextUtils.isEmpty(replyMessageKey)) {
messageDatabaseService.updateMessageReplyType(replyMessageKey, Message.ReplyMessage.REPLY_MESSAGE.getValue());
}
}
attachReplyCancelLayout.setVisibility(VISIBLE);
replayRelativeLayout.setVisibility(VISIBLE);
} catch (Exception e) {
}
break;
}
return true;
}
use of com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method deleteConversationThread.
public void deleteConversationThread() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.delete_conversation, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new DeleteConversationAsyncTask(new MobiComConversationService(getActivity()), contact, channel, currentConversationId, getActivity()).execute();
}
});
alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
alertDialog.setTitle(getActivity().getString(R.string.dialog_delete_conversation_title).replace("[name]", getNameForInviteDialog()));
alertDialog.setMessage(getActivity().getString(R.string.dialog_delete_conversation_confir).replace("[name]", getNameForInviteDialog()));
alertDialog.setCancelable(true);
alertDialog.create().show();
}
Aggregations