use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.
the class NotificationsUtils method unregisterDevicePushNotifications.
public static void unregisterDevicePushNotifications(final Context ctx) {
RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
AppLog.d(T.NOTIFS, "Unregister token action succeeded");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
editor.remove(WPCOM_PUSH_DEVICE_SERVER_ID);
editor.remove(WPCOM_PUSH_DEVICE_UUID);
editor.remove(WPCOM_PUSH_DEVICE_TOKEN);
editor.apply();
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.NOTIFS, "Unregister token action failed", volleyError);
}
};
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
String deviceID = settings.getString(WPCOM_PUSH_DEVICE_SERVER_ID, null);
if (TextUtils.isEmpty(deviceID)) {
return;
}
WordPress.getRestClientUtils().post("/devices/" + deviceID + "/delete", listener, errorListener);
}
use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.
the class AztecImageLoader method loadImage.
@Override
public void loadImage(String url, final Callbacks callbacks, int maxWidth) {
// TODO: if a local file then load it directly. This is a quick fix though.
if (new File(url).exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(url);
BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bitmap);
callbacks.onImageLoaded(bitmapDrawable);
return;
}
WordPress.sImageLoader.get(url, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
Bitmap bitmap = response.getBitmap();
if (bitmap == null) {
// the loader tries to let us know to just use the default image for now
callbacks.onUseDefaultImage();
} else {
BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), response.getBitmap());
callbacks.onImageLoaded(bitmapDrawable);
}
}
@Override
public void onErrorResponse(VolleyError error) {
callbacks.onImageLoadingFailed();
}
}, maxWidth, 0);
}
use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.
the class PeopleUtils method fetchFollowers.
private static void fetchFollowers(final SiteModel site, final int page, final FetchFollowersCallback callback, final boolean isEmailFollower) {
com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
if (jsonObject != null && callback != null) {
try {
JSONArray jsonArray = jsonObject.getJSONArray("subscribers");
Person.PersonType personType = isEmailFollower ? Person.PersonType.EMAIL_FOLLOWER : Person.PersonType.FOLLOWER;
List<Person> people = peopleListFromJSON(jsonArray, site.getId(), personType);
int pageFetched = jsonObject.optInt("page");
int numberOfPages = jsonObject.optInt("pages");
boolean isEndOfList = page >= numberOfPages || page >= FOLLOWER_PAGE_LIMIT;
callback.onSuccess(people, pageFetched, isEndOfList);
} catch (JSONException e) {
AppLog.e(T.API, "JSON exception occurred while parsing the response for " + "sites/%s/stats/followers: " + e);
callback.onError();
}
}
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.API, volleyError);
if (callback != null) {
callback.onError();
}
}
};
Map<String, String> params = new HashMap<>();
params.put("max", Integer.toString(FETCH_LIMIT));
params.put("page", Integer.toString(page));
params.put("type", isEmailFollower ? "email" : "wp_com");
String path = String.format(Locale.US, "sites/%d/stats/followers", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
}
use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.
the class PeopleUtils method sendInvitations.
public static void sendInvitations(final List<String> usernames, Role role, String message, long dotComBlogId, final InvitationsSendCallback callback) {
com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
if (callback == null) {
return;
}
if (jsonObject == null) {
callback.onError();
return;
}
Map<String, String> failedUsernames = new LinkedHashMap<>();
JSONObject errors = jsonObject.optJSONObject("errors");
if (errors != null) {
for (String username : usernames) {
JSONObject userError = errors.optJSONObject(username);
if (userError != null) {
failedUsernames.put(username, userError.optString("message"));
}
}
}
List<String> succeededUsernames = new ArrayList<>();
JSONArray succeededUsernamesJson = jsonObject.optJSONArray("sent");
if (succeededUsernamesJson == null) {
callback.onError();
return;
}
for (int i = 0; i < succeededUsernamesJson.length(); i++) {
String username = succeededUsernamesJson.optString(i);
if (usernames.contains(username)) {
succeededUsernames.add(username);
}
}
if (failedUsernames.size() + succeededUsernames.size() != usernames.size()) {
callback.onError();
}
callback.onSent(succeededUsernames, failedUsernames);
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(AppLog.T.API, volleyError);
if (callback != null) {
callback.onError();
}
}
};
String path = String.format(Locale.US, "sites/%s/invites/new", dotComBlogId);
Map<String, String> params = new HashMap<>();
for (String username : usernames) {
// specify an array key so to make the map key unique
params.put("invitees[" + username + "]", username);
}
params.put("role", role.toRESTString());
params.put("message", message);
WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener);
}
use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.
the class PeopleUtils method fetchViewers.
public static void fetchViewers(final SiteModel site, final int offset, final FetchViewersCallback callback) {
com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
if (jsonObject != null && callback != null) {
try {
JSONArray jsonArray = jsonObject.getJSONArray("viewers");
List<Person> people = peopleListFromJSON(jsonArray, site.getId(), Person.PersonType.VIEWER);
int numberOfUsers = jsonObject.optInt("found");
boolean isEndOfList = (people.size() + offset) >= numberOfUsers;
callback.onSuccess(people, isEndOfList);
} catch (JSONException e) {
AppLog.e(T.API, "JSON exception occurred while parsing the response for " + "sites/%s/viewers: " + e);
callback.onError();
}
}
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.API, volleyError);
if (callback != null) {
callback.onError();
}
}
};
int page = (offset / FETCH_LIMIT) + 1;
Map<String, String> params = new HashMap<>();
params.put("number", Integer.toString(FETCH_LIMIT));
params.put("page", Integer.toString(page));
String path = String.format(Locale.US, "sites/%d/viewers", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
}
Aggregations