Search in sources :

Example 16 with Contact

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

the class ContactDatabaseTest method createDb.

@Before
public void createDb() {
    Context context = ApplicationProvider.getApplicationContext();
    dbHelper = new MobiComDatabaseHelper(context, null, null, MobiComDatabaseHelper.DB_VERSION);
    contactDatabase = new ContactDatabase(context, dbHelper);
    contact1 = new Contact();
    contact2 = new Contact();
    contact3 = new Contact();
    contact1.setUserId("userId");
    contact1.setImageURL("imageUrl");
    // contact1.setFirstName("name"); first name is not set when retrieving from db
    contact1.setBlocked(true);
    contact1.setBlockedBy(false);
    contact1.setApplicationId("applicationId");
    // these need to be added because of an inconsistency with null and 0
    contact1.setDeletedAtTime(0L);
    contact1.setContactId(0L);
    contact1.setUserTypeId((short) 0);
    contact1.setRoleType((short) 0);
    contact1.setNotificationAfterTime(0L);
    contact1.setLastSeenAt(0L);
    contact1.setContactType((short) 0);
    contact1.setUnreadCount(0);
    contact1.setLastMessageAtTime(0L);
    contact2 = new Contact();
    contact2.setUserId("userId1");
    contact2.setImageURL("imageUrl1");
    // contact2.setFirstName("name1"); first name is not set when retrieving from db
    contact2.setBlocked(false);
    contact2.setBlockedBy(true);
    contact2.setApplicationId("applicationId");
    // these need to be added because of an inconsistency with null and 0
    contact2.setDeletedAtTime(0L);
    contact2.setContactId(0L);
    contact2.setUserTypeId((short) 0);
    contact2.setRoleType((short) 0);
    contact2.setNotificationAfterTime(0L);
    contact2.setLastSeenAt(0L);
    contact2.setContactType((short) 0);
    contact2.setUnreadCount(0);
    contact2.setLastMessageAtTime(0L);
    contact3.setUserId("userId2");
    contact3.setImageURL("imageUrl2");
    // contact3.setFirstName("name2"); first name is not set when retrieving from db
    contact3.setBlocked(true);
    contact3.setBlockedBy(true);
    contact3.setApplicationId("applicationId");
    // these need to be added because of an inconsistency with null and 0
    contact3.setDeletedAtTime(0L);
    contact3.setContactId(0L);
    contact3.setUserTypeId((short) 0);
    contact3.setRoleType((short) 0);
    contact3.setNotificationAfterTime(0L);
    contact3.setLastSeenAt(0L);
    contact3.setContactType((short) 0);
    contact3.setUnreadCount(0);
    contact3.setLastMessageAtTime(0L);
}
Also used : Context(android.content.Context) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact) Before(org.junit.Before)

Example 17 with Contact

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

the class ChannelInfoActivity method addChannelUser.

public void addChannelUser(final String userId, final Channel channel) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this).setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            AlTask.execute(new ChannelMemberAdd(channel, userId, ChannelInfoActivity.this));
        }
    });
    alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    String name = "";
    String channelName = "";
    Contact contact;
    if (channel != null) {
        contact = baseContactService.getContactById(userId);
        name = contact.getDisplayName();
        channelName = channel.getName();
    }
    alertDialog.setMessage(getString(R.string.dialog_add_group_user).replace(getString(R.string.user_name_info), name).replace(getString(R.string.group_name_info), channelName));
    alertDialog.setCancelable(true);
    alertDialog.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 18 with Contact

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

