use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class ScheduleMessageService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
Calendar c = Calendar.getInstance();
long time = c.getTimeInMillis();
MessageDatabaseService messageDatabaseService = new MessageDatabaseService(getApplicationContext());
MobiComConversationService conversationService = new MobiComConversationService(getApplicationContext());
List<Message> messages = messageDatabaseService.getScheduledMessages(time);
for (Message message : messages) {
message.setScheduledAt(null);
conversationService.sendMessage(message);
// Todo: broadcast for scheduled message fragment.
}
messageDatabaseService.deleteScheduledMessages(time);
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method loadConversation.
public void loadConversation(final Contact contact, final Channel channel, final Integer conversationId, final String searchString) {
try {
if (downloadConversation != null) {
downloadConversation.cancel(true);
}
if (this.contact != null && contact != null && !contact.getUserId().equals(this.contact.getUserId())) {
userDisplayName = null;
}
setContact(contact);
setChannel(channel);
BroadcastService.currentUserId = contact != null ? contact.getContactIds() : String.valueOf(channel.getKey());
typingStarted = false;
onSelected = false;
messageMetaData = null;
Applozic.subscribeToTyping(getContext(), channel, contact);
checkForUserNotAbleToChatAndToggleViews(contact, channel);
if (contact != null && this.channel != null) {
if (getActivity() != null) {
setToolbarSubtitle("");
setToolbarImage(contact, channel);
}
if (menu != null) {
menu.findItem(R.id.unmuteGroup).setVisible(false);
menu.findItem(R.id.muteGroup).setVisible(false);
}
}
if (replayRelativeLayout != null) {
replayRelativeLayout.setVisibility(View.GONE);
}
if (TextUtils.isEmpty(filePath) && attachmentLayout != null) {
attachmentLayout.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(defaultText) && messageEditText != null) {
messageEditText.setText(defaultText);
defaultText = "";
}
extendedSendingOptionLayout.setVisibility(VISIBLE);
unregisterForContextMenu(recyclerView);
if (getActivity() != null) {
if (ApplozicClient.getInstance(getActivity()).isNotificationStacking()) {
NotificationManagerCompat nMgr = NotificationManagerCompat.from(getActivity());
nMgr.cancel(NotificationService.NOTIFICATION_ID);
} else {
if (contact != null) {
if (!TextUtils.isEmpty(contact.getContactIds())) {
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.cancel(contact.getContactIds().hashCode());
}
}
}
if (channel != null) {
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.cancel(String.valueOf(channel.getKey()).hashCode());
}
}
}
}
clearList();
updateTitle(contact, channel);
swipeLayout.setEnabled(true);
loadMore = true;
if (selfDestructMessageSpinner != null) {
selfDestructMessageSpinner.setSelection(0);
}
if (contact != null) {
recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, contact, messageIntentClass, emojiIconHandler);
recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
recyclerDetailConversationAdapter.setContextMenuClickListener(this);
recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
if (getActivity() instanceof ALStoragePermissionListener) {
recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
} else {
recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {
@Override
public boolean isPermissionGranted() {
return false;
}
@Override
public void checkPermission(ALStoragePermission storagePermission) {
}
});
}
} else if (channel != null) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (!ChannelService.getInstance(getContext()).isUserAlreadyPresentInChannel(channel.getKey(), loggedInUserId) && messageTemplate != null && messageTemplate.isEnabled() && templateAdapter != null) {
if (getActivity() == null) {
return;
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
templateAdapter.removeTemplates();
}
});
}
}
});
thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, channel, messageIntentClass, emojiIconHandler);
recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
recyclerDetailConversationAdapter.setContextMenuClickListener(this);
recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
if (getActivity() instanceof ALStoragePermissionListener) {
recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
} else {
recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {
@Override
public boolean isPermissionGranted() {
return false;
}
@Override
public void checkPermission(ALStoragePermission storagePermission) {
}
});
}
}
linearLayoutManager.setSmoothScrollbarEnabled(true);
if (getActivity() == null) {
return;
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
linearLayoutManager.setStackFromEnd(true);
}
});
recyclerView.setAdapter(recyclerDetailConversationAdapter);
registerForContextMenu(recyclerView);
processMobiTexterUserCheck();
downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversationId);
AlTask.execute(downloadConversation);
if (hideExtendedSendingOptionLayout) {
extendedSendingOptionLayout.setVisibility(View.GONE);
}
emoticonsFrameLayout.setVisibility(View.GONE);
MobiComConversationService mobiComConversationService = new MobiComConversationService(requireContext().getApplicationContext());
if (contact != null) {
mobiComConversationService.syncUserDetail(contact.getUserId());
}
if (channel != null) {
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
mobiComConversationService.syncUserDetail(userId);
}
} else {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
updateChannelSubTitle(channel);
}
});
thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
}
}
if (alCustomizationSettings.isMessageFastScrollEnabled()) {
if (getActivity() == null) {
return;
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
recyclerView.smoothScrollToPosition(messageList.size());
recyclerView.getLayoutManager().scrollToPosition(messageList.size());
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService 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) {
AlTask.execute(new DeleteConversationAsyncTask(new MobiComConversationService(getActivity()), contact, channel, currentConversationId, getActivity()));
}
});
alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
alertDialog.setTitle(ApplozicService.getContext(getContext()).getString(R.string.dialog_delete_conversation_title).replace("[name]", getNameForInviteDialog()));
alertDialog.setMessage(ApplozicService.getContext(getContext()).getString(R.string.dialog_delete_conversation_confir).replace("[name]", getNameForInviteDialog()));
alertDialog.setCancelable(true);
alertDialog.create().show();
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method sendProductMessage.
public void sendProductMessage(final String messageToSend, final FileMeta fileMeta, final Contact contact, final short messageContentType) {
final Message message = new Message();
new Thread(new Runnable() {
@Override
public void run() {
String topicId;
MobiComConversationService conversationService = new MobiComConversationService(getActivity());
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
topicId = new MessageClientService(getActivity()).getTopicId(currentConversationId);
if (getChannel() != null) {
message.setGroupId(channelKey);
} else {
message.setContactIds(contact.getUserId());
message.setTo(contact.getUserId());
}
message.setMessage(messageToSend);
message.setRead(Boolean.TRUE);
message.setStoreOnDevice(Boolean.TRUE);
message.setSendToDevice(Boolean.FALSE);
message.setContentType(messageContentType);
message.setType(Message.MessageType.MT_OUTBOX.getValue());
message.setDeviceKeyString(userPreferences.getDeviceKeyString());
message.setSource(Message.Source.MT_MOBILE_APP.getValue());
message.setTopicId(messageToSend);
message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
message.setTopicId(topicId);
message.setConversationId(currentConversationId);
message.setFileMetas(fileMeta);
conversationService.sendMessage(message, userDisplayName);
}
}).start();
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class ApplozicDocumentView method registerEvents.
public void registerEvents() {
previewLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (alStoragePermissionListener.isPermissionGranted()) {
if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
// Starts downloading this View, using the current cache setting
mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
// After successfully downloading the image, this marks that it's available.
showDownloadInProgress();
}
if (mDownloadThread == null) {
mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
if (mDownloadThread != null)
mDownloadThread.setAttachementViewNew(attachmentViewProperties);
}
} else {
alStoragePermissionListener.checkPermission(new ALStoragePermission() {
@Override
public void onAction(boolean didGrant) {
if (didGrant) {
if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
// Starts downloading this View, using the current cache setting
mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
// After successfully downloading the image, this marks that it's available.
showDownloadInProgress();
}
if (mDownloadThread == null) {
mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
if (mDownloadThread != null)
mDownloadThread.setAttachementViewNew(attachmentViewProperties);
}
}
}
});
}
}
});
downloadedLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (alStoragePermissionListener.isPermissionGranted()) {
playAudio();
} else {
alStoragePermissionListener.checkPermission(new ALStoragePermission() {
@Override
public void onAction(boolean didGrant) {
if (didGrant) {
playAudio();
}
}
});
}
}
});
downloadInProgressLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelDownload();
}
});
retryLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
message.setCanceled(false);
MessageDatabaseService messageDatabaseService = new MessageDatabaseService(context);
messageDatabaseService.updateCanceledFlag(message.getMessageId(), 0);
new MobiComConversationService(context).sendMessage(message, null);
showDownloadInProgress();
}
});
}
Aggregations