use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method createTemplateMessages.
public void createTemplateMessages() {
if (templateAdapter == null) {
return;
}
if (!messageList.isEmpty()) {
Message lastMessage = messageList.get(messageList.size() - 1);
if (lastMessage.getMetadata().containsKey("isDoneWithClicking")) {
return;
}
if (lastMessage.getMetadata() != null && lastMessage.getMetadata().containsKey(MobiComKitConstants.TEMPLATE_MESSAGE_LIST)) {
Map<String, String> messageArray = (Map<String, String>) GsonUtils.getObjectFromJson(lastMessage.getMetadata().get(MobiComKitConstants.TEMPLATE_MESSAGE_LIST), Map.class);
templateAdapter.setMessageList(messageArray);
templateAdapter.notifyDataSetChanged();
// createMessageTemplate(Arrays.asList(messageArray));
} else {
String type = getMessageType(lastMessage);
if ("audio".equals(type)) {
if (messageTemplate.getAudioMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getAudioMessageList().isShowOnSenderSide()) || messageTemplate.getAudioMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getAudioMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
} else if ("video".equals(type)) {
if (messageTemplate.getVideoMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getVideoMessageList().isShowOnSenderSide()) || messageTemplate.getVideoMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getVideoMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
} else if ("image".equals(type)) {
if (messageTemplate.getImageMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getImageMessageList().isShowOnSenderSide()) || messageTemplate.getImageMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getImageMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
} else if (lastMessage.getContentType() == Message.ContentType.LOCATION.getValue()) {
if (messageTemplate.getLocationMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getLocationMessageList().isShowOnSenderSide()) || messageTemplate.getLocationMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getLocationMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
} else if (lastMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
if (messageTemplate.getContactMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getContactMessageList().isShowOnSenderSide()) || messageTemplate.getContactMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getContactMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
} else if ("text".equals(type)) {
if (messageTemplate.getTextMessageList() != null) {
if ((lastMessage.isTypeOutbox() && messageTemplate.getTextMessageList().isShowOnSenderSide()) || messageTemplate.getTextMessageList().isShowOnReceiverSide()) {
templateAdapter.setMessageList(messageTemplate.getTextMessageList().getMessageList());
templateAdapter.notifyDataSetChanged();
}
}
}
}
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method onCreateView.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View list = inflater.inflate(R.layout.mobicom_message_list, container, false);
recyclerView = (RecyclerView) list.findViewById(R.id.messageList);
linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setHasFixedSize(true);
recyclerViewPositionHelper = new RecyclerViewPositionHelper(recyclerView, linearLayoutManager);
((ConversationActivity) getActivity()).setChildFragmentLayoutBGToTransparent();
// listView.setDivider(null);
messageList = new ArrayList<Message>();
multimediaPopupGrid = (GridView) list.findViewById(R.id.mobicom_multimedia_options1);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
toolbar.setClickable(true);
mainEditTextLinearLayout = (LinearLayout) list.findViewById(R.id.main_edit_text_linear_layout);
individualMessageSendLayout = (LinearLayout) list.findViewById(R.id.individual_message_send_layout);
slideImageView = (ImageView) list.findViewById(R.id.slide_image_view);
sendButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.conversation_send);
recordButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.record_button);
mainEditTextLinearLayout = (LinearLayout) list.findViewById(R.id.main_edit_text_linear_layout);
audioRecordFrameLayout = (FrameLayout) list.findViewById(R.id.audio_record_frame_layout);
messageTemplateView = (RecyclerView) list.findViewById(R.id.mobicomMessageTemplateView);
Configuration config = getResources().getConfiguration();
recordButtonWeakReference = new WeakReference<ImageButton>(recordButton);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
sendButton.setScaleX(-1);
mainEditTextLinearLayout.setBackgroundResource(R.drawable.applozic_chat_left_icon);
audioRecordFrameLayout.setBackgroundResource(R.drawable.applozic_chat_left_icon);
slideImageView.setImageResource(R.drawable.slide_arrow_right);
}
}
extendedSendingOptionLayout = (LinearLayout) list.findViewById(R.id.extended_sending_option_layout);
attachmentLayout = (RelativeLayout) list.findViewById(R.id.attachment_layout);
isTyping = (TextView) list.findViewById(R.id.isTyping);
contextFrameLayout = (FrameLayout) list.findViewById(R.id.contextFrameLayout);
contextSpinner = (Spinner) list.findViewById(R.id.spinner_show);
slideTextLinearlayout = (LinearLayout) list.findViewById(R.id.slide_LinearLayout);
errorEditTextView = (EditText) list.findViewById(R.id.error_edit_text_view);
audioRecordIconImageView = (ImageView) list.findViewById(R.id.audio_record_icon_image_view);
recordTimeTextView = (TextView) list.findViewById(R.id.recording_time_text_view);
mDetector = new GestureDetectorCompat(getContext(), this);
adapterView = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
if (conversations != null && conversations.size() > 0) {
Conversation conversation = conversations.get(pos);
BroadcastService.currentConversationId = conversation.getId();
if (onSelected) {
currentConversationId = conversation.getId();
if (messageList != null) {
messageList.clear();
}
downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversation.getId());
downloadConversation.execute();
}
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
mediaUploadProgressBar = (ProgressBar) attachmentLayout.findViewById(R.id.media_upload_progress_bar);
emoticonsFrameLayout = (FrameLayout) list.findViewById(R.id.emojicons_frame_layout);
emoticonsBtn = (ImageButton) list.findViewById(R.id.emoticons_btn);
if (emojiIconHandler == null && emoticonsBtn != null) {
emoticonsBtn.setVisibility(View.GONE);
}
replayRelativeLayout = (RelativeLayout) list.findViewById(R.id.reply_message_layout);
messageTextView = (TextView) list.findViewById(R.id.messageTextView);
galleryImageView = (ImageView) list.findViewById(R.id.imageViewForPhoto);
nameTextView = (TextView) list.findViewById(R.id.replyNameTextView);
attachReplyCancelLayout = (ImageButton) list.findViewById(R.id.imageCancel);
imageViewRLayout = (RelativeLayout) list.findViewById(R.id.imageViewRLayout);
imageViewForAttachmentType = (ImageView) list.findViewById(R.id.imageViewForAttachmentType);
spinnerLayout = inflater.inflate(R.layout.mobicom_message_list_header_footer, null);
infoBroadcast = (TextView) spinnerLayout.findViewById(R.id.info_broadcast);
spinnerLayout.setVisibility(View.GONE);
emptyTextView = (TextView) list.findViewById(R.id.noConversations);
emptyTextView.setTextColor(Color.parseColor(alCustomizationSettings.getNoConversationLabelTextColor().trim()));
emoticonsBtn.setOnClickListener(this);
// listView.addHeaderView(spinnerLayout);
sentIcon = getResources().getDrawable(R.drawable.applozic_ic_action_message_sent);
deliveredIcon = getResources().getDrawable(R.drawable.applozic_ic_action_message_delivered);
// listView.setLongClickable(true);
recordButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) ? View.VISIBLE : View.GONE);
sendButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) ? View.GONE : View.VISIBLE);
GradientDrawable bgShape = (GradientDrawable) sendButton.getBackground();
bgShape.setColor(Color.parseColor(alCustomizationSettings.getSendButtonBackgroundColor().trim()));
GradientDrawable bgShapeRecordButton = (GradientDrawable) recordButton.getBackground();
bgShapeRecordButton.setColor(Color.parseColor(alCustomizationSettings.getSendButtonBackgroundColor().trim()));
attachButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.attach_button);
sendType = (Spinner) extendedSendingOptionLayout.findViewById(R.id.sendTypeSpinner);
messageEditText = (EditText) individualMessageSendLayout.findViewById(R.id.conversation_message);
messageEditText.setTextColor(Color.parseColor(alCustomizationSettings.getMessageEditTextTextColor()));
messageEditText.setHintTextColor(Color.parseColor(alCustomizationSettings.getMessageEditTextHintTextColor()));
userNotAbleToChatLayout = (LinearLayout) list.findViewById(R.id.user_not_able_to_chat_layout);
userNotAbleToChatTextView = (TextView) userNotAbleToChatLayout.findViewById(R.id.user_not_able_to_chat_textView);
userNotAbleToChatTextView.setTextColor(Color.parseColor(alCustomizationSettings.getUserNotAbleToChatTextColor()));
if (channel != null && channel.isDeleted()) {
userNotAbleToChatTextView.setText(R.string.group_has_been_deleted_text);
}
bottomlayoutTextView = (TextView) list.findViewById(R.id.user_not_able_to_chat_textView);
if (!TextUtils.isEmpty(defaultText)) {
messageEditText.setText(defaultText);
defaultText = "";
}
scheduleOption = (Button) extendedSendingOptionLayout.findViewById(R.id.scheduleOption);
mediaContainer = (ImageView) attachmentLayout.findViewById(R.id.media_container);
attachedFile = (TextView) attachmentLayout.findViewById(R.id.attached_file);
ImageView closeAttachmentLayout = (ImageView) attachmentLayout.findViewById(R.id.close_attachment_layout);
swipeLayout = (SwipeRefreshLayout) list.findViewById(R.id.swipe_container);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
// listView.setMessageEditText(messageEditText);
ArrayAdapter<CharSequence> sendTypeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.send_type_options, R.layout.mobiframework_custom_spinner);
sendTypeAdapter.setDropDownViewResource(R.layout.mobiframework_custom_spinner);
sendType.setAdapter(sendTypeAdapter);
t = new CountDownTimer(Long.MAX_VALUE, 1000) {
@Override
public void onTick(long millisUntilFinished) {
count++;
seconds = count;
if (seconds == 60) {
minutes++;
count = 0;
seconds = 0;
}
if (minutes == 60) {
minutes = 0;
count = 0;
}
if (count % 2 == 0) {
audioRecordIconImageView.setVisibility(VISIBLE);
audioRecordIconImageView.setImageResource(R.drawable.applozic_audio_record);
} else {
audioRecordIconImageView.setVisibility(View.INVISIBLE);
}
recordTimeTextView.setText(String.format("%02d:%02d", minutes, seconds));
}
@Override
public void onFinish() {
count = 0;
}
};
recordButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mDetector.onTouchEvent(motionEvent);
if (motionEvent.getAction() == MotionEvent.ACTION_UP && longPress) {
isToastVisible = true;
errorEditTextView.setVisibility(View.GONE);
errorEditTextView.requestFocus();
errorEditTextView.setError(null);
startedDraggingX = -1;
audioRecordFrameLayout.setVisibility(View.GONE);
mainEditTextLinearLayout.setVisibility(View.VISIBLE);
applozicAudioRecordManager.sendAudio();
t.cancel();
longPress = false;
messageEditText.requestFocus();
seconds = 0;
minutes = 0;
count = 0;
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
float x = motionEvent.getX();
if (x < -distCanMove) {
count = 0;
t.cancel();
audioRecordIconImageView.setImageResource(R.drawable.applozic_audio_delete);
recordTimeTextView.setVisibility(View.GONE);
applozicAudioRecordManager.cancelAudio();
messageEditText.requestFocus();
}
x = x + ApplozicAudioRecordAnimation.getX(recordButton);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideTextLinearlayout.getLayoutParams();
if (startedDraggingX != -1) {
float dist = (x - startedDraggingX);
params.leftMargin = dp(30) + (int) dist;
slideTextLinearlayout.setLayoutParams(params);
float alpha = 1.0f + dist / distCanMove;
if (alpha > 1) {
alpha = 1;
} else if (alpha < 0) {
alpha = 0;
}
ApplozicAudioRecordAnimation.setAlpha(slideTextLinearlayout, alpha);
}
if (x <= ApplozicAudioRecordAnimation.getX(slideTextLinearlayout) + slideTextLinearlayout.getWidth() + dp(30)) {
if (startedDraggingX == -1) {
startedDraggingX = x;
distCanMove = (audioRecordFrameLayout.getMeasuredWidth() - slideTextLinearlayout.getMeasuredWidth() - dp(48)) / 2.0f;
if (distCanMove <= 0) {
distCanMove = dp(80);
} else if (distCanMove > dp(80)) {
distCanMove = dp(80);
}
}
}
if (params.leftMargin > dp(30)) {
params.leftMargin = dp(30);
slideTextLinearlayout.setLayoutParams(params);
ApplozicAudioRecordAnimation.setAlpha(slideTextLinearlayout, 1);
startedDraggingX = -1;
}
}
view.onTouchEvent(motionEvent);
return true;
}
});
scheduleOption.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ConversationScheduler conversationScheduler = new ConversationScheduler();
conversationScheduler.setScheduleOption(scheduleOption);
conversationScheduler.setScheduledTimeHolder(scheduledTimeHolder);
conversationScheduler.setCancelable(false);
conversationScheduler.show(getActivity().getSupportFragmentManager(), "conversationScheduler");
}
});
messageEditText.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// EmojiconHandler.addEmojis(getActivity(), messageEditText.getText(), Utils.dpToPx(30));
// TODO: write code to emoticons .....
}
public void afterTextChanged(Editable s) {
try {
if (!TextUtils.isEmpty(s.toString()) && s.toString().trim().length() > 0 && !typingStarted) {
// Log.i(TAG, "typing started event...");
typingStarted = true;
handleSendAndRecordButtonView(true);
if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) {
Intent intent = new Intent(getActivity(), ApplozicMqttIntentService.class);
intent.putExtra(ApplozicMqttIntentService.CHANNEL, channel);
intent.putExtra(ApplozicMqttIntentService.CONTACT, contact);
intent.putExtra(ApplozicMqttIntentService.TYPING, typingStarted);
ApplozicMqttIntentService.enqueueWork(getActivity(), intent);
}
} else if (s.toString().trim().length() == 0 && typingStarted) {
// Log.i(TAG, "typing stopped event...");
typingStarted = false;
handleSendAndRecordButtonView(false);
if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) {
Intent intent = new Intent(getActivity(), ApplozicMqttIntentService.class);
intent.putExtra(ApplozicMqttIntentService.CHANNEL, channel);
intent.putExtra(ApplozicMqttIntentService.CONTACT, contact);
intent.putExtra(ApplozicMqttIntentService.TYPING, typingStarted);
ApplozicMqttIntentService.enqueueWork(getActivity(), intent);
}
}
} catch (Exception e) {
}
// sendButton.setVisibility((s == null || s.toString().trim().length() == 0) && TextUtils.isEmpty(filePath) ? View.GONE : View.VISIBLE);
// attachButton.setVisibility(s == null || s.toString().trim().length() == 0 ? View.VISIBLE : View.GONE);
}
});
messageEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
emoticonsFrameLayout.setVisibility(View.GONE);
}
});
if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
attachButton.setVisibility(View.GONE);
messageEditText.setPadding(20, 0, 0, 0);
}
attachReplyCancelLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
messageMetaData = null;
replayRelativeLayout.setVisibility(View.GONE);
}
});
messageEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (typingStarted) {
if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) {
Intent intent = new Intent(getActivity(), ApplozicMqttIntentService.class);
intent.putExtra(ApplozicMqttIntentService.CHANNEL, channel);
intent.putExtra(ApplozicMqttIntentService.CONTACT, contact);
intent.putExtra(ApplozicMqttIntentService.TYPING, typingStarted);
ApplozicMqttIntentService.enqueueWork(getActivity(), intent);
}
}
emoticonsFrameLayout.setVisibility(View.GONE);
multimediaPopupGrid.setVisibility(View.GONE);
}
}
});
messageEditText.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
Utils.toggleSoftKeyBoard(getActivity(), true);
return true;
}
return false;
}
});
recordButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isToastVisible && !typingStarted) {
vibrate();
errorEditTextView.requestFocus();
errorEditTextView.setError(getResources().getString(R.string.hold_to_record_release_to_send));
isToastVisible = true;
new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
errorEditTextView.setError(null);
messageEditText.requestFocus();
isToastVisible = false;
}
}.start();
} else {
errorEditTextView.setError(null);
isToastVisible = false;
}
emoticonsFrameLayout.setVisibility(View.GONE);
sendMessage();
handleSendAndRecordButtonView(false);
errorEditTextView.setVisibility(View.VISIBLE);
}
});
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
emoticonsFrameLayout.setVisibility(View.GONE);
sendMessage();
if (contact != null && !contact.isBlocked() || channel != null) {
handleSendAndRecordButtonView(false);
}
}
});
closeAttachmentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
filePath = null;
if (previewThumbnail != null) {
previewThumbnail.recycle();
}
attachmentLayout.setVisibility(View.GONE);
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (recyclerDetailConversationAdapter != null) {
recyclerDetailConversationAdapter.contactImageLoader.setPauseWork(newState == RecyclerView.SCROLL_STATE_DRAGGING);
}
}
@Override
public void onScrolled(final RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
if (loadMore) {
int topRowVerticalPosition = (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
swipeLayout.setEnabled(topRowVerticalPosition >= 0);
}
}
});
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (channel != null) {
if (channel.isDeleted()) {
return;
}
if (alCustomizationSettings.isGroupInfoScreenVisible() && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
Intent channelInfo = new Intent(getActivity(), ChannelInfoActivity.class);
channelInfo.putExtra(ChannelInfoActivity.CHANNEL_KEY, channel.getKey());
startActivity(channelInfo);
} else if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) && alCustomizationSettings.isUserProfileFragment()) {
UserProfileFragment userProfileFragment = (UserProfileFragment) UIService.getFragmentByTag(getActivity(), ConversationUIService.USER_PROFILE_FRAMENT);
if (userProfileFragment == null) {
String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
Contact newcContact = appContactService.getContactById(userId);
userProfileFragment = new UserProfileFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(ConversationUIService.CONTACT, newcContact);
userProfileFragment.setArguments(bundle);
ConversationActivity.addFragment(getActivity(), userProfileFragment, ConversationUIService.USER_PROFILE_FRAMENT);
}
}
}
} else {
if (alCustomizationSettings.isUserProfileFragment()) {
UserProfileFragment userProfileFragment = (UserProfileFragment) UIService.getFragmentByTag(getActivity(), ConversationUIService.USER_PROFILE_FRAMENT);
if (userProfileFragment == null) {
userProfileFragment = new UserProfileFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(ConversationUIService.CONTACT, contact);
userProfileFragment.setArguments(bundle);
ConversationActivity.addFragment(getActivity(), userProfileFragment, ConversationUIService.USER_PROFILE_FRAMENT);
}
}
}
}
});
recyclerView.setLongClickable(true);
// Adding fragment for emoticons...
// //Fragment emojiFragment = new EmojiconsFragment(this, this);
// Fragment emojiFragment = new EmojiconsFragment();
// FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
// transaction.add(R.id.emojicons_frame_layout, emojiFragment).commit();
messageTemplate = alCustomizationSettings.getMessageTemplate();
if (messageTemplate != null && messageTemplate.isEnabled()) {
templateAdapter = new MobicomMessageTemplateAdapter(messageTemplate);
MobicomMessageTemplateAdapter.MessageTemplateDataListener listener = new MobicomMessageTemplateAdapter.MessageTemplateDataListener() {
@Override
public void onItemSelected(String message) {
final Message lastMessage = !messageList.isEmpty() ? messageList.get(messageList.size() - 1) : null;
if ((messageTemplate.getTextMessageList() != null && !messageTemplate.getTextMessageList().getMessageList().isEmpty() && messageTemplate.getTextMessageList().isSendMessageOnClick() && "text".equals(getMessageType(lastMessage))) || (messageTemplate.getImageMessageList() != null && !messageTemplate.getImageMessageList().getMessageList().isEmpty() && messageTemplate.getImageMessageList().isSendMessageOnClick() && "image".equals(getMessageType(lastMessage))) || (messageTemplate.getVideoMessageList() != null && !messageTemplate.getVideoMessageList().getMessageList().isEmpty() && messageTemplate.getVideoMessageList().isSendMessageOnClick() && "video".equals(getMessageType(lastMessage))) || (messageTemplate.getLocationMessageList() != null && !messageTemplate.getLocationMessageList().getMessageList().isEmpty() && messageTemplate.getLocationMessageList().isSendMessageOnClick() && "location".equals(getMessageType(lastMessage))) || (messageTemplate.getContactMessageList() != null && !messageTemplate.getContactMessageList().getMessageList().isEmpty() && messageTemplate.getContactMessageList().isSendMessageOnClick() && "contact".equals(getMessageType(lastMessage))) || (messageTemplate.getAudioMessageList() != null && !messageTemplate.getAudioMessageList().getMessageList().isEmpty() && messageTemplate.getAudioMessageList().isSendMessageOnClick() && "audio".equals(getMessageType(lastMessage))) || messageTemplate.getSendMessageOnClick()) {
sendMessage(message);
}
if (messageTemplate.getHideOnSend()) {
AlMessageMetadataUpdateTask.MessageMetadataListener listener1 = new AlMessageMetadataUpdateTask.MessageMetadataListener() {
@Override
public void onSuccess(Context context, String message) {
templateAdapter.setMessageList(new HashMap<String, String>());
templateAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(Context context, String error) {
}
};
if (lastMessage != null) {
Map<String, String> metadata = lastMessage.getMetadata();
metadata.put("isDoneWithClicking", "true");
lastMessage.setMetadata(metadata);
new AlMessageMetadataUpdateTask(getContext(), lastMessage.getKeyString(), lastMessage.getMetadata(), listener1).execute();
}
}
final Intent intent = new Intent();
intent.setAction("com.applozic.mobicomkit.TemplateMessage");
intent.putExtra("templateMessage", message);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
getActivity().sendBroadcast(intent);
}
};
templateAdapter.setOnItemSelected(listener);
LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
messageTemplateView.setLayoutManager(horizontalLayoutManagaer);
messageTemplateView.setAdapter(templateAdapter);
}
createTemplateMessages();
return list;
}
use of com.applozic.mobicomkit.api.conversation.Message 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.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String jsonString = FileUtils.loadSettingsJsonFile(getActivity().getApplicationContext());
if (!TextUtils.isEmpty(jsonString)) {
alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
} else {
alCustomizationSettings = new AlCustomizationSettings();
}
applozicDocumentView = new ApplozicDocumentView(getContext());
restrictedWords = FileUtils.loadRestrictedWordsFile(getContext());
conversationUIService = new ConversationUIService(getActivity());
syncCallService = SyncCallService.getInstance(getActivity());
appContactService = new AppContactService(getActivity());
messageDatabaseService = new MessageDatabaseService(getActivity());
fileClientService = new FileClientService(getActivity());
setHasOptionsMenu(true);
imageThumbnailLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {
@Override
protected Bitmap processBitmap(Object data) {
return fileClientService.loadThumbnailImage(getContext(), (Message) data, getImageLayoutParam(false).width, getImageLayoutParam(false).height);
}
};
imageCache = ImageCache.getInstance((getActivity()).getSupportFragmentManager(), 0.1f);
imageThumbnailLoader.setImageFadeIn(false);
imageThumbnailLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
messageImageLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {
@Override
protected Bitmap processBitmap(Object data) {
return fileClientService.loadMessageImage(getContext(), (String) data);
}
};
messageImageLoader.setImageFadeIn(false);
messageImageLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
applozicAudioRecordManager = new ApplozicAudioRecordManager(getActivity());
mDetector = new GestureDetectorCompat(getContext(), this);
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method updateDownloadStatus.
public void updateDownloadStatus(final Message message) {
if (this.getActivity() == null) {
return;
}
this.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
int index = messageList.indexOf(message);
if (index != -1) {
Message smListItem = messageList.get(index);
smListItem.setKeyString(message.getKeyString());
smListItem.setFileMetaKeyStrings(message.getFileMetaKeyStrings());
if (messageList.get(index) != null) {
messageList.get(index).setKeyString(message.getKeyString());
messageList.get(index).setFileMetaKeyStrings(message.getFileMetaKeyStrings());
}
View view = recyclerView.getChildAt(index - linearLayoutManager.findFirstVisibleItemPosition());
if (view != null) {
final RelativeLayout attachmentDownloadProgressLayout = (RelativeLayout) view.findViewById(R.id.attachment_download_progress_layout);
final AttachmentView attachmentView = (AttachmentView) view.findViewById(R.id.main_attachment_view);
final ImageView preview = (ImageView) view.findViewById(R.id.preview);
TextView audioDurationTextView = (TextView) view.findViewById(R.id.audio_duration_textView);
final ImageView videoIcon = (ImageView) view.findViewById(R.id.video_icon);
String audioDuration;
if (message.getFileMetas() != null && message.getFileMetas().getContentType().contains("image")) {
attachmentView.setVisibility(VISIBLE);
preview.setVisibility(View.GONE);
attachmentView.setMessage(smListItem);
attachmentDownloadProgressLayout.setVisibility(View.GONE);
} else if (message.getFileMetas() != null && message.getFileMetas().getContentType().contains("video")) {
FileClientService fileClientService = new FileClientService(getContext());
attachedFile.setVisibility(View.GONE);
preview.setVisibility(VISIBLE);
videoIcon.setVisibility(VISIBLE);
preview.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
} else if (message.getFileMetas() != null) {
// Hide Attachment View...
RelativeLayout applozicDocRelativeLayout = (RelativeLayout) view.findViewById(R.id.applozic_doc_downloaded);
ImageView imageViewDoc = (ImageView) applozicDocRelativeLayout.findViewById(R.id.doc_icon);
if (message.getFileMetas() != null && message.getFilePaths() == null) {
if (message.getFileMetas().getContentType().contains("audio")) {
imageViewDoc.setImageResource(R.drawable.ic_play_circle_outline);
} else {
imageViewDoc.setImageResource(R.drawable.ic_documentreceive);
}
applozicDocRelativeLayout.setVisibility(VISIBLE);
} else if (message.getFilePaths() != null) {
String filePath = message.getFilePaths().get(0);
final String mimeType = FileUtils.getMimeType(filePath);
if (mimeType.contains("audio")) {
if (message.isAttachmentDownloaded()) {
audioDuration = ApplozicAudioManager.getInstance(getContext()).refreshAudioDuration(filePath);
audioDurationTextView.setVisibility(View.VISIBLE);
audioDurationTextView.setText(audioDuration);
} else {
audioDurationTextView.setVisibility(View.VISIBLE);
audioDurationTextView.setText("00:00");
}
imageViewDoc.setImageResource(R.drawable.ic_play_circle_outline);
} else {
imageViewDoc.setImageResource(R.drawable.ic_documentreceive);
}
applozicDocRelativeLayout.setVisibility(VISIBLE);
}
view.findViewById(R.id.applozic_doc_download_progress_rl).setVisibility(View.GONE);
}
}
}
} catch (Exception ex) {
Utils.printLog(getContext(), TAG, "Exception while updating download status: " + ex.getMessage());
}
}
});
}
Aggregations