Search in sources :

Example 1 with ContactDatabase

use of com.applozic.mobicomkit.contact.database.ContactDatabase 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);
            applozicGetMemberFromContactGroupTask.execute();
        } 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(), "Failed to load contacts : Response : " + response + "\nException : " + e, Toast.LENGTH_SHORT).show();
            }
        };
        if (MobiComUserPreference.getInstance(getContext()).isContactGroupNameList()) {
            new AlGetMembersFromContactGroupListTask(getContext(), listener, null, groupList, "9").execute();
        } else {
            new AlGetMembersFromContactGroupListTask(getContext(), listener, groupList, null, "9").execute();
        }
    }
}
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 2 with ContactDatabase

use of com.applozic.mobicomkit.contact.database.ContactDatabase in project Applozic-Android-SDK by AppLozic.

the class ContactSelectionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_select_layout);
    contactDatabase = new ContactDatabase(this);
    contactSelectionFragment = new ContactSelectionFragment();
    setSearchListFragment(contactSelectionFragment);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    contactService = new AppContactService(this);
    mActionBar = getSupportActionBar();
    String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    if (!TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimary()) && !TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimaryDark())) {
        mActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(alCustomizationSettings.getThemeColorPrimary())));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.parseColor(alCustomizationSettings.getThemeColorPrimaryDark()));
        }
    }
    mActionBar.setDisplayShowHomeEnabled(true);
    mActionBar.setDisplayHomeAsUpEnabled(true);
    if (getIntent().getExtras() != null) {
        channel = (Channel) getIntent().getSerializableExtra(CHANNEL_OBJECT);
        disableCheckBox = getIntent().getBooleanExtra(CHECK_BOX, false);
        mActionBar.setTitle(R.string.channel_member_title);
        name = getIntent().getStringExtra(CHANNEL);
        imageUrl = getIntent().getStringExtra(IMAGE_LINK);
        groupType = getIntent().getIntExtra(GROUP_TYPE, Channel.GroupType.PUBLIC.getValue().intValue());
    } else {
        mActionBar.setTitle(R.string.channel_members_title);
    }
    Bundle bundle = new Bundle();
    bundle.putSerializable(CHANNEL_OBJECT, channel);
    bundle.putBoolean(CHECK_BOX, disableCheckBox);
    bundle.putString(CHANNEL, name);
    bundle.putString(IMAGE_LINK, imageUrl);
    bundle.putInt(GROUP_TYPE, groupType);
    contactSelectionFragment.setArguments(bundle);
    addFragment(this, contactSelectionFragment, "ContactSelectionFragment");
    connectivityReceiver = new ConnectivityReceiver();
    registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
Also used : IntentFilter(android.content.IntentFilter) AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) AppContactService(com.applozic.mobicomkit.contact.AppContactService) ColorDrawable(android.graphics.drawable.ColorDrawable) Bundle(android.os.Bundle) ConnectivityReceiver(com.applozic.mobicomkit.broadcast.ConnectivityReceiver) ContactSelectionFragment(com.applozic.mobicomkit.uiwidgets.people.contact.ContactSelectionFragment) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with ContactDatabase

use of com.applozic.mobicomkit.contact.database.ContactDatabase in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method addMTMessage.

public Contact addMTMessage(Message message) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    Contact receiverContact = null;
    message.processContactIds(context);
    String currentId = message.getCurrentId();
    if (message.getGroupId() == null) {
        receiverContact = baseContactService.getContactById(message.getContactIds());
    }
    if (message.getMessage() != null && PersonalizedMessage.isPersonalized(message.getMessage())) {
        message.setMessage(PersonalizedMessage.prepareMessageFromTemplate(message.getMessage(), receiverContact));
    }
    messageDatabaseService.createMessage(message);
    // Check if we are........container is already opened...don't send broadcast
    boolean isContainerOpened;
    if (message.getConversationId() != null && BroadcastService.isContextBasedChatEnabled()) {
        if (BroadcastService.currentConversationId == null) {
            BroadcastService.currentConversationId = message.getConversationId();
        }
        isContainerOpened = (currentId.equals(BroadcastService.currentUserId) && message.getConversationId().equals(BroadcastService.currentConversationId));
    } else {
        isContainerOpened = currentId.equals(BroadcastService.currentUserId);
    }
    if (message.isVideoNotificationMessage()) {
        Utils.printLog(context, TAG, "Got notifications for Video call...");
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
        helper.handleVideoCallNotificationMessages(message);
    } else if (message.isVideoCallMessage()) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper.buildVideoCallNotification(context, message);
    } else if (!isContainerOpened) {
        if (message.isConsideredForCount()) {
            if (message.getTo() != null && message.getGroupId() == null) {
                messageDatabaseService.updateContactUnreadCount(message.getTo());
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Contact contact = new ContactDatabase(context).getContactById(message.getTo());
                if (contact != null && !contact.isNotificationMuted()) {
                    sendNotification(message);
                }
            }
            if (message.getGroupId() != null && !Message.GroupMessageMetaData.FALSE.getValue().equals(message.getMetaDataValueForKey(Message.GroupMessageMetaData.KEY.getValue()))) {
                if (!Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType())) {
                    messageDatabaseService.updateChannelUnreadCount(message.getGroupId());
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Channel currentChannel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
                if (currentChannel != null && !currentChannel.isNotificationMuted()) {
                    sendNotification(message);
                }
            }
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        } else {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        }
    } else {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    Utils.printLog(context, TAG, "Updating delivery status: " + message.getPairedMessageKeyString() + ", " + userPreferences.getUserId() + ", " + userPreferences.getContactNumber());
    messageClientService.updateDeliveryStatus(message.getPairedMessageKeyString(), userPreferences.getUserId(), userPreferences.getContactNumber());
    return receiverContact;
}
Also used : VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 4 with ContactDatabase

