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;
}
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);
}
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);
}
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);
}
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;
}
});
}
Aggregations