Search in sources :

Example 1 with AlChannelCreateAsyncTask

use of com.applozic.mobicomkit.uiwidgets.async.AlChannelCreateAsyncTask 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)

Aggregations

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 ChannelInfo (com.applozic.mobicomkit.api.people.ChannelInfo)1 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)1 ErrorResponseFeed (com.applozic.mobicomkit.feed.ErrorResponseFeed)1 AlChannelCreateAsyncTask (com.applozic.mobicomkit.uiwidgets.async.AlChannelCreateAsyncTask)1 Channel (com.applozic.mobicommons.people.channel.Channel)1 Contact (com.applozic.mobicommons.people.contact.Contact)1