Search in sources :

Example 21 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class ReaderTagActions method addTag.

public static boolean addTag(final ReaderTag tag, final ReaderActions.ActionListener actionListener) {
    if (tag == null) {
        ReaderActions.callActionListener(actionListener, false);
        return false;
    }
    final String tagNameForApi = ReaderUtils.sanitizeWithDashes(tag.getTagSlug());
    final String path = "read/tags/" + tagNameForApi + "/mine/new";
    String endpoint = "/read/tags/" + tagNameForApi + "/posts";
    ReaderTag newTag = new ReaderTag(tag.getTagSlug(), tag.getTagDisplayName(), tag.getTagTitle(), endpoint, ReaderTagType.FOLLOWED);
    com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {

        @Override
        public void onResponse(JSONObject jsonObject) {
            AppLog.i(T.READER, "add tag  succeeded");
            // the response will contain the list of the user's followed tags
            ReaderTagList tags = parseFollowedTags(jsonObject);
            ReaderTagTable.replaceFollowedTags(tags);
            ReaderActions.callActionListener(actionListener, true);
        }
    };
    RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            // treat is as a success if we're adding a tag and the error says the user is
            // already following it
            String error = VolleyUtils.errStringFromVolleyError(volleyError);
            if (error.equals("already_subscribed")) {
                AppLog.w(T.READER, "add tag succeeded with error " + error);
                ReaderActions.callActionListener(actionListener, true);
                return;
            }
            AppLog.w(T.READER, "add tag failed");
            AppLog.e(T.READER, volleyError);
            // revert on failure
            ReaderTagTable.deleteTag(tag);
            ReaderActions.callActionListener(actionListener, false);
        }
    };
    ReaderTagTable.addOrUpdateTag(newTag);
    WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener);
    return true;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) VolleyError(com.android.volley.VolleyError) RestRequest(com.wordpress.rest.RestRequest) JSONObject(org.json.JSONObject) ReaderTagList(org.wordpress.android.models.ReaderTagList)

Example 22 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class ReaderPhotoView method loadLoResImage.

private void loadLoResImage() {
    if (!hasLayout() || TextUtils.isEmpty(mLoResImageUrl)) {
        return;
    }
    // skip if this same image url is already being loaded
    if (isRequestingUrl(mLoResContainer, mLoResImageUrl)) {
        AppLog.d(AppLog.T.READER, "reader photo > already requesting lo-res");
        return;
    }
    Point pt = DisplayUtils.getDisplayPixelSize(this.getContext());
    int maxSize = Math.min(pt.x, pt.y);
    showProgress();
    mLoResContainer = WordPress.sImageLoader.get(mLoResImageUrl, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            AppLog.e(AppLog.T.READER, error);
            hideProgress();
            showError();
        }

        @Override
        public void onResponse(final ImageContainer response, boolean isImmediate) {
            post(new Runnable() {

                @Override
                public void run() {
                    handleResponse(response.getBitmap(), true);
                }
            });
        }
    }, maxSize, maxSize);
}
Also used : VolleyError(com.android.volley.VolleyError) Point(android.graphics.Point) Point(android.graphics.Point) ImageContainer(com.android.volley.toolbox.ImageLoader.ImageContainer)

Example 23 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class ReaderPhotoView method loadHiResImage.

private void loadHiResImage() {
    if (!hasLayout() || TextUtils.isEmpty(mHiResImageUrl)) {
        return;
    }
    if (isRequestingUrl(mHiResContainer, mHiResImageUrl)) {
        AppLog.d(AppLog.T.READER, "reader photo > already requesting hi-res");
        return;
    }
    Point pt = DisplayUtils.getDisplayPixelSize(this.getContext());
    int maxSize = Math.max(pt.x, pt.y);
    mHiResContainer = WordPress.sImageLoader.get(mHiResImageUrl, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            AppLog.e(AppLog.T.READER, error);
        }

        @Override
        public void onResponse(final ImageContainer response, boolean isImmediate) {
            post(new Runnable() {

                @Override
                public void run() {
                    handleResponse(response.getBitmap(), false);
                }
            });
        }
    }, maxSize, maxSize);
}
Also used : VolleyError(com.android.volley.VolleyError) Point(android.graphics.Point) Point(android.graphics.Point) ImageContainer(com.android.volley.toolbox.ImageLoader.ImageContainer)

Example 24 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class LegacyEditorFragment method loadWPImageSpanThumbnail.

