Search in sources :

Example 11 with ChannelFeedApiResponse

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

the class ChannelService method createGroupOfTwoWithResponse.

/**
 * Internal. Group-of-two channels are implemented in the UI. You will not need them.
 *
 * <p>Create a {@link Channel.GroupType#GROUPOFTWO} channel.</p>
 *
 * <p>A group-of-two type channel is implemented in the UI to look like a 1-to-1 chat.
 * It is meant to have two members only.</p>
 *
 * @param channelInfo the channel info that will be used to create the channel
 * @return the {@link AlResponse} from the server
 */
public AlResponse createGroupOfTwoWithResponse(ChannelInfo channelInfo) {
    if (channelInfo == null) {
        return null;
    }
    AlResponse alResponse = new AlResponse();
    if (!TextUtils.isEmpty(channelInfo.getClientGroupId())) {
        Channel channel = channelDatabaseService.getChannelByClientGroupId(channelInfo.getClientGroupId());
        if (channel != null) {
            alResponse.setStatus(AlResponse.SUCCESS);
            alResponse.setResponse(channel);
        } else {
            ChannelFeedApiResponse channelFeedApiResponse = channelClientService.createChannelWithResponse(channelInfo);
            if (channelFeedApiResponse == null) {
                alResponse.setStatus(AlResponse.ERROR);
            } else {
                if (channelFeedApiResponse.isSuccess()) {
                    ChannelFeed channelFeed = channelFeedApiResponse.getResponse();
                    if (channelFeed != null) {
                        ChannelFeed[] channelFeeds = new ChannelFeed[1];
                        channelFeeds[0] = channelFeed;
                        processChannelFeedList(channelFeeds, true);
                        alResponse.setStatus(AlResponse.SUCCESS);
                        alResponse.setResponse(getChannel(channelFeed));
                    }
                } else {
                    ChannelFeed channelFeed = channelClientService.getChannelInfo(channelInfo.getClientGroupId());
                    if (channelFeed != null) {
                        ChannelFeed[] channelFeeds = new ChannelFeed[1];
                        channelFeeds[0] = channelFeed;
                        processChannelFeedList(channelFeeds, false);
                        alResponse.setStatus(AlResponse.SUCCESS);
                        alResponse.setResponse(getChannel(channelFeed));
                    }
                }
            }
        }
    }
    return alResponse;
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Example 12 with ChannelFeedApiResponse

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

the class ChannelService method createChannelWithResponse.

/**
 * Creates a new {@link Channel}.
 *
 * <p>This method will block the main thread. Run it asynchronously.</p>
 *
 * @param channelInfo contains the parameters/details for the creating the channel
 * @return The response object. Pass {@link ChannelFeedApiResponse#getResponse()} to {@link ChannelService#getChannel(ChannelFeed)} to get your newly created <i>channel</i> object.
 */
@Nullable
public ChannelFeedApiResponse createChannelWithResponse(@NonNull ChannelInfo channelInfo) {
    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 channelFeedApiResponse;
}
Also used : ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Nullable(androidx.annotation.Nullable)

Example 13 with ChannelFeedApiResponse

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

the class ChannelService method createChannel.

/**
 * @deprecated {@link AlResponse} is not longer used. It will be replaced by {@link ApiResponse}.
 *
 * Use {@link ChannelService#createChannelWithResponse(ChannelInfo)} instead.
 */
@Deprecated
public synchronized AlResponse createChannel(final ChannelInfo channelInfo) {
    if (channelInfo == null) {
        return null;
    }
    AlResponse alResponse = new AlResponse();
    ChannelFeedApiResponse channelFeedResponse = null;
    try {
        channelFeedResponse = channelClientService.createChannelWithResponse(channelInfo);
        if (channelFeedResponse == null) {
            return null;
        }
        if (channelFeedResponse.isSuccess()) {
            alResponse.setStatus(AlResponse.SUCCESS);
            ChannelFeed channelFeed = channelFeedResponse.getResponse();
            if (channelFeed != null) {
                ChannelFeed[] channelFeeds = new ChannelFeed[1];
                channelFeeds[0] = channelFeed;
                processChannelFeedList(channelFeeds, true);
                alResponse.setResponse(getChannel(channelFeed));
            }
        } else {
            alResponse.setStatus(AlResponse.ERROR);
            alResponse.setResponse(channelFeedResponse.getErrorResponse());
        }
    } catch (Exception e) {
        alResponse.setStatus(AlResponse.ERROR);
        alResponse.setException(e);
    }
    return alResponse;
}
Also used : AlResponse(com.applozic.mobicomkit.feed.AlResponse) 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