Search in sources :

Example 1 with ChannelDatabaseService

use of com.applozic.mobicomkit.channel.database.ChannelDatabaseService in project Applozic-Android-SDK by AppLozic.

the class MentionHelper method getMentionsListForChannel.

@NonNull
public static List<Mention> getMentionsListForChannel(Context context, Integer channelKey) {
    ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(context);
    List<ChannelUserMapper> channelUserMapperList = channelDatabaseService.getChannelUserList(channelKey);
    if (channelUserMapperList == null) {
        return new ArrayList<>();
    }
    List<Mention> mentionUsersList = new ArrayList<>();
    AppContactService appContactService = new AppContactService(context);
    String currentUserId = MobiComUserPreference.getInstance(context).getUserId();
    for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
        Contact contact = appContactService.getContactById(channelUserMapper.getUserKey());
        if (channelUserMapper.getUserKey().equals(currentUserId)) {
            continue;
        }
        if (contact != null && !TextUtils.isEmpty(contact.getUserId())) {
            mentionUsersList.add(new Mention(contact.getUserId(), contact.getDisplayName(), !TextUtils.isEmpty(contact.getLocalImageUrl()) ? contact.getLocalImageUrl() : contact.getImageURL()));
        } else {
            mentionUsersList.add(new Mention(channelUserMapper.getUserKey()));
        }
    }
    return mentionUsersList;
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Example 2 with ChannelDatabaseService

use of com.applozic.mobicomkit.channel.database.ChannelDatabaseService 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 3 with ChannelDatabaseService

use of com.applozic.mobicomkit.channel.database.ChannelDatabaseService in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseServiceTest method addAndRetrieveChannelUserMapper.

// ChannelUserMapper methods >>
// addChannelUserMapper, getChannelUserByChannelKeyAndUserId, getChannelUserList, getChannelByChannelKey, getGroupOfTwoChannelUserId
@Test
public void addAndRetrieveChannelUserMapper() {
    channelDatabaseService.addChannelUserMapper(channelUserMapper);
    channelDatabaseService.addChannelUserMapper(channelUserMapper1);
    channelDatabaseService.addChannelUserMapper(channelUserMapper2);
    assertThat(channelDatabaseService.getChannelUserByChannelKeyAndUserId(channel1.getKey(), "clientId").toString()).isEqualTo(channelUserMapper.toString());
    assertThat(channelDatabaseService.getChannelUserByChannelKeyAndUserId(channel1.getKey(), "clientId1").toString()).isEqualTo(channelUserMapper1.toString());
    assertThat(channelDatabaseService.getChannelByChannelKey(channel2.getKey())).isNull();
    List<ChannelUserMapper> channelUserMappersChannel1 = channelDatabaseService.getChannelUserList(channel1.getKey());
    List<ChannelUserMapper> channelUserMappersChannel2 = channelDatabaseService.getChannelUserList(channel2.getKey());
    assertThat(channelUserMappersChannel1.get(0).toString()).isEqualTo(channelUserMapper.toString());
    assertThat(channelUserMappersChannel1.get(1).toString()).isEqualTo(channelUserMapper1.toString());
    assertThat(channelUserMappersChannel2.get(0).toString()).isEqualTo(channelUserMapper2.toString());
    // get group of two channel user id, NOTE: the function needed to be tampered to provide getting the logged in user id
    // Reason: MobicomUserPreference is used inside the function
    // I have tested it by manually providing a mock userId
    ChannelDatabaseService channelDatabaseService = Mockito.mock(ChannelDatabaseService.class);
    String userKey = channelDatabaseService.getGroupOfTwoReceiverId(channel1.getKey());
// assertThat(userKey).isEqualTo("clientId1"); //see user mapper objects for explanation
}
Also used : ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) Test(org.junit.Test)

Example 4 with ChannelDatabaseService

use of com.applozic.mobicomkit.channel.database.ChannelDatabaseService 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);
            AlTask.execute(applozicGetMemberFromContactGroupTask);
        } 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()) {
            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) 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)