use of com.applozic.mobicomkit.contact.database.ContactDatabase in project Applozic-Android-SDK by AppLozic.

the class SyncCallService method syncMutedUserList.

public synchronized void syncMutedUserList(boolean isFromFcm, String userId) {
    if (userId == null) {
        Utils.printLog(context, TAG, "Syncing muted user list from " + (isFromFcm ? "FCM" : "MQTT"));
        Intent intent = new Intent(context, ConversationIntentService.class);
        intent.putExtra(ConversationIntentService.MUTED_USER_LIST_SYNC, true);
        ConversationIntentService.enqueueWork(context, intent);
    } else {
        Utils.printLog(context, TAG, "Unmuting userId : " + userId + " from " + (isFromFcm ? "FCM" : "MQTT"));
        new ContactDatabase(context).updateNotificationAfterTime(userId, Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime().getTime());
        BroadcastService.sendMuteUserBroadcast(context, BroadcastService.INTENT_ACTIONS.MUTE_USER_CHAT.toString(), false, userId);
    }
}
Also used : Intent(android.content.Intent) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase)

Example 5 with ContactDatabase

use of com.applozic.mobicomkit.contact.database.ContactDatabase in project Applozic-Android-SDK by AppLozic.

the class ContactSelectionFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bundle = getArguments();
    String jsonString = FileUtils.loadSettingsJsonFile(getActivity().getApplicationContext());
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    userPreference = MobiComUserPreference.getInstance(getActivity());
    if (bundle != null) {
        channel = (Channel) bundle.getSerializable(CHANNEL_OBJECT);
        disableCheckBox = bundle.getBoolean(CHECK_BOX, false);
        channelName = bundle.getString(CHANNEL);
        imageUrl = bundle.getString(IMAGE_LINK);
        groupType = bundle.getInt(GROUP_TYPE);
        contactsGroupId = userPreference.getContactsGroupId();
    }
    setHasOptionsMenu(true);
    refreshContactsScreenBroadcast = new RefreshContactsScreenBroadcast();
    if (savedInstanceState != null) {
        mSearchTerm = savedInstanceState.getString(SearchManager.QUERY);
        mPreviouslySelectedSearchItem = savedInstanceState.getInt(STATE_PREVIOUSLY_SELECTED_KEY, 0);
    }
    contactDatabase = new ContactDatabase(getContext());
    appContactService = new AppContactService(getActivity());
    mAdapter = new ContactsAdapter(getActivity());
    final Context context = getActivity().getApplicationContext();
    mImageLoader = new ImageLoader(context, getListPreferredItemHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return appContactService.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 (contactsGroupId != null) {
        ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(context);
        groupContacts = channelDatabaseService.getChannelMemberByName(contactsGroupId, String.valueOf(Channel.GroupType.CONTACT_GROUP.getValue()));
        if (Utils.isInternetAvailable(getContext())) {
            ApplozicGetMemberFromContactGroupTask.GroupMemberListener eventMemberListener = new ApplozicGetMemberFromContactGroupTask.GroupMemberListener() {

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

                @Override
                public void onFailure(String response, Context context) {
                }
            };
            // pass GroupId whose contact Members you want to show, contactGroupType
            ApplozicGetMemberFromContactGroupTask applozicGetMemberFromContactGroupTask = new ApplozicGetMemberFromContactGroupTask(getActivity(), contactsGroupId, String.valueOf(Channel.GroupType.CONTACT_GROUP.getValue()), eventMemberListener);
            applozicGetMemberFromContactGroupTask.execute();
        } else if (groupContacts != null) {
            getLoaderManager().initLoader(ContactsQuery.QUERY_ID, null, ContactSelectionFragment.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();
                groupContacts = contactList;
                getLoaderManager().initLoader(ContactSelectionFragment.ContactsQuery.QUERY_ID, null, ContactSelectionFragment.this);
            }

            @Override
            public void onFailure(Context context, String response, Exception e) {
                progressBar.dismiss();
                Toast.makeText(getContext(), "Failed to load contacts : Response : " + response + "\nException : " + e, Toast.LENGTH_SHORT).show();
            }
        };
        if (MobiComUserPreference.getInstance(getContext()).isContactGroupNameList()) {
            new AlGetMembersFromContactGroupListTask(getContext(), listener, null, groupList, "9").execute();
        } else {
            new AlGetMembersFromContactGroupListTask(getContext(), listener, groupList, null, "9").execute();
        }
    }
}
Also used : Context(android.content.Context) AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) 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)

Aggregations

ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)5 AppContactService (com.applozic.mobicomkit.contact.AppContactService)3 Contact (com.applozic.mobicommons.people.contact.Contact)3 ProgressDialog (android.app.ProgressDialog)2 Context (android.content.Context)2 Bitmap (android.graphics.Bitmap)2 SpannableString (android.text.SpannableString)2 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)2 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)2 AlGetMembersFromContactGroupListTask (com.applozic.mobicomkit.uiwidgets.async.AlGetMembersFromContactGroupListTask)2 ApplozicGetMemberFromContactGroupTask (com.applozic.mobicomkit.uiwidgets.async.ApplozicGetMemberFromContactGroupTask)2 ImageLoader (com.applozic.mobicommons.commons.image.ImageLoader)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Bundle (android.os.Bundle)1 Toolbar (android.support.v7.widget.Toolbar)1 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)1