Search in sources :

Example 6 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseService method getChannelUserByChannelKey.

// Cleanup: default
public ChannelUserMapper getChannelUserByChannelKey(final Integer channelKey) {
    ChannelUserMapper channelUserMapper = null;
    Cursor cursor = null;
    try {
        String structuredNameWhere = MobiComDatabaseHelper.CHANNEL_KEY + " =? AND " + MobiComDatabaseHelper.USERID + "=" + MobiComUserPreference.getInstance(context).getUserId();
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        cursor = db.query(CHANNEL_USER_X, null, structuredNameWhere, new String[] { String.valueOf(channelKey) }, null, null, null);
        if (cursor != null) {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                channelUserMapper = getChannelUser(cursor);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        dbHelper.close();
    }
    return channelUserMapper;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Cursor(android.database.Cursor)

Example 7 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper 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 8 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method updateChannelSubTitle.

public void updateChannelSubTitle(final Channel channel) {
    if (channel.isOpenGroup()) {
        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    setToolbarSubtitle("");
                    setToolbarImage(null, channel);
                }
            });
            return;
        }
    }
    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)) {
                final Contact withUserContact = appContactService.getContactById(userId);
                if (withUserContact != null) {
                    if (getActivity() == null) {
                        return;
                    }
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            if (withUserContact.isBlocked()) {
                                if (getActivity() != null) {
                                    setToolbarSubtitle("");
                                }
                            } else {
                                if (withUserContact.isConnected() && getActivity() != null) {
                                    setToolbarSubtitle(ApplozicService.getContext(getContext()).getString(R.string.user_online));
                                    setToolbarImage(null, channel);
                                } else if (withUserContact.getLastSeenAt() != 0 && getActivity() != null) {
                                    setToolbarSubtitle(ApplozicService.getContext(getContext()).getString(R.string.subtitle_last_seen_at_time) + " " + DateUtils.getDateAndTimeForLastSeen(getContext(), withUserContact.getLastSeenAt(), alCustomizationSettings.getDateFormatCustomization().getTimeAndDateTemplate(), R.string.JUST_NOW, R.plurals.MINUTES_AGO, R.plurals.HOURS_AGO, R.string.YESTERDAY));
                                    setToolbarImage(null, channel);
                                } else if (getActivity() != null) {
                                    setToolbarSubtitle("");
                                    setToolbarImage(null, channel);
                                }
                            }
                        }
                    });
                }
            }
        } else {
            final StringBuffer stringBuffer = new StringBuffer();
            Contact contactDisplayName;
            String youString = "";
            int i = 0;
            for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
                i++;
                if (i > 20)
                    break;
                contactDisplayName = appContactService.getContactById(channelUserMapper.getUserKey());
                if (!TextUtils.isEmpty(channelUserMapper.getUserKey())) {
                    if (loggedInUserId.equals(channelUserMapper.getUserKey())) {
                        youString = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                }
            }
            final String finalYouString = youString;
            if (getActivity() == null) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (!TextUtils.isEmpty(stringBuffer)) {
                        if (channelUserMapperList.size() <= 20) {
                            if (!TextUtils.isEmpty(finalYouString)) {
                                stringBuffer.append(finalYouString).append(",");
                            }
                            int lastIndex = stringBuffer.lastIndexOf(",");
                            String userIds = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                            if (getActivity() != null) {
                                setToolbarSubtitle(userIds);
                                setToolbarImage(null, channel);
                            }
                        } else {
                            if (getActivity() != null) {
                                setToolbarSubtitle(stringBuffer.toString());
                                setToolbarImage(null, channel);
                            }
                        }
                    } else {
                        if (getActivity() != null) {
                            setToolbarSubtitle(finalYouString);
                            setToolbarImage(null, channel);
                        }
                    }
                }
            });
        }
    }
}
Also used : ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Collections.disjoint(java.util.Collections.disjoint) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 9 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseServiceTest method addAndRetrieveChannels.

