Search in sources :

Example 46 with Contact

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

the class QuickConversationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (getItemViewType(position) == 2) {
        FooterViewHolder myHolder = (FooterViewHolder) holder;
        myHolder.infoBroadCast.setVisibility(View.GONE);
    } else {
        Myholder myholder = (Myholder) holder;
        final Message message = getItem(position);
        myholder.smTime.setVisibility(View.GONE);
        if (message != null) {
            List<String> items = null;
            List<String> userIds = null;
            final Channel channel = ChannelDatabaseService.getInstance(context).getChannelByChannelKey(message.getGroupId());
            if (channel == null && message.getGroupId() == null) {
                items = Arrays.asList(message.getTo().split("\\s*,\\s*"));
                if (!TextUtils.isEmpty(message.getContactIds())) {
                    userIds = Arrays.asList(message.getContactIds().split("\\s*,\\s*"));
                }
            }
            final Contact contactReceiver = contactService.getContactReceiver(items, userIds);
            showSenderNameIfRequired(myholder, message);
            myholder.contactImage.setVisibility(View.GONE);
            myholder.alphabeticTextView.setVisibility(View.GONE);
            if (contactReceiver != null) {
                String contactInfo = contactReceiver.getDisplayName();
                if (items != null && items.size() > 1) {
                    Contact contact2 = contactService.getContactById(items.get(1));
                    contactInfo = TextUtils.isEmpty(contactReceiver.getFirstName()) ? contactReceiver.getContactNumber() : contactReceiver.getFirstName() + ", " + (TextUtils.isEmpty(contact2.getFirstName()) ? contact2.getContactNumber() : contact2.getFirstName()) + (items.size() > 2 ? " & others" : "");
                }
                myholder.smReceivers.setText(contactInfo);
                contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                processContactImage(contactReceiver, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
            } else if (message.getGroupId() != null) {
                if (channel != null && Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                    contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                    if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                        Contact withUserContact = contactService.getContactById(ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey()));
                        if (withUserContact != null) {
                            myholder.smReceivers.setText(withUserContact.getDisplayName());
                            processContactImage(withUserContact, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
                        }
                    }
                } else {
                    if (channel != null && Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
                        channelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                        myholder.contactImage.setImageResource(R.drawable.applozic_ic_contact_picture_holo_light);
                    } else {
                        channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
                        myholder.contactImage.setImageResource(R.drawable.applozic_group_icon);
                    }
                    myholder.smReceivers.setText(ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId()));
                    myholder.alphabeticTextView.setVisibility(View.GONE);
                    myholder.contactImage.setVisibility(View.VISIBLE);
                    if (channel != null && !TextUtils.isEmpty(channel.getImageUrl())) {
                        channelImageLoader.loadImage(channel, myholder.contactImage);
                    } else if (channel != null && channel.isBroadcastMessage()) {
                        myholder.contactImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
                    } else if (channel != null && Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
                        channelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                    } else {
                        channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
                    }
                }
            }
            myholder.onlineTextView.setVisibility(View.GONE);
            if (alCustomizationSettings.isOnlineStatusMasterList()) {
                myholder.onlineTextView.setVisibility(contactReceiver != null && contactReceiver.isOnline() ? View.VISIBLE : View.GONE);
            }
            if (myholder.attachedFile != null) {
                myholder.attachedFile.setText("");
                myholder.attachedFile.setVisibility(View.GONE);
            }
            if (myholder.attachmentIcon != null) {
                myholder.attachmentIcon.setVisibility(View.GONE);
            }
            if (message.isVideoCallMessage()) {
                createVideoCallView(message, myholder.attachmentIcon, myholder.messageTextView);
            } else if (message.hasAttachment() && myholder.attachmentIcon != null && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                // Todo: handle it for fileKeyStrings when filePaths is empty
                String filePath = message.getFileMetas() == null && message.getFilePaths() != null ? message.getFilePaths().get(0).substring(message.getFilePaths().get(0).lastIndexOf("/") + 1) : message.getFileMetas() != null ? message.getFileMetas().getName() : "";
                myholder.attachmentIcon.setVisibility(View.VISIBLE);
                myholder.attachmentIcon.setImageResource(R.drawable.applozic_ic_action_attachment);
                myholder.messageTextView.setText(filePath);
            } else if (myholder.attachmentIcon != null && message.getContentType() == Message.ContentType.LOCATION.getValue()) {
                myholder.attachmentIcon.setVisibility(View.VISIBLE);
                myholder.attachmentIcon.setImageResource(R.drawable.mobicom_notification_location_icon);
                myholder.messageTextView.setText(Utils.getString(context, R.string.Location));
            } else if (message.getContentType() == Message.ContentType.PRICE.getValue()) {
                SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor()));
                spannableStringBuilder.insert(0, ConversationUIService.FINAL_PRICE_TEXT);
                myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, spannableStringBuilder, emojiconHandler));
            } else if (message.getContentType() == Message.ContentType.TEXT_HTML.getValue()) {
                myholder.messageTextView.setText(Html.fromHtml(message.getMessage()));
            } else {
                Spannable messageSpannable = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor());
                CharSequence messageSpannableSubString = (!TextUtils.isEmpty(messageSpannable.toString()) ? messageSpannable.subSequence(0, Math.min(messageSpannable.length(), 50)) : new SpannableString(Utils.EMPTY_STRING));
                myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, messageSpannableSubString, emojiconHandler));
            }
            if (myholder.sentOrReceived != null) {
                if (message.isCall()) {
                    myholder.sentOrReceived.setImageResource(R.drawable.applozic_ic_action_call_holo_light);
                    myholder.messageTextView.setTextColor(Utils.getColor(context, message.isIncomingCall() ? R.color.incoming_call : R.color.outgoing_call));
                } else if (getItemViewType(position) == 0) {
                    myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_forward);
                } else {
                    myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_reply);
                }
            }
            if (myholder.createdAtTime != null) {
                myholder.createdAtTime.setText(DateUtils.getFormattedDateAndTime(context, message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getSameDayTimeTemplate(), alCustomizationSettings.getDateFormatCustomization().getOtherDayDateTemplate(), R.string.JUST_NOW, R.plurals.MINUTES, R.plurals.HOURS));
            }
            int messageUnReadCount = 0;
            if (message.getGroupId() == null && contactReceiver != null && !TextUtils.isEmpty(contactReceiver.getContactIds())) {
                messageUnReadCount = messageDatabaseService.getUnreadMessageCountForContact(contactReceiver.getContactIds());
            } else if (channel != null && channel.getKey() != null && channel.getKey() != 0) {
                messageUnReadCount = messageDatabaseService.getUnreadMessageCountForChannel(channel.getKey());
            }
            if (messageUnReadCount > 0) {
                myholder.unReadCountTextView.setVisibility(View.VISIBLE);
                myholder.unReadCountTextView.setText(String.valueOf(messageUnReadCount));
            } else {
                myholder.unReadCountTextView.setVisibility(View.GONE);
            }
            Spannable mentionsMessageString = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor());
            int startIndex = indexOfSearchQuery(mentionsMessageString.toString());
            if (startIndex != -1) {
                final SpannableString highlightedName = new SpannableString(mentionsMessageString);
                // Sets the span to start at the starting point of the match and end at "length"
                // characters beyond the starting point
                highlightedName.setSpan(highlightTextSpan, startIndex, startIndex + searchString.toString().length(), 0);
                myholder.messageTextView.setText(highlightedName);
            }
        }
    }
}
Also used : SpannableString(android.text.SpannableString) Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder) Spannable(android.text.Spannable) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 47 with Contact

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

