Search in sources :

Example 6 with ChannelFeedApiResponse

use of com.applozic.mobicomkit.feed.ChannelFeedApiResponse in project Applozic-Android-SDK by AppLozic.

the class ConversationClientService method createConversation.

// Cleanup: default
public ChannelFeed createConversation(Conversation conversation) {
    ChannelFeed channelFeed = null;
    try {
        String jsonFromObject = GsonUtils.getJsonFromObject(conversation, conversation.getClass());
        String createChannelResponse = httpRequestUtils.postData(getCreateConversationUrl(), "application/json", "application/json", jsonFromObject);
        Utils.printLog(context, TAG, "Create Conversation reponse:" + createChannelResponse);
        ChannelFeedApiResponse channelFeedApiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(createChannelResponse, ChannelFeedApiResponse.class);
        if (channelFeedApiResponse != null && channelFeedApiResponse.isSuccess()) {
            channelFeed = channelFeedApiResponse.getResponse();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return channelFeed;
}
Also used : ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Example 7 with ChannelFeedApiResponse

use of com.applozic.mobicomkit.feed.ChannelFeedApiResponse in project Applozic-Android-SDK by AppLozic.

the class ContactSelectionFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.Done) {
        if (userIdList != null && userIdList.size() == 0) {
            Toast.makeText(getActivity(), R.string.select_at_least, Toast.LENGTH_SHORT).show();
        } else {
            final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getActivity().getString(TextUtils.isEmpty(channelName) ? R.string.broadcast_creating_info : R.string.group_creating_info), true);
            AlChannelCreateAsyncTask.TaskListenerInterface taskListenerInterface = new AlChannelCreateAsyncTask.TaskListenerInterface() {

                @Override
                public void onSuccess(Channel channel, Context context) {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    if (channel != null) {
                        Intent intent = new Intent(getActivity(), ConversationActivity.class);
                        if (ApplozicClient.getInstance(getActivity().getApplicationContext()).isContextBasedChat()) {
                            intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
                        }
                        intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
                        intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
                        getActivity().startActivity(intent);
                    }
                    if (bundle != null && bundle.getString(CHANNEL) != null) {
                        getActivity().sendBroadcast(new Intent(ChannelCreateActivity.ACTION_FINISH_CHANNEL_CREATE));
                    }
                    if (getActivity() != null) {
                        getActivity().finish();
                    }
                }

                @Override
                public void onFailure(ChannelFeedApiResponse channelFeedApiResponse, Context context) {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    if (channelFeedApiResponse != null) {
                        List<ErrorResponseFeed> error = channelFeedApiResponse.getErrorResponse();
                        if (error != null && error.size() > 0) {
                            ErrorResponseFeed errorResponseFeed = error.get(0);
                            String errorDescription = errorResponseFeed.getDescription();
                            if (!TextUtils.isEmpty(errorDescription)) {
                                if (MobiComKitConstants.GROUP_USER_LIMIT_EXCEED.equalsIgnoreCase(errorDescription)) {
                                    Toast.makeText(context, R.string.group_members_limit_exceeds, Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(context, R.string.applozic_server_error, Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                    } else {
                        Toast.makeText(context, Utils.isInternetAvailable(context) ? R.string.applozic_server_error : R.string.you_dont_have_any_network_access_info, Toast.LENGTH_SHORT).show();
                    }
                }
            };
            if (userIdList != null && userIdList.size() > 0) {
                if (TextUtils.isEmpty(channelName)) {
                    StringBuffer stringBuffer = new StringBuffer();
                    int i = 0;
                    for (String userId : userIdList) {
                        i++;
                        if (i > 10)
                            break;
                        Contact contactDisplayName = appContactService.getContactById(userId);
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                    int lastIndex = stringBuffer.lastIndexOf(",");
                    channelName = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                }
                ChannelInfo channelInfo = new ChannelInfo(channelName, userIdList);
                if (!TextUtils.isEmpty(imageUrl)) {
                    channelInfo.setImageUrl(imageUrl);
                }
                if (groupType == Channel.GroupType.BROADCAST.getValue()) {
                    channelInfo.setType(groupType);
                } else if (alCustomizationSettings != null) {
                    channelInfo.setType(alCustomizationSettings.getDefaultGroupType());
                } else {
                    channelInfo.setType(groupType);
                }
                if (MobiComUserPreference.getInstance(getActivity()).getParentGroupKey() != null && MobiComUserPreference.getInstance(getActivity()).getParentGroupKey() != 0) {
                    channelInfo.setParentKey(MobiComUserPreference.getInstance(getActivity()).getParentGroupKey());
                }
                AlChannelCreateAsyncTask alChannelCreateAsyncTask = new AlChannelCreateAsyncTask(getActivity(), channelInfo, taskListenerInterface);
                AlTask.execute(alChannelCreateAsyncTask);
            }
        }
        return true;
    }
    return false;
}
Also used : Context(android.content.Context) ErrorResponseFeed(com.applozic.mobicomkit.feed.ErrorResponseFeed) Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) ChannelInfo(com.applozic.mobicomkit.api.people.ChannelInfo) SpannableString(android.text.SpannableString) ProgressDialog(android.app.ProgressDialog) SuppressLint(android.annotation.SuppressLint) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact) AlChannelCreateAsyncTask(com.applozic.mobicomkit.uiwidgets.async.AlChannelCreateAsyncTask)

Example 8 with ChannelFeedApiResponse

use of com.applozic.mobicomkit.feed.ChannelFeedApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelClientService method getMembersFromContactGroupOfType.

/**
 * Sends a request to get the contacts for a group, identified by it's contactGroupId and groupType.
 *
 * <p>Contacts for a user can be grouped together. Such a group is called a contact group.</p>
 *
 * @param contactGroupId the contact group id
 * @param groupType the group type
 * @return {@link ChannelFeed}. User {@link ChannelFeed#getGroupUsers()} to get the contacts.
 */
@Nullable
public ChannelFeed getMembersFromContactGroupOfType(@Nullable String contactGroupId, @Nullable String groupType) {
    String response;
    if (!TextUtils.isEmpty(contactGroupId) && !TextUtils.isEmpty(groupType)) {
        String url = String.format(getMembersFromContactGroupOfTypeUrl() + "?" + GROUPTYPE + "=" + groupType, contactGroupId);
        response = httpRequestUtils.getResponse(url, "application/json", "application/json");
        ChannelFeedApiResponse channelFeedApiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(response, ChannelFeedApiResponse.class);
        if (channelFeedApiResponse != null && channelFeedApiResponse.isSuccess()) {
            ChannelFeed channelFeed = channelFeedApiResponse.getResponse();
            return channelFeed;
        }
    }
    return null;
}
Also used : SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Nullable(androidx.annotation.Nullable)

Example 9 with ChannelFeedApiResponse

use of com.applozic.mobicomkit.feed.ChannelFeedApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelClientService method createChannel.

// Cleanup: default
@Deprecated
public ChannelFeed createChannel(ChannelInfo channelInfo) {
    ChannelFeed channelFeed = null;
    try {
        String jsonFromObject = GsonUtils.getJsonFromObject(channelInfo, channelInfo.getClass());
        String createChannelResponse = httpRequestUtils.postData(getCreateChannelUrl(), "application/json", "application/json", jsonFromObject);
        Utils.printLog(context, TAG, "Create channel Response :" + createChannelResponse);
        ChannelFeedApiResponse channelFeedApiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(createChannelResponse, ChannelFeedApiResponse.class);
        if (channelFeedApiResponse != null && channelFeedApiResponse.isSuccess()) {
            channelFeed = channelFeedApiResponse.getResponse();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return channelFeed;
}
Also used : SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) JSONException(org.json.JSONException)

Example 10 with ChannelFeedApiResponse

use of com.applozic.mobicomkit.feed.ChannelFeedApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelService method createGroupOfTwo.

/**
 * @deprecated Use {@link #createGroupOfTwoWithResponse(ChannelInfo)} instead.
 */
@Deprecated
public Channel createGroupOfTwo(ChannelInfo channelInfo) {
    if (channelInfo == null) {
        return null;
    }
    if (!TextUtils.isEmpty(channelInfo.getClientGroupId())) {
        Channel channel = channelDatabaseService.getChannelByClientGroupId(channelInfo.getClientGroupId());
        if (channel != null) {
            return channel;
        } else {
            ChannelFeedApiResponse channelFeedApiResponse = channelClientService.createChannelWithResponse(channelInfo);
            if (channelFeedApiResponse == null) {
                return null;
            }
            if (channelFeedApiResponse.isSuccess()) {
                ChannelFeed channelFeed = channelFeedApiResponse.getResponse();
                if (channelFeed != null) {
                    ChannelFeed[] channelFeeds = new ChannelFeed[1];
                    channelFeeds[0] = channelFeed;
                    processChannelFeedList(channelFeeds, true);
                    return getChannel(channelFeed);
                }
            } else {
                ChannelFeed channelFeed = channelClientService.getChannelInfo(channelInfo.getClientGroupId());
                if (channelFeed != null) {
                    ChannelFeed[] channelFeeds = new ChannelFeed[1];
                    channelFeeds[0] = channelFeed;
                    processChannelFeedList(channelFeeds, false);
                    return getChannel(channelFeed);
                }
            }
        }
    }
    return null;
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Aggregations

ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)13 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)9 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)8 MultipleChannelFeedApiResponse (com.applozic.mobicomkit.MultipleChannelFeedApiResponse)4 AlResponse (com.applozic.mobicomkit.feed.AlResponse)4 Channel (com.applozic.mobicommons.people.channel.Channel)4 Nullable (androidx.annotation.Nullable)3 ChannelInfo (com.applozic.mobicomkit.api.people.ChannelInfo)3 JSONException (org.json.JSONException)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 ProgressDialog (android.app.ProgressDialog)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SpannableString (android.text.SpannableString)1 HttpRequestUtils (com.applozic.mobicomkit.api.HttpRequestUtils)1 ErrorResponseFeed (com.applozic.mobicomkit.feed.ErrorResponseFeed)1 AlChannelCreateAsyncTask (com.applozic.mobicomkit.uiwidgets.async.AlChannelCreateAsyncTask)1 Contact (com.applozic.mobicommons.people.contact.Contact)1