// channel methods >>
@Test
public void addAndRetrieveChannels() {
    // getAllChannels for null
    assertThat(channelDatabaseService.getAllChannels()).isEmpty();
    channelUserMapper = new ChannelUserMapper();
    // for channel1
    channelUserMapper.setKey(123451);
    channelUserMapper.setUserKey("clientId");
    channelUserMapper.setUnreadCount(20);
    channelUserMapper.setStatus((short) 2);
    channelUserMapper.setParentKey(123);
    channelUserMapper.setRole(4);
    // add two channels
    channelDatabaseService.addChannel(channel);
    channelDatabaseService.addChannel(channel1);
    // test addChannel and getChannelByClientId and getChannelByChannelKey
    Channel actualChannelRetrievedByClientGroupId = channelDatabaseService.getChannelByClientGroupId(channel.getClientGroupId());
    assertThat(actualChannelRetrievedByClientGroupId.toString()).isEqualTo(channel.toString());
    Channel actualChannelRetrievedByChannelKey = channelDatabaseService.getChannelByChannelKey(channel.getKey());
    assertThat(actualChannelRetrievedByChannelKey.toString()).isEqualTo(channel.toString());
    assertThat(channelDatabaseService.getChannelByChannelKey(999)).isNull();
    assertThat(channelDatabaseService.getChannelByClientGroupId("doesn't-exist")).isNull();
    // add more channels
    channelDatabaseService.addChannel(channel2);
    channelDatabaseService.addChannel(channel3);
    // test getAllChannels
    List<Channel> actualChannelList = channelDatabaseService.getAllChannels();
    assertThat(actualChannelList.get(0).toString()).isEqualTo(channel2.toString());
    assertThat(actualChannelList.get(1).toString()).isEqualTo(channel1.toString());
    assertThat(actualChannelList.get(2).toString()).isEqualTo(channel3.toString());
    assertThat(actualChannelList.get(3).toString()).isEqualTo(channel.toString());
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Test(org.junit.Test)

Example 10 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ALGroupInfoTask method onPostExecute.

@Override
protected void onPostExecute(ChannelModel model) {
    super.onPostExecute(model);
    if (listener != null) {
        if (model.getChannel() != null) {
            ChannelInfoModel infoModel = new ChannelInfoModel();
            if (isUserListRequest) {
                List<ChannelUserMapper> mapperList = ChannelService.getInstance(context).getListOfUsersFromChannelUserMapper(model.getChannel().getKey());
                ArrayList<String> users = new ArrayList<String>();
                for (ChannelUserMapper channelUserMapper : mapperList) {
                    users.add(channelUserMapper.getUserKey());
                }
                infoModel.setUserList(users);
            }
            infoModel.setChannel(model.getChannel());
            listener.onSuccess(infoModel, "Success, found in local DB", context);
        } else {
            if (model.getChannelFeedApiResponse() != null) {
                if (model.getChannelFeedApiResponse().isSuccess()) {
                    ChannelFeed channelFeed = model.getChannelFeedApiResponse().getResponse();
                    if (channelFeed != null) {
                        channelService = ChannelService.getInstance(context);
                        channelFeed.setUnreadCount(0);
                        ChannelFeed[] channelFeeds = new ChannelFeed[1];
                        channelFeeds[0] = channelFeed;
                        channelService.processChannelFeedList(channelFeeds, false);
                        Channel channel = channelService.getChannel(channelFeed);
                        if (channel != null) {
                            ChannelInfoModel infoModel = new ChannelInfoModel();
                            if (isUserListRequest) {
                                ArrayList<String> users = new ArrayList<String>();
                                users.addAll(channelFeed.getMembersName());
                                infoModel.setUserList(users);
                            }
                            infoModel.setChannel(channel);
                            listener.onSuccess(infoModel, "Success, fetched from server", context);
                        }
                    }
                } else {
                    if (model.getChannelFeedApiResponse().getErrorResponse() != null) {
                        listener.onFailure(GsonUtils.getJsonFromObject(model.getChannelFeedApiResponse().getErrorResponse().toArray(new ErrorResponseFeed[model.getChannelFeedApiResponse().getErrorResponse().size()]), ErrorResponseFeed[].class), model.getException(), context);
                    } else {
                        listener.onFailure(null, model.getException(), context);
                    }
                }
            } else {
                listener.onFailure(null, model.getException(), context);
            }
        }
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper)

Aggregations

ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)22 Channel (com.applozic.mobicommons.people.channel.Channel)7 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Contact (com.applozic.mobicommons.people.contact.Contact)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)3 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)3 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 AdapterView (android.widget.AdapterView)2 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)2 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)2 Collections.disjoint (java.util.Collections.disjoint)2 Test (org.junit.Test)2 Context (android.content.Context)1 Intent (android.content.Intent)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 SpannableString (android.text.SpannableString)1