the class ConversationFragment method reload.

public void reload() {
    try {
        StringBuffer stringBufferTitle = new StringBuffer();
        if (contact != null) {
            Contact updatedInfoContact = appContactService.getContactById(contact.getContactIds());
            contact.setImageURL(updatedInfoContact.getImageURL());
            contact.setLocalImageUrl(updatedInfoContact.getLocalImageUrl());
            if (updatedInfoContact.isDeleted()) {
                Utils.toggleSoftKeyBoard(getActivity(), true);
                ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("");
            }
            if (updatedInfoContact != null && (!TextUtils.isEmpty(contact.getDisplayName())) && (!contact.getDisplayName().equals(updatedInfoContact.getDisplayName()))) {
                stringBufferTitle.append(updatedInfoContact.getDisplayName());
            }
            enableOrDisableChat(updatedInfoContact);
        } else if (channel != null) {
            if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
                if (!TextUtils.isEmpty(userId)) {
                    Contact withUserContact = appContactService.getContactById(userId);
                    if (withUserContact != null && (!TextUtils.isEmpty(contact.getDisplayName())) && (!contact.getDisplayName().equals(withUserContact.getDisplayName()))) {
                        stringBufferTitle.append(withUserContact.getDisplayName());
                    }
                }
            }
        }
        if (!TextUtils.isEmpty(stringBufferTitle)) {
            ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(stringBufferTitle.toString());
        }
        recyclerDetailConversationAdapter.refreshContactData();
        recyclerDetailConversationAdapter.notifyDataSetChanged();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Contact(com.applozic.mobicommons.people.contact.Contact)

Example 48 with Contact

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

the class AppContactFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    contactDatabase = new ContactDatabase(getContext());
    contactService = new AppContactService(getActivity());
    mAdapter = new ContactsAdapter(getActivity().getApplicationContext());
    userPreference = MobiComUserPreference.getInstance(getContext());
    inviteMessage = Utils.getMetaDataValue(getActivity().getApplicationContext(), SHARE_TEXT);
    if (savedInstanceState != null) {
        mSearchTerm = savedInstanceState.getString(SearchManager.QUERY);
        mPreviouslySelectedSearchItem = savedInstanceState.getInt(STATE_PREVIOUSLY_SELECTED_KEY, 0);
        alCustomizationSettings = (AlCustomizationSettings) savedInstanceState.getSerializable(AL_CUSTOMIZATION_SETTINGS);
    }
    refreshContactsScreenBroadcast = new RefreshContactsScreenBroadcast();
    final Context context = getActivity().getApplicationContext();
    mImageLoader = new ImageLoader(context, getListPreferredItemHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadContactImage(context, (Contact) data);
        }
    };
    // Set a placeholder loading image for the image loader
    mImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
    // Add a cache to the image loader
    mImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f);
    mImageLoader.setImageFadeIn(false);
    if (!TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getContactsGroupId())) {
        ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(context);
        userIdArray = channelDatabaseService.getChannelMemberByName(MobiComUserPreference.getInstance(context).getContactsGroupId(), String.valueOf(Channel.GroupType.CONTACT_GROUP.getValue()));
        if (Utils.isInternetAvailable(getContext())) {
            ApplozicGetMemberFromContactGroupTask.GroupMemberListener eventMemberListener = new ApplozicGetMemberFromContactGroupTask.GroupMemberListener() {

                @Override
                public void onSuccess(String[] userIdArrays, Context context) {
                    if (isAdded()) {
                        userIdArray = new String[userIdArrays.length];
                        userIdArray = userIdArrays;
                        getLoaderManager().initLoader(ContactSelectionFragment.ContactsQuery.QUERY_ID, null, AppContactFragment.this);
                    }
                }

                @Override
                public void onFailure(String response, Context context) {
                }
            };
            ApplozicGetMemberFromContactGroupTask applozicGetMemberFromContactGroupTask = new ApplozicGetMemberFromContactGroupTask(getActivity(), MobiComUserPreference.getInstance(context).getContactsGroupId(), String.valueOf(Channel.GroupType.CONTACT_GROUP.getValue()), eventMemberListener);
            AlTask.execute(applozicGetMemberFromContactGroupTask);
        } else if (userIdArray != null) {
            getLoaderManager().initLoader(ContactSelectionFragment.ContactsQuery.QUERY_ID, null, AppContactFragment.this);
        }
    } else if (MobiComUserPreference.getInstance(getContext()).getContactGroupIdList() != null && !MobiComUserPreference.getInstance(getContext()).getContactGroupIdList().isEmpty()) {
        List<String> groupList = new ArrayList<String>();
        groupList.addAll(MobiComUserPreference.getInstance(getContext()).getContactGroupIdList());
        final ProgressDialog progressBar = new ProgressDialog(getContext());
        progressBar.setMessage(getContext().getResources().getString(R.string.processing_please_wait));
        progressBar.show();
        AlGetMembersFromContactGroupListTask.GetMembersFromGroupIdListListener listener = new AlGetMembersFromContactGroupListTask.GetMembersFromGroupIdListListener() {

            @Override
            public void onSuccess(Context context, String response, String[] contactList) {
                progressBar.dismiss();
                userIdArray = contactList;
                getLoaderManager().initLoader(ContactSelectionFragment.ContactsQuery.QUERY_ID, null, AppContactFragment.this);
            }

            @Override
            public void onFailure(Context context, String response, Exception e) {
                progressBar.dismiss();
                Toast.makeText(getContext(), R.string.failed_to_load_contact + response + "\nException : " + e, Toast.LENGTH_SHORT).show();
            }
        };
        if (MobiComUserPreference.getInstance(getContext()).isContactGroupNameList()) {
            AlTask.execute(new AlGetMembersFromContactGroupListTask(getContext(), listener, null, groupList, "9"));
        } else {
            AlTask.execute(new AlGetMembersFromContactGroupListTask(getContext(), listener, groupList, null, "9"));
        }
    }
}
Also used : Context(android.content.Context) AppContactService(com.applozic.mobicomkit.contact.AppContactService) SpannableString(android.text.SpannableString) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) ProgressDialog(android.app.ProgressDialog) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) AlGetMembersFromContactGroupListTask(com.applozic.mobicomkit.uiwidgets.async.AlGetMembersFromContactGroupListTask) Contact(com.applozic.mobicommons.people.contact.Contact) ApplozicGetMemberFromContactGroupTask(com.applozic.mobicomkit.uiwidgets.async.ApplozicGetMemberFromContactGroupTask) Bitmap(android.graphics.Bitmap) List(java.util.List) ArrayList(java.util.ArrayList) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader)

