Search in sources :

Example 31 with ApiResponse

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

the class MessageClientService method getTopicId.

public String getTopicId(Integer conversationId) {
    try {
        String topicId = null;
        String url = getProductTopicIdUrl() + "?conversationId=" + conversationId;
        String response = httpRequestUtils.getResponse(url, "application/json", "application/json");
        if (response == null || TextUtils.isEmpty(response) || response.equals("UnAuthorized Access")) {
            return null;
        }
        ApiResponse productConversationIdResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        if ("success".equals(productConversationIdResponse.getStatus())) {
            topicId = productConversationIdResponse.getResponse().toString();
            return topicId;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return null;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with ApiResponse

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

the class ConversationClientService method closeConversationByTopicId.

public String closeConversationByTopicId(Set<String> topicIds, String userId) {
    String response = "";
    try {
        StringBuffer stringBuffer = new StringBuffer();
        if (topicIds != null && topicIds.size() > 0) {
            for (String topicId : topicIds) {
                stringBuffer.append(TOPIC_ID).append("=").append(URLEncoder.encode(topicId, "UTF-8")).append("&");
            }
            stringBuffer.append(WITH_USER_ID).append("=").append(URLEncoder.encode(userId, "UTF-8"));
            response = httpRequestUtils.getResponse(getConversationCloseByTopicIdUrl() + "?" + stringBuffer.toString(), "application/json", null);
            if (TextUtils.isEmpty(response)) {
                return null;
            }
            ApiResponse apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            Utils.printLog(context, TAG, "Conversation close by topic id :" + response);
            if (apiResponse != null && apiResponse.isSuccess()) {
                return apiResponse.getResponse().toString();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse)

Example 33 with ApiResponse

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

the class AppContactFragment method blockUserProcess.

public void blockUserProcess(final Contact contact, final boolean block) {
    final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getActivity().getString(R.string.please_wait_info), true);
    UserBlockTask.TaskListener listener = new UserBlockTask.TaskListener() {

        @Override
        public void onSuccess(ApiResponse apiResponse) {
            getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, AppContactFragment.this);
        }

        @Override
        public void onFailure(ApiResponse apiResponse, Exception exception) {
            String error = getString(Utils.isInternetAvailable(getActivity()) ? R.string.applozic_server_error : R.string.you_need_network_access_for_block_or_unblock);
            Toast toast = Toast.makeText(getActivity(), error, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        @Override
        public void onCompletion() {
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }
    };
    AlTask.execute(new UserBlockTask(getActivity(), listener, contact.getUserId(), block));
}
Also used : Toast(android.widget.Toast) UserBlockTask(com.applozic.mobicomkit.api.account.user.UserBlockTask) SpannableString(android.text.SpannableString) ProgressDialog(android.app.ProgressDialog) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse)

Example 34 with ApiResponse

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

the class MobiComConversationFragment method muteGroupChat.

public void muteGroupChat() {
    final CharSequence[] items = { ApplozicService.getContext(getContext()).getString(R.string.eight_Hours), ApplozicService.getContext(getContext()).getString(R.string.one_week), ApplozicService.getContext(getContext()).getString(R.string.one_year) };
    Date date = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
    millisecond = date.getTime();
    final MuteNotificationAsync.TaskListener taskListener = new MuteNotificationAsync.TaskListener() {

        @Override
        public void onSuccess(ApiResponse apiResponse) {
            if (menu != null) {
                menu.findItem(R.id.muteGroup).setVisible(false);
                menu.findItem(R.id.unmuteGroup).setVisible(true);
            }
        }

        @Override
        public void onFailure(ApiResponse apiResponse, Exception exception) {
        }

        @Override
        public void onCompletion() {
        }
    };
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setTitle(ApplozicService.getContext(getContext()).getString(R.string.mute_group_for)).setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, final int selectedItem) {
            if (selectedItem == 0) {
                millisecond = millisecond + 28800000;
            } else if (selectedItem == 1) {
                millisecond = millisecond + 604800000;
            } else if (selectedItem == 2) {
                millisecond = millisecond + 31558000000L;
            }
            muteNotificationRequest = new MuteNotificationRequest(channel.getKey(), millisecond);
            MuteNotificationAsync muteNotificationAsync = new MuteNotificationAsync(getContext(), taskListener, muteNotificationRequest);
            AlTask.execute(muteNotificationAsync);
            dialog.dismiss();
        }
    });
    AlertDialog alertdialog = builder.create();
    alertdialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) MessageBuilder(com.applozic.mobicomkit.api.conversation.MessageBuilder) Date(java.util.Date) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException) Collections.disjoint(java.util.Collections.disjoint) MuteNotificationRequest(com.applozic.mobicomkit.api.notification.MuteNotificationRequest) MuteNotificationAsync(com.applozic.mobicomkit.api.notification.MuteNotificationAsync)

Example 35 with ApiResponse

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

the class UserClientService method getUsersBySearchString.

/**
 * Will return a list of contacts matching the search term , from the server. Search happens by user-id.
 *
 * <p>Note: This is a network method. Run it asynchronously.</p>
 *
 * To get result use:
 * <code>
 *     String userDetails = apiResponse.getResponse();
 *     UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(GsonUtils.getJsonFromObject(userDetails, List.class), UserDetail[].class);
 * </code>
 *
 * <p>Note: This is a network method. Run it asynchronously.</p>
 *
 * @param searchString the search term
 * @return the api response. use {@link ApiResponse#isSuccess()} to check for success. cast the result from {@link ApiResponse#getResponse()}
 * to a {@link UserDetail} array to get the list in usable form
 * @throws ApplozicException when the backend returns an error response
 */
@Nullable
public ApiResponse getUsersBySearchString(@Nullable String searchString) throws ApplozicException {
    if (TextUtils.isEmpty(searchString)) {
        return null;
    }
    String response;
    ApiResponse apiResponse;
    try {
        response = httpRequestUtils.getResponse(getUserSearchUrl() + "?name=" + URLEncoder.encode(searchString, "UTF-8"), "application/json", "application/json");
        if (TextUtils.isEmpty(response)) {
            return null;
        }
        Utils.printLog(context, TAG, "Search user response : " + response);
        apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
    } catch (Exception e) {
        throw new ApplozicException(e.getMessage());
    }
    return apiResponse;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Nullable(androidx.annotation.Nullable)

Aggregations

ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)54 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)23 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)22 JSONException (org.json.JSONException)19 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)16 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)16 Test (org.junit.Test)14 MultipleChannelFeedApiResponse (com.applozic.mobicomkit.MultipleChannelFeedApiResponse)12 MockedConstants.userDetailsApiResponse (com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Nullable (androidx.annotation.Nullable)8 Contact (com.applozic.mobicommons.people.contact.Contact)8 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)3 ArrayList (java.util.ArrayList)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ProgressDialog (android.app.ProgressDialog)2 Toast (android.widget.Toast)2 UserBlockTask (com.applozic.mobicomkit.api.account.user.UserBlockTask)2 MuteNotificationAsync (com.applozic.mobicomkit.api.notification.MuteNotificationAsync)2 MuteNotificationRequest (com.applozic.mobicomkit.api.notification.MuteNotificationRequest)2