Example 5 with ChannelDatabaseService

use of com.applozic.mobicomkit.channel.database.ChannelDatabaseService in project Applozic-Android-SDK by AppLozic.

the class ConversationActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    // noinspection SimplifiableIfStatement
    if (id == R.id.start_new) {
        if (!TextUtils.isEmpty(contactsGroupId)) {
            if (Utils.isInternetAvailable(this)) {
                conversationUIService.startContactActivityForResult();
            } else {
                Intent intent = new Intent(this, MobiComKitPeopleActivity.class);
                ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(this);
                String[] userIdArray = channelDatabaseService.getChannelMemberByName(contactsGroupId, null);
                if (userIdArray != null) {
                    conversationUIService.startContactActivityForResult(intent, null, null, userIdArray);
                }
            }
        } else {
            conversationUIService.startContactActivityForResult();
        }
    } else if (id == R.id.conversations) {
        Intent intent = new Intent(this, ChannelCreateActivity.class);
        intent.putExtra(ChannelCreateActivity.GROUP_TYPE, Channel.GroupType.PUBLIC.getValue().intValue());
        startActivity(intent);
    } else if (id == R.id.broadcast) {
        Intent intent = new Intent(this, ContactSelectionActivity.class);
        intent.putExtra(ContactSelectionActivity.GROUP_TYPE, Channel.GroupType.BROADCAST.getValue().intValue());
        startActivity(intent);
    } else if (id == R.id.refresh) {
        Toast.makeText(this, getString(R.string.info_message_sync), Toast.LENGTH_LONG).show();
        AlTask.execute(new SyncMessagesAsyncTask(this));
    } else if (id == R.id.shareOptions) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setAction(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, inviteMessage);
        startActivity(Intent.createChooser(intent, "Share Via"));
        return super.onOptionsItemSelected(item);
    } else if (id == R.id.applozicUserProfile) {
        profilefragment.setApplozicPermissions(applozicPermission);
        addFragment(this, profilefragment, ProfileFragment.ProfileFragmentTag);
    } else if (id == R.id.logout) {
        if (!TextUtils.isEmpty(alCustomizationSettings.getLogoutPackage())) {
            Applozic.logoutUser(ConversationActivity.this, new AlLogoutHandler() {

                @Override
                public void onSuccess(Context context) {
                    try {
                        Class loginActivity = Class.forName(alCustomizationSettings.getLogoutPackage().trim());
                        if (loginActivity != null) {
                            Toast.makeText(getBaseContext(), getString(R.string.user_logout_info), Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(ConversationActivity.this, loginActivity);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                            startActivity(intent);
                            finish();
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Exception exception) {
                }
            });
        }
    } else if (id == R.id.sendTextLogs) {
        try {
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.setType("vnd.android.cursor.dir/email");
            String[] receivers = { ALSpecificSettings.getInstance(this).getSupportEmailId() };
            emailIntent.putExtra(Intent.EXTRA_EMAIL, receivers);
            emailIntent.putExtra(Intent.EXTRA_STREAM, Utils.getTextLogFileUri(this));
            emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " " + getString(R.string.log_email_subject));
            startActivity(Intent.createChooser(emailIntent, getString(R.string.select_email_app_chooser_title)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : Context(android.content.Context) Intent(android.content.Intent) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) SuppressLint(android.annotation.SuppressLint) AlLogoutHandler(com.applozic.mobicomkit.listners.AlLogoutHandler)

Aggregations

ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)5 Context (android.content.Context)3 SpannableString (android.text.SpannableString)3 AppContactService (com.applozic.mobicomkit.contact.AppContactService)3 Contact (com.applozic.mobicommons.people.contact.Contact)3 ArrayList (java.util.ArrayList)3 ProgressDialog (android.app.ProgressDialog)2 Bitmap (android.graphics.Bitmap)2 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)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 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)2 List (java.util.List)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 NonNull (androidx.annotation.NonNull)1 AlLogoutHandler (com.applozic.mobicomkit.listners.AlLogoutHandler)1 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)1 Test (org.junit.Test)1