Example 49 with Contact

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

the class AppContactFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    final Cursor cursor = mAdapter.getCursor();
    // Moves to the Cursor row corresponding to the ListView item that was clicked
    cursor.moveToPosition(position);
    Contact contact = contactDatabase.getContact(cursor, "_id");
    if (contact.isBlocked()) {
        userUnBlockDialog(contact);
        return;
    }
    mOnContactSelectedListener.onCustomContactSelected(contact);
}
Also used : Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 50 with Contact

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

the class MobiComConversationService method read.

public void read(Contact contact, Channel channel) {
    try {
        int unreadCount = 0;
        if (contact != null) {
            Contact newContact = baseContactService.getContactById(contact.getContactIds());
            unreadCount = newContact.getUnreadCount();
            messageDatabaseService.updateReadStatusForContact(contact.getContactIds());
        } else if (channel != null) {
            Channel newChannel = channelService.getChannelByChannelKey(channel.getKey());
            unreadCount = newChannel.getUnreadCount();
            messageDatabaseService.updateReadStatusForChannel(String.valueOf(newChannel.getKey()));
        }
        Intent intent = new Intent(context, UserIntentService.class);
        intent.putExtra(UserIntentService.CONTACT, contact);
        intent.putExtra(UserIntentService.CHANNEL, channel);
        intent.putExtra(UserIntentService.UNREAD_COUNT, unreadCount);
        UserIntentService.enqueueWork(context, intent);
    } catch (Exception e) {
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) 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