Search in sources :

Example 96 with Contact

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

the class ChannelInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.channel_info_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    refreshBroadcast = new RefreshBroadcast();
    baseContactService = new AppContactService(getApplicationContext());
    channelImage = (ImageView) findViewById(R.id.channelImage);
    userPreference = MobiComUserPreference.getInstance(this);
    createdBy = (TextView) findViewById(R.id.created_by);
    groupParticipantsTexView = (TextView) findViewById(R.id.groupParticipantsTexView);
    exitChannelButton = (Button) findViewById(R.id.exit_channel);
    deleteChannelButton = (Button) findViewById(R.id.delete_channel_button);
    channelDeleteRelativeLayout = (RelativeLayout) findViewById(R.id.channel_delete_relativeLayout);
    channelExitRelativeLayout = (RelativeLayout) findViewById(R.id.channel_exit_relativeLayout);
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
    nestedScrollView = findViewById(R.id.nestedScrollView);
    textViewGroupDescription = findViewById(R.id.groupDescriptionTexView);
    cardViewGroupDescriptionContainer = findViewById(R.id.groupDescriptionCardView);
    collapsingToolbarLayout.setContentScrimColor(Color.parseColor(alCustomizationSettings.getCollapsingToolbarLayoutColor()));
    groupParticipantsTexView.setTextColor(Color.parseColor(alCustomizationSettings.getGroupParticipantsTextColor()));
    deleteChannelButton.setBackgroundColor(Color.parseColor((alCustomizationSettings.getGroupDeleteButtonBackgroundColor())));
    exitChannelButton.setBackgroundColor(Color.parseColor(alCustomizationSettings.getGroupExitButtonBackgroundColor()));
    mActionBar = getSupportActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mActionBar.setHomeButtonEnabled(true);
    mActionBar.setDisplayShowHomeEnabled(true);
    mainListView = (ListView) findViewById(R.id.mainList);
    mainListView.setLongClickable(true);
    mainListView.setSmoothScrollbarEnabled(true);
    if (Utils.hasLollipop()) {
        mainListView.setNestedScrollingEnabled(true);
    }
    nestedScrollView.post(new Runnable() {

        @Override
        public void run() {
            nestedScrollView.scrollTo(nestedScrollView.getLeft(), groupParticipantsTexView.getTop());
        }
    });
    connectivityReceiver = new ConnectivityReceiver();
    mobiComKitBroadcastReceiver = new MobiComKitBroadcastReceiver(this);
    registerForContextMenu(mainListView);
    if (alCustomizationSettings.isHideGroupExitButton()) {
        channelExitRelativeLayout.setVisibility(View.GONE);
    }
    if (alCustomizationSettings.isHideGroupDeleteButton()) {
        channelDeleteRelativeLayout.setVisibility(View.GONE);
    }
    if (getIntent().getExtras() != null) {
        channelKey = getIntent().getIntExtra(CHANNEL_KEY, 0);
        channelUpdateReceiver = getIntent().getParcelableExtra(CHANNEL_UPDATE_RECEIVER);
        channel = ChannelService.getInstance(this).getChannelByChannelKey(channelKey);
        isUserPresent = ChannelService.getInstance(this).processIsUserPresentInChannel(channelKey);
        if (channel != null) {
            String title = ChannelUtils.getChannelTitleName(channel, userPreference.getUserId());
            if (!TextUtils.isEmpty(channel.getAdminKey())) {
                contact = baseContactService.getContactById(channel.getAdminKey());
                mActionBar.setTitle(title);
                if (userPreference.getUserId().equals(contact.getUserId())) {
                    createdBy.setText(getString(R.string.channel_created_by) + " " + getString(R.string.you_string));
                } else {
                    createdBy.setText(getString(R.string.channel_created_by) + " " + contact.getDisplayName());
                }
            }
            updateChannelDescriptionUIFrom(channel.getMetadata());
            if (!isUserPresent) {
                channelExitRelativeLayout.setVisibility(View.GONE);
                channelDeleteRelativeLayout.setVisibility(View.VISIBLE);
            }
        }
    }
    if (channel != null && channel.getType() != null) {
        if (Channel.GroupType.BROADCAST.getValue().equals(channel.getType())) {
            deleteChannelButton.setText(R.string.broadcast_delete_button);
            exitChannelButton.setText(R.string.broadcast_exit_button);
            channelExitRelativeLayout.setVisibility(View.GONE);
            channelDeleteRelativeLayout.setVisibility(View.VISIBLE);
        } else {
            deleteChannelButton.setText(R.string.channel_delete_group_button);
            exitChannelButton.setText(R.string.channel_exit_button);
        }
    }
    contactImageLoader = new ImageLoader(getApplicationContext(), getListPreferredItemHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return baseContactService.downloadContactImage(getApplicationContext(), (Contact) data);
        }
    };
    contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
    contactImageLoader.addImageCache(this.getSupportFragmentManager(), 0.1f);
    contactImageLoader.setImageFadeIn(false);
    channelImageLoader = new ImageLoader(getApplicationContext(), getListPreferredItemHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return baseContactService.downloadGroupImage(getApplicationContext(), (Channel) data);
        }
    };
    channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
    channelImageLoader.addImageCache(this.getSupportFragmentManager(), 0.1f);
    channelImageLoader.setImageFadeIn(false);
    if (channelImage != null && !channel.isBroadcastMessage()) {
        channelImageLoader.loadImage(channel, channelImage);
    } else {
        channelImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
    }
    channelUserMapperList = ChannelService.getInstance(this).getListOfUsersFromChannelUserMapper(channel.getKey());
    contactsAdapter = new ContactsAdapter(this);
    mainListView.setAdapter(contactsAdapter);
    Helper.getListViewSize(mainListView);
    mainListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause image loader to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                contactImageLoader.setPauseWork(true);
            } else {
                contactImageLoader.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i1, int i2) {
        }
    });
    exitChannelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            leaveChannel(channel);
        }
    });
    deleteChannelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            deleteChannel(channel);
        }
    });
    cardViewGroupDescriptionContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isUserPresent && alCustomizationSettings.isEditChannelDescriptionAllowed() && channel != null) {
                Intent editChannelNameIntent = new Intent(ChannelInfoActivity.this, EditChannelDescriptionActivity.class);
                GroupInfoUpdate groupInfoUpdate = new GroupInfoUpdate(channel.getMetadata(), channel.getKey());
                String groupJson = GsonUtils.getJsonFromObject(groupInfoUpdate, GroupInfoUpdate.class);
                editChannelNameIntent.putExtra(GROUP_UPDTAE_INFO, groupJson);
                startActivityForResult(editChannelNameIntent, REQUEST_CODE_FOR_CHANNEL_NEW_DESCRIPTION);
            } else {
                Toast.makeText(ChannelInfoActivity.this, alCustomizationSettings.isEditChannelDescriptionAllowed() ? getString(R.string.channel_edit_description_alert) : getString(R.string.editing_channel_description_is_not_allowed), Toast.LENGTH_SHORT).show();
            }
        }
    });
    registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
