Search in sources :

Example 56 with Contact

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

the class ConversationReadService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    MessageClientService messageClientService = new MessageClientService(getApplicationContext());
    Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
    boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
    Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
    Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
    if (unreadCount != 0) {
        Intent readIntent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(readIntent);
    }
    if (unreadCount != 0 || singleMessageRead) {
        messageClientService.updateReadStatus(contact, channel);
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 57 with Contact

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

the class NotificationIntentService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_AL_NOTIFICATION.equals(action)) {
            String messageKey = intent.getStringExtra(MobiComKitConstants.AL_MESSAGE_KEY);
            Message message = messageDatabaseService.getMessage(messageKey);
            if (message != null) {
                int notificationId = Utils.getLauncherIcon(getApplicationContext());
                final NotificationService notificationService = new NotificationService(notificationId == 0 ? resourceArray[0] : notificationId, NotificationIntentService.this, resourceArray[1], resourceArray[2], resourceArray[3]);
                if (MobiComUserPreference.getInstance(NotificationIntentService.this).isLoggedIn()) {
                    Channel channel = ChannelService.getInstance(NotificationIntentService.this).getChannelInfo(message.getGroupId());
                    Contact contact = null;
                    if (message.getConversationId() != null) {
                        ConversationService.getInstance(NotificationIntentService.this).getConversation(message.getConversationId());
                    }
                    if (message.getGroupId() == null) {
                        contact = appContactService.getContactById(message.getContactIds());
                    }
                    if (ApplozicClient.getInstance(NotificationIntentService.this).isNotificationStacking()) {
                        notificationService.notifyUser(contact, channel, message);
                    } else {
                        notificationService.notifyUserForNormalMessage(contact, channel, message);
                    }
                }
            }
        }
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 58 with Contact

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

the class NotificationService method notifyUserForNormalMessage.

