Search in sources :

Example 6 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class NotificationService method notifyUser.

public void notifyUser(Contact contact, Channel channel, Message message) {
    if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
        Utils.printLog(context, TAG, "Notification is disabled !!");
        return;
    }
    Bitmap notificationIconBitmap = null;
    unReadMessageList = messageDatabaseService.getUnreadMessages();
    int count = appContactService.getChatConversationCount() + appContactService.getGroupConversationCount();
    int totalCount = messageDatabaseService.getTotalUnreadCount();
    Class activity = null;
    try {
        activity = Class.forName(activityToOpen);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (message.getGroupId() != null) {
        if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
            String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
            if (!TextUtils.isEmpty(userId)) {
                Contact newContact = appContactService.getContactById(userId);
                notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
            }
        } else {
            notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
        }
    } else {
        notificationIconBitmap = appContactService.downloadContactImage(context, contact);
    }
    Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
    Intent intent;
    if (count < 2) {
        intent = new Intent(context, activity);
        intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    } else {
        intent = new Intent(context, activity);
        intent.putExtra(MobiComKitConstants.QUICK_LIST, true);
    }
    if (applozicClient.isChatListOnNotificationIsHidden()) {
        intent.putExtra("takeOrder", true);
    }
    if (applozicClient.isContextBasedChat()) {
        intent.putExtra("contextBasedChat", true);
    }
    intent.putExtra("sms_body", "text");
    intent.setType("vnd.android-dir/mms-sms");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) (System.currentTimeMillis() & 0xfffffff), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, MobiComKitConstants.AL_PUSH_NOTIFICATION).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis());
    mBuilder.setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        mBuilder.setGroup(GROUP_KEY);
        mBuilder.setGroupSummary(true);
    } else {
        if (totalCount != 0) {
            mBuilder.setNumber(totalCount);
        }
    }
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    if (ApplozicClient.getInstance(context).getVibrationOnNotification()) {
        mBuilder.setVibrate(pattern);
    }
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel));
    // Moves events into the expanded layout
    try {
        if (unReadMessageList != null) {
            for (Message messageString : unReadMessageList) {
                if (messageString.getGroupId() != null) {
                    Channel unreadChannel = ChannelService.getInstance(context).getChannelByChannelKey(messageString.getGroupId());
                    if (unreadChannel != null && unreadChannel.getUnreadCount() == 0) {
                        continue;
                    }
                } else {
                    Contact unreadCount = appContactService.getContactById(messageString.getContactIds());
                    if (unreadCount != null && unreadCount.getUnreadCount() == 0) {
                        continue;
                    }
                }
                inboxStyle.addLine(getMessageBody(messageString, count, channel, contact));
            }
        }
    // Moves the expanded layout object into the notification object.
    } catch (Exception e) {
        e.printStackTrace();
    }
    String summaryText = "";
    if (count < 1) {
        summaryText = "";
        mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
        mBuilder.setContentText(getMessageBody(message, count, channel, contact));
    } else if (count >= 1 && count < 2) {
        summaryText = totalCount < 2 ? totalCount + " new message " : totalCount + " new messages ";
        mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
        mBuilder.setContentText(summaryText);
    } else {
        summaryText = totalCount + " messages from " + count + " chats";
        mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), iconResourceId));
        mBuilder.setContentText(summaryText);
    }
    inboxStyle.setSummaryText(summaryText);
    mBuilder.setContentTitle(getNotificationTitle(count, contact, channel));
    mBuilder.setStyle(inboxStyle);
    if (message.hasAttachment()) {
        try {
            InputStream in;
            FileMeta fileMeta = message.getFileMetas();
            HttpURLConnection httpConn = null;
            if (fileMeta.getThumbnailUrl() != null) {
                httpConn = new MobiComKitClientService(context).openHttpConnection(fileMeta.getThumbnailUrl());
                int response = httpConn.getResponseCode();
                if (response == HttpURLConnection.HTTP_OK) {
                    in = httpConn.getInputStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(in);
                    String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
                    File file = FileClientService.getFilePath(imageName, context, "image", true);
                    ImageUtils.saveImageToInternalStorage(file, bitmap);
                    if (unReadMessageList != null && unReadMessageList.size() < 2) {
                        mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, NOTIFICATION_ID);
    notificationWithVoice.setCurrentContext(context);
    notificationWithVoice.setPendingIntent(pendingIntent);
    try {
        if (unReadMessageList != null && unReadMessageList.size() > 0) {
            notificationWithVoice.sendNotification();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) InputStream(java.io.InputStream) Channel(com.applozic.mobicommons.people.channel.Channel) MobiComKitClientService(com.applozic.mobicomkit.api.MobiComKitClientService) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 7 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MainActivity method buildSupportContactData.

private void buildSupportContactData() {
    Context context = getApplicationContext();
    AppContactService appContactService = new AppContactService(context);
    // avoid each time update ....
    if (!appContactService.isContactExists(getString(R.string.support_contact_userId))) {
        Contact contact = new Contact();
        contact.setUserId(getString(R.string.support_contact_userId));
        contact.setFullName(getString(R.string.support_contact_display_name));
        contact.setContactNumber(getString(R.string.support_contact_number));
        contact.setImageURL(getString(R.string.support_contact_image_url));
        contact.setEmailId(getString(R.string.support_contact_emailId));
        appContactService.add(contact);
    }
}
Also used : Context(android.content.Context) AppContactService(com.applozic.mobicomkit.contact.AppContactService) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 8 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class ConversationServiceTest method testDeleteMessage.

@Test
public void testDeleteMessage() {
    try {
        Message message = (Message) GsonUtils.getObjectFromJson(MockedConstants.Message, Message.class);
        Mockito.when(messageDatabaseService.deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.anyString())).thenReturn("checkMe");
        Mockito.when(messageClientService.deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.nullable(Contact.class))).thenReturn("success");
        mobiComConversationService.deleteMessage(message, new Contact());
        Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.nullable(String.class));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MockitoException(org.mockito.exceptions.base.MockitoException) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 9 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class ConversationServiceTest method testDeleteSyncWithContactReturnSuccess.

@Test
public void testDeleteSyncWithContactReturnSuccess() {
    try {
        Contact contact = new Contact();
        contact.setUserId("testUserId");
        Mockito.when(messageClientService.syncDeleteConversationThreadFromServer(contact, null)).thenReturn("success");
        Assert.assertEquals("success", mobiComConversationService.deleteSync(contact, null, null));
        // Check if method is called...
        Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteConversation(ArgumentMatchers.anyString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 10 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class ConversationRunnables method syncConversation.

private void syncConversation() {
    try {
        MobiComConversationService mobiComConversationService = new MobiComConversationService(context);
        List<Message> messages = mobiComConversationService.getLatestMessagesGroupByPeople();
        UserService.getInstance(context).processSyncUserBlock();
        for (Message message : messages.subList(0, Math.min(PRE_FETCH_MESSAGES_FOR, messages.size()))) {
            Contact contact = null;
            Channel channel = null;
            if (message.getGroupId() != null) {
                channel = new Channel(message.getGroupId());
            } else {
                contact = new Contact(message.getContactIds());
            }
            mobiComConversationService.getMessagesWithNetworkMetaData(1L, null, contact, channel, null, true, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

Contact (com.applozic.mobicommons.people.contact.Contact)107 Channel (com.applozic.mobicommons.people.channel.Channel)26 Message (com.applozic.mobicomkit.api.conversation.Message)18 Intent (android.content.Intent)17 AppContactService (com.applozic.mobicomkit.contact.AppContactService)17 ArrayList (java.util.ArrayList)15 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)14 UserDetail (com.applozic.mobicomkit.api.account.user.UserDetail)12 Test (org.junit.Test)12 Bitmap (android.graphics.Bitmap)11 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)10 Context (android.content.Context)9 SpannableString (android.text.SpannableString)8 NonNull (androidx.annotation.NonNull)8 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)8 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)8 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)8 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)7 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)7 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)7