Also used : GroupInfoUpdate(com.applozic.mobicomkit.feed.GroupInfoUpdate) IntentFilter(android.content.IntentFilter) AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) AppContactService(com.applozic.mobicomkit.contact.AppContactService) ConnectivityReceiver(com.applozic.mobicomkit.broadcast.ConnectivityReceiver) Channel(com.applozic.mobicommons.people.channel.Channel) AbsListView(android.widget.AbsListView) MobiComKitBroadcastReceiver(com.applozic.mobicomkit.uiwidgets.conversation.MobiComKitBroadcastReceiver) Intent(android.content.Intent) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader) Toolbar(androidx.appcompat.widget.Toolbar)

Example 97 with Contact

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

the class QuickConversationAdapter method getSenderNameWithSeparator.

private String getSenderNameWithSeparator(Message message) {
    final String SEPARATOR = ": ";
    List<String> senderIds = message.getSenderIdListFor();
    if (senderIds != null && !senderIds.isEmpty()) {
        String senderUserId = senderIds.get(0);
        String nameToDisplay = senderUserId;
        if (contactService == null) {
            Log.d(TAG, "AppContactService for the class is null.");
            return nameToDisplay;
        }
        Contact senderContact = contactService.getContactById(senderUserId);
        nameToDisplay = !TextUtils.isEmpty(senderContact.getDisplayName()) ? senderContact.getDisplayName() : !TextUtils.isEmpty(senderContact.getFullName()) ? senderContact.getFullName() : nameToDisplay;
        return nameToDisplay + SEPARATOR;
    } else {
        return null;
    }
}
Also used : SpannableString(android.text.SpannableString) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 98 with Contact

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