public void notifyUserForNormalMessage(Contact contact, Channel channel, Message message) {
    if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
        Utils.printLog(context, TAG, "Notification is disabled");
        return;
    }
    String title = null;
    String notificationText;
    Bitmap notificationIconBitmap = null;
    Contact displayNameContact = null;
    if (message.getGroupId() != null) {
        if (channel == null) {
            return;
        }
        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);
                title = newContact.getDisplayName();
            }
        } else {
            displayNameContact = appContactService.getContactById(message.getTo());
            title = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId());
            notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
        }
    } else {
        title = contact.getDisplayName();
        notificationIconBitmap = appContactService.downloadContactImage(context, contact);
    }
    if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
        notificationText = MobiComKitConstants.LOCATION;
    } else if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
        notificationText = MobiComKitConstants.AUDIO;
    } else if (message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) {
        notificationText = MobiComKitConstants.VIDEO;
    } else if (message.hasAttachment() && TextUtils.isEmpty(message.getMessage())) {
        notificationText = MobiComKitConstants.ATTACHMENT;
    } else {
        notificationText = message.getMessage();
    }
    Class activity = null;
    try {
        activity = Class.forName(activityToOpen);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
    Intent intent = new Intent(context, activity);
    intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    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);
    mBuilder.setSmallIcon(smallIconResourceId).setLargeIcon(ApplozicClient.getInstance(context).isShowAppIconInNotification() ? BitmapFactory.decodeResource(context.getResources(), iconResourceId) : notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(channel != null && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName()))).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()).setContentTitle(title).setContentText(channel != null && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? displayNameContact.getDisplayName() + ": " + notificationText : notificationText).setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
        int totalCount = messageDatabaseService.getTotalUnreadCount();
        if (totalCount != 0) {
            mBuilder.setNumber(totalCount);
        }
    }
    if (message.hasAttachment()) {
        try {
            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) {
                    Bitmap bitmap = BitmapFactory.decodeStream(httpConn.getInputStream());
                    String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
                    File file = FileClientService.getFilePath(imageName, context, "image", true);
                    ImageUtils.saveImageToInternalStorage(file, bitmap);
                    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, message.getGroupId() != null ? String.valueOf(message.getGroupId()).hashCode() : message.getContactIds().hashCode());
    notificationWithVoice.setCurrentContext(context);
    notificationWithVoice.setPendingIntent(pendingIntent);
    try {
        notificationWithVoice.sendNotification();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) 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 59 with Contact

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

the class UserIntentService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
    boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
    Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
    Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
    if (unreadCount != 0 || singleMessageRead) {
        messageClientService.updateReadStatus(contact, channel);
    } else {
        String userId = intent.getStringExtra(USER_ID);
        if (!TextUtils.isEmpty(userId)) {
            SyncCallService.getInstance(UserIntentService.this).processUserStatus(userId);
        } else if (intent.getBooleanExtra(USER_LAST_SEEN_AT_STATUS, false)) {
            mobiComConversationService.processLastSeenAtStatus();
        }
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 60 with Contact

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

the class ScheduledMessageAdapter method getView.

public View getView(int position, View convertView, ViewGroup parent) {
    View customView = convertView;
    if (customView == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        customView = inflater.inflate(R.layout.mobicom_message_row_view, null);
        ImageView sentOrReceived = (ImageView) customView.findViewById(R.id.sentOrReceivedIcon);
        sentOrReceived.setVisibility(View.GONE);
        TextView unreadSmsTxtView = (TextView) customView.findViewById(R.id.unreadSmsCount);
        unreadSmsTxtView.setVisibility(View.GONE);
    }
    Message messageListItem = getItem(position);
    if (messageListItem != null) {
        TextView smReceivers = (TextView) customView.findViewById(R.id.smReceivers);
        TextView smTime = (TextView) customView.findViewById(R.id.createdAtTime);
        // TextView createdAtTime = (TextView) customView.findViewById(R.id.createdAtTime);
        TextView scheduledMessage = (TextView) customView.findViewById(R.id.message);
        ImageView contactImage = (ImageView) customView.findViewById(R.id.contactImage);
        if (smReceivers != null) {
            List<String> items = Arrays.asList(messageListItem.getTo().split("\\s*,\\s*"));
            Contact contact1 = ContactUtils.getContact(getContext(), items.get(0));
            String contactinfo = TextUtils.isEmpty(contact1.getFirstName()) ? contact1.getContactNumber() : contact1.getFirstName();
            if (items.size() > 1) {
                Contact contact2 = baseContactService.getContactById(items.get(1));
                contactinfo = contactinfo + " , " + (TextUtils.isEmpty(contact2.getFirstName()) ? contact2.getContactNumber() : contact2.getFirstName());
            }
            smReceivers.setText(contactinfo.length() > 22 ? contactinfo.substring(0, 22) + "..." : contactinfo);
            String contactId = ContactUtils.getContactId(items.get(0), getContext().getContentResolver());
            // Todo: Check if contactId is working or not.
            Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactId);
            mImageLoader.loadImage(contactUri, contactImage);
        }
        if (smTime != null) {
            Calendar calendarForCurrent = Calendar.getInstance();
            Calendar calendarForScheduled = Calendar.getInstance();
            Date currentDate = new Date();
            Date date = new Date(messageListItem.getScheduledAt());
            calendarForCurrent.setTime(currentDate);
            calendarForScheduled.setTime(date);
            boolean sameDay = calendarForCurrent.get(Calendar.YEAR) == calendarForScheduled.get(Calendar.YEAR) && calendarForCurrent.get(Calendar.DAY_OF_YEAR) == calendarForScheduled.get(Calendar.DAY_OF_YEAR);
            String formattedDate = sameDay ? DateFormat.getTimeInstance().format(date) : DateFormat.getDateInstance().format(date);
            smTime.setText(formattedDate);
        }
        if (scheduledMessage != null) {
            scheduledMessage.setText(messageListItem.getMessage());
        }
    }
    return customView;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) LayoutInflater(android.view.LayoutInflater) Calendar(java.util.Calendar) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) Date(java.util.Date) 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