the class MobiComKitBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Message message = null;
    String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
    if (!TextUtils.isEmpty(messageJson)) {
        message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
        if (message != null) {
            if (hideActionMessages && message.isActionMessage()) {
                message.setHidden(true);
            }
        }
    }
    Utils.printLog(context, TAG, "Received broadcast, action: " + action + ", message: " + message);
    if (message != null && !message.isSentToMany()) {
        conversationUIService.addMessage(message);
    } else if (message != null && message.isSentToMany() && BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
        for (String toField : message.getTo().split(",")) {
            Message singleMessage = new Message(message);
            singleMessage.setKeyString(message.getKeyString());
            singleMessage.setTo(toField);
            singleMessage.processContactIds(context);
            conversationUIService.addMessage(message);
        }
    }
    String keyString = intent.getStringExtra("keyString");
    String userId = message != null ? message.getContactIds() : "";
    if (BroadcastService.INTENT_ACTIONS.INSTRUCTION.toString().equals(action)) {
        InstructionUtil.showInstruction(context, intent.getIntExtra("resId", -1), intent.getBooleanExtra("actionable", false), R.color.instruction_color);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_CHANNEL_NAME.toString().equals(action)) {
        conversationUIService.updateChannelName();
    } else if (BroadcastService.INTENT_ACTIONS.FIRST_TIME_SYNC_COMPLETE.toString().equals(action)) {
        conversationUIService.downloadConversations(true);
    } else if (BroadcastService.INTENT_ACTIONS.LOAD_MORE.toString().equals(action)) {
        conversationUIService.setLoadMore(intent.getBooleanExtra("loadMore", true));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString().equals(action)) {
        conversationUIService.updateMessageKeyString(message);
    } else if (BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
        conversationUIService.syncMessages(message, keyString);
    } else if (BroadcastService.INTENT_ACTIONS.DELETE_MESSAGE.toString().equals(intent.getAction())) {
        userId = intent.getStringExtra("contactNumbers");
        conversationUIService.deleteMessage(keyString, userId);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY.toString().equals(action) || BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED.toString().equals(action)) {
        conversationUIService.updateDeliveryStatus(message, userId);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY_FOR_CONTACT.toString().equals(action)) {
        conversationUIService.updateDeliveryStatusForContact(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED_FOR_CONTECT.toString().equals(action)) {
        conversationUIService.updateReadStatusForContact(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString().equals(action)) {
        String contactNumber = intent.getStringExtra("contactNumber");
        Integer channelKey = intent.getIntExtra("channelKey", 0);
        String response = intent.getStringExtra("response");
        Contact contact = null;
        if (contactNumber != null) {
            contact = baseContactService.getContactById(contactNumber);
        }
        conversationUIService.deleteConversation(contact, channelKey, response);
    } else if (BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString().equals(action) && message != null) {
        conversationUIService.updateUploadFailedStatus(message);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_DONE.toString().equals(action) && message != null) {
        conversationUIService.updateDownloadStatus(message);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_FAILD.toString().equals(action) && message != null) {
        conversationUIService.updateDownloadFailed(message);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_TYPING_STATUS.toString().equals(action)) {
        String currentUserId = intent.getStringExtra("userId");
        String isTyping = intent.getStringExtra("isTyping");
        conversationUIService.updateTypingStatus(currentUserId, isTyping);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString().equals(action)) {
        conversationUIService.updateLastSeenStatus(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MQTT_DISCONNECTED.toString().equals(action)) {
        if (intent.getBooleanExtra("isMQTTReconnectionBroadcast", false)) {
            conversationUIService.reconnectMQTT();
        }
    } else if (BroadcastService.INTENT_ACTIONS.MQTT_CONNECTED.toString().equals(action)) {
        conversationUIService.onMqttConnected();
    } else if (BroadcastService.INTENT_ACTIONS.CHANNEL_SYNC.toString().equals(action)) {
        boolean isMetaDataUpdate = intent.getBooleanExtra("isMetadataUpdate", false);
        conversationUIService.updateChannelSync(isMetaDataUpdate);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString().equals(action)) {
        conversationUIService.updateTitleAndSubtitle();
    } else if (BroadcastService.INTENT_ACTIONS.CONVERSATION_READ.toString().equals(action)) {
        String currentId = intent.getStringExtra("currentId");
        boolean isGroup = intent.getBooleanExtra("isGroup", false);
        conversationUIService.updateConversationRead(currentId, isGroup);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_USER_DETAIL.toString().equals(action)) {
        conversationUIService.updateUserInfo(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_METADATA_UPDATE.toString().equals(action)) {
        String updateForUserId = intent.getStringExtra("userId");
        Integer groupId = intent.getIntExtra("groupId", 0);
        Boolean isOpenGroup = intent.getBooleanExtra("openGroup", false);
        String messageMetaDataJson = intent.getStringExtra("messageMetadata");
        Map<String, String> messageMetaData = null;
        if (!TextUtils.isEmpty(messageMetaDataJson)) {
            messageMetaData = (Map<String, String>) GsonUtils.getObjectFromJson(messageMetaDataJson, Map.class);
        }
        conversationUIService.updateMessageMetadata(keyString, updateForUserId, groupId, isOpenGroup, messageMetaData);
    } else if (BroadcastService.INTENT_ACTIONS.MUTE_USER_CHAT.toString().equals(action)) {
        conversationUIService.muteUserChat(intent.getBooleanExtra("mute", false), intent.getStringExtra("userId"));
    } else if (BroadcastService.INTENT_ACTIONS.GROUP_MUTE.toString().equals(action)) {
        conversationUIService.updateChannelMuteMenuOptionForGroupId(intent.getIntExtra("groupId", 0));
    } else if (BroadcastService.INTENT_ACTIONS.LOGGED_USER_DELETE.toString().equals(action)) {
        conversationUIService.updateLoggedUserDeletedUI();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 19 with Contact

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

the class ConversationUIService method getConversationFragment.

public ConversationFragment getConversationFragment() {
    ConversationFragment conversationFragment = (ConversationFragment) UIService.getFragmentByTag(fragmentActivity, CONVERSATION_FRAGMENT);
    if (conversationFragment == null) {
        Contact contact = ((ConversationActivity) fragmentActivity).getContact();
        Channel channel = ((ConversationActivity) fragmentActivity).getChannel();
        Integer conversationId = ((ConversationActivity) fragmentActivity).getConversationId();
        conversationFragment = ConversationFragment.newInstance(contact, channel, conversationId, null, null);
        ConversationActivity.addFragment(fragmentActivity, conversationFragment, CONVERSATION_FRAGMENT);
    }
    return conversationFragment;
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) Channel(com.applozic.mobicommons.people.channel.Channel) MobiComQuickConversationFragment(com.applozic.mobicomkit.uiwidgets.conversation.fragment.MobiComQuickConversationFragment) ConversationFragment(com.applozic.mobicomkit.uiwidgets.conversation.fragment.ConversationFragment) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 20 with Contact

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

the class MentionHelper method getMessageSpannableStringForMentionsDisplay.

@NonNull
private static Spannable getMessageSpannableStringForMentionsDisplay(Context context, String messageStringWithMentionsUserId, List<MentionMetadataModel> mentionMetadataModels, boolean isDetailedConversationList, int detailedSpanColor) {
    if (TextUtils.isEmpty(messageStringWithMentionsUserId)) {
        return new SpannableString(Utils.EMPTY_STRING);
    }
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(messageStringWithMentionsUserId);
    if (mentionMetadataModels == null) {
        return spannableStringBuilder;
    }
    try {
        // the list must be sorted in descending order position of mention to avoid the side-effect of replacing with indexes
        Collections.sort(mentionMetadataModels, new Comparator<MentionMetadataModel>() {

            @Override
            public int compare(MentionMetadataModel o1, MentionMetadataModel o2) {
                int comparatorValue = 0;
                if (o1.indices[0] > o2.indices[0]) {
                    comparatorValue = -1;
                } else if (o1.indices[0] < o2.indices[0]) {
                    comparatorValue = +1;
                }
                return comparatorValue;
            }
        });
    } catch (NullPointerException | IndexOutOfBoundsException exception) {
        exception.printStackTrace();
        return spannableStringBuilder;
    }
    for (MentionMetadataModel metadataModel : mentionMetadataModels) {
        if (metadataModel == null || TextUtils.isEmpty(metadataModel.userId) || metadataModel.indices == null || metadataModel.indices.length < 2) {
            continue;
        }
        int start = metadataModel.indices[0];
        Contact contact = new AppContactService(context).getContactById(metadataModel.userId);
        String userIdOrDisplayName = !TextUtils.isEmpty(contact.getDisplayName()) ? contact.getDisplayName() : contact.getUserId();
        int end = metadataModel.indices[1];
        int replacedEnd = metadataModel.indices[0] + userIdOrDisplayName.length();
        int length = spannableStringBuilder.length();
        if (start >= 0 && start < length && end >= 0 && end - 1 < length) {
            spannableStringBuilder.replace(start + 1, end, userIdOrDisplayName);
        } else {
            continue;
        }
        int replacedLength = spannableStringBuilder.length();
        if (start < replacedLength && replacedEnd >= 0 && replacedEnd < replacedLength) {
            CharacterStyle characterStyle = isDetailedConversationList ? new ReceivedDetailedConversationMessageMentionDisplaySpan(detailedSpanColor) : new ReceivedQuickConversationMessageMentionDisplaySpan();
            spannableStringBuilder.setSpan(characterStyle, start, replacedEnd + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableStringBuilder;
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) SpannableString(android.text.SpannableString) MentionMetadataModel(com.applozic.mobicomkit.api.conversation.MentionMetadataModel) CharacterStyle(android.text.style.CharacterStyle) Contact(com.applozic.mobicommons.people.contact.Contact) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder) NonNull(androidx.annotation.NonNull)

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