the class ConversationFragment method onCreateView.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.title = getResources().getString(R.string.chats);
    this.conversationService = new MobiComConversationService(getActivity());
    hideExtendedSendingOptionLayout = true;
    View view = super.onCreateView(inflater, container, savedInstanceState);
    populateAttachmentOptions();
    conversationCallbackHandler = new ConversationCallbackHandler(getContext(), this);
    if (alCustomizationSettings.isHideAttachmentButton()) {
        attachButton.setVisibility(View.GONE);
        messageEditText.setPadding(20, 0, 0, 0);
    }
    sendType.setSelection(1);
    messageEditText.setHint(R.string.enter_message_hint);
    multimediaPopupGrid.setVisibility(View.GONE);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.secret_message_timer_array, R.layout.mobiframework_custom_spinner);
    adapter.setDropDownViewResource(R.layout.mobiframework_custom_spinner);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
    messageEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            multimediaPopupGrid.setVisibility(View.GONE);
        }
    });
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (contact != null && !contact.isBlocked() || channel != null) {
                if (attachmentLayout.getVisibility() == View.VISIBLE) {
                    Toast.makeText(getActivity(), R.string.select_file_count_limit, Toast.LENGTH_LONG).show();
                    return;
                }
            }
            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.isBlocked()) {
                            userBlockDialog(false, withUserContact, true);
                        } else {
                            processAttachButtonClick(view);
                        }
                    }
                } else {
                    processAttachButtonClick(view);
                }
            } else if (contact != null) {
                if (contact.isBlocked()) {
                    userBlockDialog(false, contact, false);
                } else {
                    processAttachButtonClick(view);
                }
            }
        }
    });
    return view;
}
Also used : ConversationCallbackHandler(com.applozic.mobicomkit.uiwidgets.conversation.ConversationCallbackHandler) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) View(android.view.View) MultimediaOptionsGridView(com.applozic.mobicomkit.uiwidgets.conversation.MultimediaOptionsGridView) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 99 with Contact

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

the class ConversationUIService method deleteConversationThread.

public void deleteConversationThread(final Contact contact, final Channel channel) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(fragmentActivity).setPositiveButton(R.string.delete_conversation, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            AlTask.execute(new DeleteConversationAsyncTask(new MobiComConversationService(fragmentActivity), contact, channel, null, fragmentActivity));
        }
    });
    alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    String name = "";
    if (channel != null) {
        if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
            String userId = ChannelService.getInstance(fragmentActivity).getGroupOfTwoReceiverUserId(channel.getKey());
            if (!TextUtils.isEmpty(userId)) {
                Contact withUserContact = baseContactService.getContactById(userId);
                name = withUserContact.getDisplayName();
            }
        } else {
            name = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(fragmentActivity).getUserId());
        }
    } else if (contact != null) {
        name = contact.getDisplayName();
    }
    alertDialog.setTitle(fragmentActivity.getString(R.string.dialog_delete_conversation_title).replace("[name]", name));
    alertDialog.setMessage(fragmentActivity.getString(R.string.dialog_delete_conversation_confir).replace("[name]", name));
    alertDialog.setCancelable(true);
    alertDialog.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 100 with Contact

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

the class ConversationUIService method checkForStartNewConversation.

