Search in sources :

Example 61 with Contact

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

the class MobiComConversationFragment method updateChannelSubTitle.

public void updateChannelSubTitle() {
    channelUserMapperList = ChannelService.getInstance(getActivity()).getListOfUsersFromChannelUserMapper(channel.getKey());
    if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
        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) {
                    if (withUserContact.isBlocked()) {
                        ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("");
                    } else {
                        if (withUserContact.isConnected()) {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getActivity().getString(R.string.user_online));
                        } else if (withUserContact.getLastSeenAt() != 0) {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getActivity().getString(R.string.subtitle_last_seen_at_time) + " " + DateUtils.getDateAndTimeForLastSeen(withUserContact.getLastSeenAt()));
                        } else {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("");
                        }
                    }
                }
            }
        } else {
            StringBuffer stringBuffer = new StringBuffer();
            Contact contactDisplayName;
            String youString = null;
            int i = 0;
            for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
                i++;
                if (i > 20)
                    break;
                contactDisplayName = appContactService.getContactById(channelUserMapper.getUserKey());
                if (!TextUtils.isEmpty(channelUserMapper.getUserKey())) {
                    if (MobiComUserPreference.getInstance(getActivity()).getUserId().equals(channelUserMapper.getUserKey())) {
                        youString = getString(R.string.you_string);
                    } else {
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                }
            }
            if (!TextUtils.isEmpty(stringBuffer)) {
                if (channelUserMapperList.size() <= 20) {
                    if (!TextUtils.isEmpty(youString)) {
                        stringBuffer.append(youString).append(",");
                    }
                    int lastIndex = stringBuffer.lastIndexOf(",");
                    String userIds = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                    ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(userIds);
                } else {
                    ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(stringBuffer.toString());
                }
            } else {
                ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(youString);
            }
        }
    }
}
Also used : AppCompatActivity(android.support.v7.app.AppCompatActivity) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Collections.disjoint(java.util.Collections.disjoint) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 62 with Contact

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

the class Support method getSupportContact.

public Contact getSupportContact() {
    Contact contact = new Contact();
    contact.setFirstName("Support");
    contact.setLastName("");
    contact.setFullName("Support");
    contact.setContactNumber(getSupportNumber());
    contact.setFormattedContactNumber(getSupportNumber());
    return contact;
}
Also used : Contact(com.applozic.mobicommons.people.contact.Contact)

Example 63 with Contact

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

the class LoginActivity method buildContactData.

/**
 * Don't use this method...this is only for demo purpose..
 */
private void buildContactData() {
    Context context = getApplicationContext();
    AppContactService appContactService = new AppContactService(context);
    // avoid each time update ....
    if (!appContactService.isContactExists("adarshk")) {
        List<Contact> contactList = new ArrayList<Contact>();
        // Adarsh....
        Contact contact = new Contact();
        contact.setUserId("adarshk");
        contact.setFullName("John");
        contact.setImageURL("R.drawable.couple");
        contactList.add(contact);
        Contact contactRaj = new Contact();
        contactRaj.setUserId("raj");
        contactRaj.setFullName("rajni");
        contactRaj.setImageURL("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p200x200/12049601_556630871166455_1647160929759032778_n.jpg?oh=7ab819fc614f202e144cecaad0eb696b&oe=56EBA555&__gda__=1457202000_85552414c5142830db00c1571cc50641");
        contactList.add(contactRaj);
        // Adarsh
        Contact contact2 = new Contact();
        contact2.setUserId("rathan");
        contact2.setFullName("Liz");
        contact2.setImageURL("R.drawable.liz");
        contactList.add(contact2);
        Contact contact3 = new Contact();
        contact3.setUserId("clem");
        contact3.setFullName("Clement");
        contact3.setImageURL("R.drawable.shivam");
        contactList.add(contact3);
        Contact contact4 = new Contact();
        contact4.setUserId("shanki.gupta");
        contact4.setFullName("Bill");
        contact4.setImageURL("R.drawable.contact_shanki");
        contactList.add(contact4);
        Contact contact6 = new Contact();
        contact6.setUserId("krishna");
        contact6.setFullName("Krishi");
        contact6.setImageURL("R.drawable.girl");
        contactList.add(contact6);
        Contact contact7 = new Contact();
        contact7.setUserId("heather");
        contact7.setFullName("Heather");
        contact7.setImageURL("R.drawable.heather");
        contactList.add(contact7);
        appContactService.addAll(contactList);
    }
}
Also used : Context(android.content.Context) AppContactService(com.applozic.mobicomkit.contact.AppContactService) ArrayList(java.util.ArrayList) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 64 with Contact

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