private void loadWPImageSpanThumbnail(MediaFile mediaFile, String imageURL, ImageLoader imageLoader) {
    if (mediaFile == null || imageURL == null) {
        return;
    }
    final String mediaId = mediaFile.getMediaId();
    if (mediaId == null) {
        return;
    }
    final int maxThumbWidth = ImageUtils.getMaximumThumbnailWidthForEditor(getActivity());
    imageLoader.get(imageURL, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError arg0) {
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer container, boolean arg1) {
            Bitmap downloadedBitmap = container.getBitmap();
            if (downloadedBitmap == null) {
                // no bitmap downloaded from the server.
                return;
            }
            if (downloadedBitmap.getWidth() < MIN_THUMBNAIL_WIDTH) {
                // Picture is too small. Show the placeholder in this case.
                return;
            }
            Bitmap resizedBitmap;
            // resize the downloaded bitmap
            resizedBitmap = ImageUtils.getScaledBitmapAtLongestSide(downloadedBitmap, maxThumbWidth);
            if (resizedBitmap == null) {
                return;
            }
            final EditText editText = mContentEditText;
            Editable s = editText.getText();
            if (s == null) {
                return;
            }
            WPImageSpan[] spans = s.getSpans(0, s.length(), WPImageSpan.class);
            if (spans.length != 0 && getActivity() != null) {
                for (WPImageSpan is : spans) {
                    MediaFile mediaFile = is.getMediaFile();
                    if (mediaFile == null) {
                        continue;
                    }
                    if (mediaId.equals(mediaFile.getMediaId()) && !is.isNetworkImageLoaded()) {
                        // replace the existing span with a new one with the correct image, re-add
                        // it to the same position.
                        int spanStart = is.getStartPosition();
                        int spanEnd = is.getEndPosition();
                        WPEditImageSpan imageSpan = new WPEditImageSpan(getActivity(), resizedBitmap, is.getImageSource());
                        imageSpan.setMediaFile(is.getMediaFile());
                        imageSpan.setNetworkImageLoaded(true);
                        imageSpan.setPosition(spanStart, spanEnd);
                        s.removeSpan(is);
                        s.setSpan(imageSpan, spanStart, spanEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        break;
                    }
                }
            }
        }
    }, 0, 0);
}
Also used : VolleyError(com.android.volley.VolleyError) WPEditText(org.wordpress.android.util.widgets.WPEditText) EditText(android.widget.EditText) MediaFile(org.wordpress.android.util.helpers.MediaFile) WPEditImageSpan(org.wordpress.android.editor.legacy.WPEditImageSpan) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) Bitmap(android.graphics.Bitmap) Editable(android.text.Editable) ImageLoader(com.android.volley.toolbox.ImageLoader)

Example 25 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class ThemeBrowserActivity method searchThemes.

public void searchThemes(String searchTerm) {
    mFetchingThemes = true;
    int page = 1;
    if (mThemeSearchFragment != null) {
        page = mThemeSearchFragment.getPage();
    }
    WordPress.getRestClientUtilsV1_2().getFreeSearchThemes(mSite.getSiteId(), THEME_FETCH_MAX, page, searchTerm, new Listener() {

        @Override
        public void onResponse(JSONObject response) {
            new FetchThemesTask().execute(response);
        }
    }, new ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError response) {
            if (response.toString().equals(AuthFailureError.class.getName())) {
                String errorTitle = getString(R.string.theme_auth_error_title);
                String errorMsg = getString(R.string.theme_auth_error_message);
                if (mIsRunning) {
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    WPAlertDialogFragment fragment = WPAlertDialogFragment.newAlertDialog(errorMsg, errorTitle);
                    ft.add(fragment, ALERT_TAB);
                    ft.commitAllowingStateLoss();
                }
                AppLog.d(T.THEMES, getString(R.string.theme_auth_error_authenticate));
            }
            mFetchingThemes = false;
        }
    });
}
Also used : ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) VolleyError(com.android.volley.VolleyError) ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) Listener(com.wordpress.rest.RestRequest.Listener) FragmentTransaction(android.app.FragmentTransaction) JSONObject(org.json.JSONObject) WPAlertDialogFragment(org.wordpress.android.widgets.WPAlertDialogFragment)

Aggregations

VolleyError (com.android.volley.VolleyError)180 Response (com.android.volley.Response)121 JSONObject (org.json.JSONObject)104 HashMap (java.util.HashMap)70 JSONException (org.json.JSONException)66 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)57 User (model.User)49 JSONArray (org.json.JSONArray)35 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)16 Toast (android.widget.Toast)16 StringRequest (com.android.volley.toolbox.StringRequest)16 RestRequest (com.wordpress.rest.RestRequest)16 CustomRequest (dz.easy.androidclient.Util.CustomRequest)12 TextView (android.widget.TextView)11 MockHttpStack (com.android.volley.mock.MockHttpStack)9 GsonRequest (com.android.volley.toolbox.GsonRequest)9 ImageContainer (com.android.volley.toolbox.ImageLoader.ImageContainer)9 Test (org.junit.Test)9