public void checkForStartNewConversation(Intent intent) {
    Contact contact = null;
    Channel channel = null;
    Integer conversationId = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.getType() != null) {
        if ("text/plain".equals(intent.getType())) {
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (sharedText != null) {
                startContactActivityForResult(null, sharedText);
            }
        } else if (intent.getType().startsWith("image/")) {
        // Todo: use this for image forwarding
        }
    }
    Integer channelKey = intent.getIntExtra(GROUP_ID, -1);
    String clientGroupId = intent.getStringExtra(CLIENT_GROUP_ID);
    String channelName = intent.getStringExtra(GROUP_NAME);
    if (!TextUtils.isEmpty(clientGroupId)) {
        channel = ChannelService.getInstance(fragmentActivity).getChannelByClientGroupId(clientGroupId);
        if (channel == null) {
            return;
        }
    } else if (channelKey != -1 && channelKey != null && channelKey != 0) {
        channel = ChannelService.getInstance(fragmentActivity).getChannel(channelKey);
    }
    if (channel != null && !TextUtils.isEmpty(channelName) && TextUtils.isEmpty(channel.getName())) {
        channel.setName(channelName);
        ChannelService.getInstance(fragmentActivity).updateChannel(channel);
    }
    String userId = intent.getStringExtra(USER_ID);
    String fullName = intent.getStringExtra(DISPLAY_NAME);
    if (!TextUtils.isEmpty(userId)) {
        contact = baseContactService.getContactById(userId);
        if (contact != null) {
            if (!TextUtils.isEmpty(fullName)) {
                Map<String, String> metadata = contact.getMetadata();
                if (metadata == null) {
                    metadata = new HashMap<>();
                    metadata.put(Contact.AL_DISPLAY_NAME_UPDATED, "false");
                    contact.setMetadata(metadata);
                } else if (!metadata.isEmpty() && !fullName.equals(contact.getDisplayName())) {
                    metadata.put(Contact.AL_DISPLAY_NAME_UPDATED, "false");
                    contact.setMetadata(metadata);
                }
            }
            if (!TextUtils.isEmpty(fullName)) {
                contact.setFullName(fullName);
            }
        }
        String applicationId = intent.getStringExtra(APPLICATION_ID);
        if (contact != null) {
            contact.setApplicationId(applicationId);
        }
        baseContactService.upsert(contact);
    }
    String searchString = intent.getStringExtra(SEARCH_STRING);
    String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
    if (!TextUtils.isEmpty(messageJson)) {
        Message message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
        if (message.getGroupId() != null) {
            channel = ChannelService.getInstance(fragmentActivity).getChannelByChannelKey(message.getGroupId());
            if (channel.getParentKey() != null && channel.getParentKey() != 0) {
                BroadcastService.parentGroupKey = channel.getParentKey();
                MobiComUserPreference.getInstance(fragmentActivity).setParentGroupKey(channel.getParentKey());
            }
        } else {
            contact = baseContactService.getContactById(message.getContactIds());
        }
        conversationId = message.getConversationId();
    }
    if (conversationId == null) {
        conversationId = intent.getIntExtra(CONVERSATION_ID, 0);
    }
    if (conversationId != 0 && conversationId != null && getConversationFragment() != null) {
        getConversationFragment().setConversationId(conversationId);
    } else {
        conversationId = null;
    }
    String defaultText = intent.getStringExtra(ConversationUIService.DEFAULT_TEXT);
    if (!TextUtils.isEmpty(defaultText) && getConversationFragment() != null) {
        getConversationFragment().setDefaultText(defaultText);
    }
    String forwardMessage = intent.getStringExtra(MobiComKitPeopleActivity.FORWARD_MESSAGE);
    if (!TextUtils.isEmpty(forwardMessage)) {
        Message messageToForward = (Message) GsonUtils.getObjectFromJson(forwardMessage, Message.class);
        if (getConversationFragment() != null) {
            getConversationFragment().forwardMessage(messageToForward, contact, channel);
        }
    }
    if (contact != null) {
        openConversationFragment(contact, conversationId, searchString, fullName);
    }
    if (channel != null) {
        openConversationFragment(channel, conversationId, searchString, fullName);
    }
    String productTopicId = intent.getStringExtra(ConversationUIService.PRODUCT_TOPIC_ID);
    String productImageUrl = intent.getStringExtra(ConversationUIService.PRODUCT_IMAGE_URL);
    if (!TextUtils.isEmpty(productTopicId) && !TextUtils.isEmpty(productImageUrl)) {
        try {
            FileMeta fileMeta = new FileMeta();
            fileMeta.setContentType("image");
            fileMeta.setBlobKeyString(productImageUrl);
            if (getConversationFragment() != null) {
                getConversationFragment().sendProductMessage(productTopicId, fileMeta, contact, Message.ContentType.TEXT_URL.getValue());
            }
        } catch (Exception e) {
        }
    }
    String sharedText = intent.getStringExtra(MobiComKitPeopleActivity.SHARED_TEXT);
    if (!TextUtils.isEmpty(sharedText) && getConversationFragment() != null) {
        getConversationFragment().sendMessage(sharedText);
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) 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