the class MobiComConversationService method getAlConversationList.

/**
 * @deprecated This method is no longer used and will be deprecated soon.
 */
@Deprecated
public synchronized List<Message> getAlConversationList(int status, int pageSize, Long lastFetchTime, boolean makeServerCall) throws Exception {
    List<Message> conversationList = new ArrayList<>();
    List<Message> cachedConversationList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    if (!makeServerCall && !cachedConversationList.isEmpty()) {
        return cachedConversationList;
    }
    AlConversationResponse alConversationResponse = null;
    try {
        ApiResponse<AlConversationResponse> apiResponse = (ApiResponse<AlConversationResponse>) GsonUtils.getObjectFromJson(messageClientService.getAlConversationList(status, pageSize, lastFetchTime), new TypeToken<ApiResponse<AlConversationResponse>>() {
        }.getType());
        if (apiResponse != null) {
            alConversationResponse = apiResponse.getResponse();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    if (alConversationResponse == null) {
        return null;
    }
    try {
        if (alConversationResponse.getUserDetails() != null) {
            processUserDetails(alConversationResponse.getUserDetails());
        }
        if (alConversationResponse.getGroupFeeds() != null) {
            ChannelService.getInstance(context).processChannelFeedList(alConversationResponse.getGroupFeeds(), false);
        }
        Message[] messages = alConversationResponse.getMessage();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (messages != null && messages.length > 0 && cachedConversationList.size() > 0 && cachedConversationList.get(0).isLocalMessage()) {
            if (cachedConversationList.get(0).equals(messages[0])) {
                Utils.printLog(context, TAG, "Both messages are same.");
                deleteMessage(cachedConversationList.get(0));
            }
        }
        for (Message message : messages) {
            if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
                if (message.getTo() == null) {
                    continue;
                }
                if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(message);
                }
                if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(message);
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (isHideActionMessage && message.isActionMessage()) {
                    message.setHidden(true);
                }
                if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
                    messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
                } else {
                    messageDatabaseService.createMessage(message);
                }
                if (message.hasHideKey()) {
                    if (message.getGroupId() != null) {
                        Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                        if (newChannel != null) {
                            getMessagesWithNetworkMetaData(null, null, null, newChannel, null, true, false);
                        }
                    } else {
                        getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, false);
                    }
                }
            }
            conversationList.add(message);
        }
        Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    List<Message> finalMessageList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    List<String> messageKeys = new ArrayList<>();
    for (Message msg : finalMessageList) {
        if (msg.getTo() == null) {
            continue;
        }
        if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
            continue;
        }
        if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
    }
    if (messageKeys != null && messageKeys.size() > 0) {
        Message[] replyMessageList = getMessageListByKeyList(messageKeys);
        if (replyMessageList != null) {
            for (Message replyMessage : replyMessageList) {
                if (replyMessage.getTo() == null) {
                    continue;
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(replyMessage);
                }
                if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(replyMessage);
                }
                replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                messageDatabaseService.createMessage(replyMessage);
            }
        }
    }
    if (!conversationList.isEmpty()) {
        Collections.sort(conversationList, new Comparator<Message>() {

            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });
    }
    return finalMessageList;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) JsonSyntaxException(com.google.gson.JsonSyntaxException) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 65 with Contact

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

the class MessageClientService method processUserStatus.

public void processUserStatus(String userId, boolean isProfileImageUpdated) {
    try {
        UserDetail[] userDetails = getUserDetails(userId);
        if (userDetails != null) {
            for (UserDetail userDetail : userDetails) {
                Contact contact = new Contact();
                contact.setUserId(userDetail.getUserId());
                if (!TextUtils.isEmpty(userDetail.getDisplayName())) {
                    contact.setFullName(userDetail.getDisplayName());
                }
                contact.setConnected(userDetail.isConnected());
                contact.setContactNumber(userDetail.getPhoneNumber());
                contact.setLastSeenAt(userDetail.getLastSeenAtTime());
                contact.setImageURL(userDetail.getImageLink());
                contact.setStatus(userDetail.getStatusMessage());
                contact.setUserTypeId(userDetail.getUserTypeId());
                contact.setDeletedAtTime(userDetail.getDeletedAtTime());
                contact.setUnreadCount(0);
                contact.setRoleType(userDetail.getRoleType());
                contact.setMetadata(userDetail.getMetadata());
                contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
                baseContactService.upsert(contact);
            }
            if (isProfileImageUpdated) {
                BroadcastService.sendUpdateUserDetailBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_USER_DETAIL.toString(), userId);
            } else {
                BroadcastService.sendUpdateLastSeenAtTimeBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString(), userId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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