From af01ceb670a4fc8c6b09a537aef6872bea980ede Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:34:22 +0300 Subject: [PATCH 01/87] Refactor: Reformat media rest client --- .../rest/wpcom/media/MediaRestClient.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index ba885681e1..f9b2df486b 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -89,13 +89,14 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList // to monitor multiple uploads private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); - @Inject public MediaRestClient(Context appContext, - Dispatcher dispatcher, - @Named("regular") RequestQueue requestQueue, - @Named("regular") OkHttpClient okHttpClient, - AccessToken accessToken, - UserAgent userAgent, - MediaResponseUtils mediaResponseUtils) { + @Inject public MediaRestClient( + Context appContext, + Dispatcher dispatcher, + @Named("regular") RequestQueue requestQueue, + @Named("regular") OkHttpClient okHttpClient, + AccessToken accessToken, + UserAgent userAgent, + MediaResponseUtils mediaResponseUtils) { super(appContext, dispatcher, requestQueue, accessToken, userAgent); mOkHttpClient = okHttpClient; mMediaResponseUtils = mediaResponseUtils; @@ -143,8 +144,7 @@ public void onErrorResponse(@NonNull WPComGsonNetworkError error) { mediaError.logMessage = errorMessage; notifyMediaPushed(site, media, mediaError); } - } - )); + })); } /** @@ -176,7 +176,7 @@ public void uploadMedia(final SiteModel site, final MediaModel media) { // Abort upload if it exceeds the site upload limit if (site.hasMaxUploadSize() && body.contentLength() > site.getMaxUploadSize()) { String errorMessage = "Media size of " + body.contentLength() + " exceeds site limit of " - + site.getMaxUploadSize(); + + site.getMaxUploadSize(); AppLog.d(T.MEDIA, errorMessage); MediaError error = new MediaError(MediaErrorType.EXCEEDS_FILESIZE_LIMIT); error.logMessage = errorMessage; @@ -188,7 +188,7 @@ public void uploadMedia(final SiteModel site, final MediaModel media) { double maxFilesizeForMemoryLimit = MediaUtils.getMaxFilesizeForMemoryLimit(site.getMemoryLimit()); if (site.hasMemoryLimit() && body.contentLength() > maxFilesizeForMemoryLimit) { String errorMessage = "Media size of " + body.contentLength() + " exceeds safe memory limit of " - + maxFilesizeForMemoryLimit + " for this site"; + + maxFilesizeForMemoryLimit + " for this site"; AppLog.d(T.MEDIA, errorMessage); MediaError error = new MediaError(MediaErrorType.EXCEEDS_MEMORY_LIMIT); error.logMessage = errorMessage; @@ -199,7 +199,7 @@ public void uploadMedia(final SiteModel site, final MediaModel media) { // Abort upload if it exceeds the space quota limit for the site if (site.hasDiskSpaceQuotaInformation() && body.contentLength() > site.getSpaceAvailable()) { String errorMessage = "Media size of " + body.contentLength() + " exceeds disk space quota remaining " - + site.getSpaceAvailable() + " for this site"; + + site.getSpaceAvailable() + " for this site"; AppLog.d(T.MEDIA, errorMessage); MediaError error = new MediaError(MediaErrorType.EXCEEDS_SITE_SPACE_QUOTA_LIMIT); error.logMessage = errorMessage; @@ -299,7 +299,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) { /** * Gets a list of media items given the offset on a WP.com site. - * + *

* NOTE: Only media item data is gathered, the actual media file can be downloaded from the URL * provided in the response {@link MediaModel}'s (via {@link MediaModel#getUrl()}). */ @@ -341,8 +341,7 @@ public void onErrorResponse(@NonNull WPComGsonNetworkError error) { mediaError.logMessage = error.apiError; notifyMediaListFetched(site, mediaError, mimeType); } - } - )); + })); } /** @@ -384,8 +383,7 @@ public void onErrorResponse(@NonNull WPComGsonNetworkError error) { mediaError.logMessage = error.apiError; notifyMediaFetched(site, media, mediaError); } - } - )); + })); } /** @@ -430,8 +428,7 @@ public void onErrorResponse(@NonNull WPComGsonNetworkError error) { mediaError.logMessage = error.apiError; notifyMediaDeleted(site, media, mediaError); } - } - )); + })); } public void cancelUpload(final MediaModel media) { @@ -457,7 +454,7 @@ public void cancelUpload(final MediaModel media) { private void removeCallFromCurrentUploadsMap(int id) { mCurrentUploadCalls.remove(id); AppLog.d(T.MEDIA, "mediaRestClient: removed id: " + id + " from current uploads, remaining: " - + mCurrentUploadCalls.size()); + + mCurrentUploadCalls.size()); } public void uploadStockMedia(@NonNull final SiteModel site, @@ -616,11 +613,13 @@ private void notifyMediaUploadCanceled(MediaModel media) { /** * The current REST API call (v1.1) accepts 'title', 'description', 'caption', 'alt', * and 'parent_id' for all media. Audio media also accepts 'artist' and 'album' attributes. - * + *

* ref https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/ */ private Map getEditRequestParams(final MediaModel media) { - if (media == null) return null; + if (media == null) { + return null; + } MediaFields[] fieldsToUpdate = media.getFieldsToUpdate(); From dff7ec59ba7ccb91115741a7fb4ddca005545ff9 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:37:33 +0300 Subject: [PATCH 02/87] Refactor: Reformat media xmlrpc client --- .../xmlrpc/media/MediaXMLRPCClient.java | 137 +++++++++--------- 1 file changed, 72 insertions(+), 65 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index ff9c83a76c..5a730f0db9 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -80,11 +80,12 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe // to monitor multiple uploads private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); - @Inject public MediaXMLRPCClient(Dispatcher dispatcher, - @Named("custom-ssl") RequestQueue requestQueue, - @Named("custom-ssl") OkHttpClient okHttpClient, - UserAgent userAgent, - HTTPAuthManager httpAuthManager) { + @Inject public MediaXMLRPCClient( + Dispatcher dispatcher, + @Named("custom-ssl") RequestQueue requestQueue, + @Named("custom-ssl") OkHttpClient okHttpClient, + UserAgent userAgent, + HTTPAuthManager httpAuthManager) { super(dispatcher, requestQueue, userAgent, httpAuthManager); mOkHttpClient = okHttpClient; } @@ -118,22 +119,21 @@ public void onResponse(Object response) { notifyMediaPushed(site, media, null); } }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String errorMessage = "error response to XMLRPC.EDIT_MEDIA request: " + error; - AppLog.e(T.MEDIA, errorMessage); - if (is404Response(error)) { - AppLog.e(T.MEDIA, "media does not exist, no need to report error"); - notifyMediaPushed(site, media, null); - } else { - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.message = error.message; - mediaError.logMessage = errorMessage; - notifyMediaPushed(site, media, mediaError); - } - } + @Override + public void onErrorResponse(@NonNull BaseNetworkError error) { + String errorMessage = "error response to XMLRPC.EDIT_MEDIA request: " + error; + AppLog.e(T.MEDIA, errorMessage); + if (is404Response(error)) { + AppLog.e(T.MEDIA, "media does not exist, no need to report error"); + notifyMediaPushed(site, media, null); + } else { + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.message = error.message; + mediaError.logMessage = errorMessage; + notifyMediaPushed(site, media, mediaError); } - )); + } + })); } /** @@ -303,16 +303,15 @@ public void onResponse(Object[] response) { } } }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; - AppLog.e(T.MEDIA, message, error.volleyError); - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaListFetched(site, mediaError, mimeType); - } - } - )); + @Override + public void onErrorResponse(@NonNull BaseNetworkError error) { + String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; + AppLog.e(T.MEDIA, message, error.volleyError); + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaListFetched(site, mediaError, mimeType); + } + })); } public void fetchMedia(final SiteModel site, final MediaModel media) { @@ -369,24 +368,23 @@ public void onResponse(Object response) { } } }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "XMLRPC.GET_MEDIA_ITEM error response: " + error; - AppLog.e(T.MEDIA, message); - if (isFreshUpload) { - // we tried to fetch a media that's just uploaded but failed, so we should return - // an upload error and not a fetch error as initially parsing the upload response failed - MediaError mediaError = new MediaError(MediaErrorType.PARSE_ERROR); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaUploaded(media, mediaError); - } else { - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaFetched(site, media, mediaError); - } - } + @Override + public void onErrorResponse(@NonNull BaseNetworkError error) { + String message = "XMLRPC.GET_MEDIA_ITEM error response: " + error; + AppLog.e(T.MEDIA, message); + if (isFreshUpload) { + // we tried to fetch a media that's just uploaded but failed, so we should return + // an upload error and not a fetch error as initially parsing the upload response failed + MediaError mediaError = new MediaError(MediaErrorType.PARSE_ERROR); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaUploaded(media, mediaError); + } else { + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaFetched(site, media, mediaError); } - )); + } + })); } public void deleteMedia(final SiteModel site, final MediaModel media) { @@ -417,17 +415,16 @@ public void onResponse(Object response) { notifyMediaDeleted(site, media, null); } }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "Error response from XMLRPC.DELETE_MEDIA:" + error; - AppLog.e(T.MEDIA, message); - MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); - MediaError mediaError = new MediaError(mediaErrorType); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaDeleted(site, media, mediaError); - } - } - )); + @Override + public void onErrorResponse(@NonNull BaseNetworkError error) { + String message = "Error response from XMLRPC.DELETE_MEDIA:" + error; + AppLog.e(T.MEDIA, message); + MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); + MediaError mediaError = new MediaError(mediaErrorType); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaDeleted(site, media, mediaError); + } + })); } public void cancelUpload(final MediaModel media) { @@ -453,7 +450,7 @@ public void cancelUpload(final MediaModel media) { private void removeCallFromCurrentUploadsMap(int id) { mCurrentUploadCalls.remove(id); AppLog.d(T.MEDIA, "mediaXMLRPCClient: removed id: " + id + " from current uploads, remaining: " - + mCurrentUploadCalls.size()); + + mCurrentUploadCalls.size()); } // @@ -516,11 +513,15 @@ private void notifyMediaUploadCanceled(MediaModel media) { // media list responses should be of type Object[] with each media item in the array represented by a HashMap private List getMediaListFromXmlrpcResponse(Object[] response, int localSiteId) { - if (response == null) return null; + if (response == null) { + return null; + } List responseMedia = new ArrayList<>(); for (Object mediaObject : response) { - if (!(mediaObject instanceof HashMap)) continue; + if (!(mediaObject instanceof HashMap)) { + continue; + } MediaModel media = getMediaFromXmlrpcResponse((HashMap) mediaObject); if (media != null) { media.setLocalSiteId(localSiteId); @@ -532,7 +533,9 @@ private List getMediaListFromXmlrpcResponse(Object[] response, int l } private MediaModel getMediaFromXmlrpcResponse(Map response) { - if (response == null || response.isEmpty()) return null; + if (response == null || response.isEmpty()) { + return null; + } MediaModel media = new MediaModel(); media.setMediaId(MapUtils.getMapLong(response, "attachment_id")); @@ -576,7 +579,9 @@ private String getFileUrlForSize(String mediaUrl, Map metadataMap, String size) } // make sure the path to the original image is a valid path to a file - if (mediaUrl.lastIndexOf("/") + 1 >= mediaUrl.length()) return null; + if (mediaUrl.lastIndexOf("/") + 1 >= mediaUrl.length()) { + return null; + } String baseURL = mediaUrl.substring(0, mediaUrl.lastIndexOf("/") + 1); return baseURL + fileName; @@ -651,7 +656,9 @@ private static boolean isDeprecatedUploadResponse(Map responseMap) { } private Map getEditMediaFields(final MediaModel media) { - if (media == null) return null; + if (media == null) { + return null; + } Map mediaFields = new HashMap<>(); mediaFields.put("post_title", media.getTitle()); mediaFields.put("post_content", media.getDescription()); @@ -667,7 +674,7 @@ private boolean is404Response(BaseNetworkError error) { if (error.hasVolleyError() && error.volleyError != null) { VolleyError volleyError = error.volleyError; if (volleyError.networkResponse != null - && volleyError.networkResponse.statusCode == HttpURLConnection.HTTP_NOT_FOUND) { + && volleyError.networkResponse.statusCode == HttpURLConnection.HTTP_NOT_FOUND) { return true; } From b2e3a7ceca82a8f99aa481eb56f3593b10b76686 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:39:42 +0300 Subject: [PATCH 03/87] Refactor: Replace anonymous classes with lambda on media rest client --- .../rest/wpcom/media/MediaRestClient.java | 205 ++++++++---------- 1 file changed, 86 insertions(+), 119 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index f9b2df486b..b57d725370 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -6,7 +6,6 @@ import androidx.annotation.NonNull; import com.android.volley.RequestQueue; -import com.android.volley.Response.Listener; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -28,8 +27,6 @@ import org.wordpress.android.fluxc.network.UserAgent; import org.wordpress.android.fluxc.network.rest.wpcom.BaseWPComRestClient; import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest; -import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest.WPComErrorListener; -import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest.WPComGsonNetworkError; import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken; import org.wordpress.android.fluxc.network.rest.wpcom.media.MediaWPComRestResponse.MultipleMediaResponse; import org.wordpress.android.fluxc.store.MediaStore.FetchMediaListResponsePayload; @@ -121,29 +118,23 @@ public void pushMedia(final SiteModel site, final MediaModel media) { String url = WPCOMREST.sites.site(site.getSiteId()).media.item(media.getMediaId()).getUrlV1_1(); add(WPComGsonRequest.buildPostRequest(url, getEditRequestParams(media), MediaWPComRestResponse.class, - new Listener() { - @Override - public void onResponse(MediaWPComRestResponse response) { - MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (responseMedia != null) { - AppLog.v(T.MEDIA, "media changes pushed for " + responseMedia.getTitle()); - responseMedia.setLocalSiteId(site.getId()); - notifyMediaPushed(site, responseMedia, null); - } else { - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "Parsed media is null"; - notifyMediaPushed(site, media, error); - } - } - }, new WPComErrorListener() { - @Override - public void onErrorResponse(@NonNull WPComGsonNetworkError error) { - String errorMessage = "error editing remote media: " + error; - AppLog.e(T.MEDIA, errorMessage); - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.logMessage = errorMessage; - notifyMediaPushed(site, media, mediaError); + response -> { + MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); + if (responseMedia != null) { + AppLog.v(T.MEDIA, "media changes pushed for " + responseMedia.getTitle()); + responseMedia.setLocalSiteId(site.getId()); + notifyMediaPushed(site, responseMedia, null); + } else { + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = "Parsed media is null"; + notifyMediaPushed(site, media, error); } + }, error -> { + String errorMessage = "error editing remote media: " + error; + AppLog.e(T.MEDIA, errorMessage); + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.logMessage = errorMessage; + notifyMediaPushed(site, media, mediaError); })); } @@ -314,33 +305,27 @@ public void fetchMediaList(final SiteModel site, final int number, final int off } String url = WPCOMREST.sites.site(site.getSiteId()).media.getUrlV1_1(); add(WPComGsonRequest.buildGetRequest(url, params, MultipleMediaResponse.class, - new Listener() { - @Override - public void onResponse(MultipleMediaResponse response) { - List mediaList = - mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); - if (mediaList != null) { - AppLog.v(T.MEDIA, "Fetched media list for site with size: " + mediaList.size()); - boolean canLoadMore = mediaList.size() == number; - notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); - } else { - String errorMessage = "could not parse Fetch all media response: " + response; - AppLog.w(T.MEDIA, errorMessage); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = errorMessage; - notifyMediaListFetched(site, error, mimeType); - } - } - }, new WPComErrorListener() { - @Override - public void onErrorResponse(@NonNull WPComGsonNetworkError error) { - String errorMessage = "VolleyError Fetching media: " + error; - AppLog.e(T.MEDIA, errorMessage); - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.message = error.message; - mediaError.logMessage = error.apiError; - notifyMediaListFetched(site, mediaError, mimeType); + response -> { + List mediaList = + mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); + if (mediaList != null) { + AppLog.v(T.MEDIA, "Fetched media list for site with size: " + mediaList.size()); + boolean canLoadMore = mediaList.size() == number; + notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); + } else { + String errorMessage = "could not parse Fetch all media response: " + response; + AppLog.w(T.MEDIA, errorMessage); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = errorMessage; + notifyMediaListFetched(site, error, mimeType); } + }, error -> { + String errorMessage = "VolleyError Fetching media: " + error; + AppLog.e(T.MEDIA, errorMessage); + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.message = error.message; + mediaError.logMessage = error.apiError; + notifyMediaListFetched(site, mediaError, mimeType); })); } @@ -358,31 +343,25 @@ public void fetchMedia(final SiteModel site, final MediaModel media) { String url = WPCOMREST.sites.site(site.getSiteId()).media.item(media.getMediaId()).getUrlV1_1(); add(WPComGsonRequest.buildGetRequest(url, null, MediaWPComRestResponse.class, - new Listener() { - @Override - public void onResponse(MediaWPComRestResponse response) { - MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (responseMedia != null) { - responseMedia.setLocalSiteId(site.getId()); - AppLog.v(T.MEDIA, "Fetched media with ID: " + media.getMediaId()); - notifyMediaFetched(site, responseMedia, null); - } else { - String message = "could not parse Fetch media response, ID: " + media.getMediaId(); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = message; - notifyMediaFetched(site, media, error); - } - } - }, new WPComErrorListener() { - @Override - public void onErrorResponse(@NonNull WPComGsonNetworkError error) { - AppLog.e(T.MEDIA, "VolleyError Fetching media: " + error); - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.message = error.message; - mediaError.logMessage = error.apiError; - notifyMediaFetched(site, media, mediaError); + response -> { + MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); + if (responseMedia != null) { + responseMedia.setLocalSiteId(site.getId()); + AppLog.v(T.MEDIA, "Fetched media with ID: " + media.getMediaId()); + notifyMediaFetched(site, responseMedia, null); + } else { + String message = "could not parse Fetch media response, ID: " + media.getMediaId(); + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = message; + notifyMediaFetched(site, media, error); } + }, error -> { + AppLog.e(T.MEDIA, "VolleyError Fetching media: " + error); + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.message = error.message; + mediaError.logMessage = error.apiError; + notifyMediaFetched(site, media, mediaError); })); } @@ -400,34 +379,28 @@ public void deleteMedia(final SiteModel site, final MediaModel media) { String url = WPCOMREST.sites.site(site.getSiteId()).media.item(media.getMediaId()).delete.getUrlV1_1(); add(WPComGsonRequest.buildPostRequest(url, null, MediaWPComRestResponse.class, - new Listener() { - @Override - public void onResponse(MediaWPComRestResponse response) { - MediaModel deletedMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (deletedMedia != null) { - AppLog.v(T.MEDIA, "deleted media: " + media.getTitle()); - notifyMediaDeleted(site, media, null); - } else { - String message = "could not parse delete media response, ID: " + media.getMediaId(); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = message; - notifyMediaDeleted(site, media, error); - } + response -> { + MediaModel deletedMedia = mMediaResponseUtils.getMediaFromRestResponse(response); + if (deletedMedia != null) { + AppLog.v(T.MEDIA, "deleted media: " + media.getTitle()); + notifyMediaDeleted(site, media, null); + } else { + String message = "could not parse delete media response, ID: " + media.getMediaId(); + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = message; + notifyMediaDeleted(site, media, error); } - }, new WPComErrorListener() { - @Override - public void onErrorResponse(@NonNull WPComGsonNetworkError error) { - AppLog.e(T.MEDIA, "VolleyError deleting media (ID=" + media.getMediaId() + "): " + error); - MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); - if (mediaErrorType == MediaErrorType.NOT_FOUND) { - AppLog.i(T.MEDIA, "Attempted to delete media that does not exist remotely."); - } - MediaError mediaError = new MediaError(mediaErrorType); - mediaError.message = error.message; - mediaError.logMessage = error.apiError; - notifyMediaDeleted(site, media, mediaError); + }, error -> { + AppLog.e(T.MEDIA, "VolleyError deleting media (ID=" + media.getMediaId() + "): " + error); + MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); + if (mediaErrorType == MediaErrorType.NOT_FOUND) { + AppLog.i(T.MEDIA, "Attempted to delete media that does not exist remotely."); } + MediaError mediaError = new MediaError(mediaErrorType); + mediaError.message = error.message; + mediaError.logMessage = error.apiError; + notifyMediaDeleted(site, media, mediaError); })); } @@ -475,24 +448,18 @@ public void uploadStockMedia(@NonNull final SiteModel site, body.put("external_ids", jsonBody); WPComGsonRequest request = WPComGsonRequest.buildPostRequest(url, body, MultipleMediaResponse.class, - new com.android.volley.Response.Listener() { - @Override - public void onResponse(MultipleMediaResponse response) { - // response is a list of media, exactly like that of MediaRestClient.fetchMediaList() - List mediaList = - mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); - UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); - mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); - } - }, new WPComErrorListener() { - @Override - public void onErrorResponse(@NonNull WPComGsonNetworkError error) { - AppLog.e(AppLog.T.MEDIA, "VolleyError uploading stock media: " + error); - UploadStockMediaError mediaError = new UploadStockMediaError( - UploadStockMediaErrorType.fromNetworkError(error), error.message); - UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaError); - mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); - } + response -> { + // response is a list of media, exactly like that of MediaRestClient.fetchMediaList() + List mediaList = + mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); + UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); + mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); + }, error -> { + AppLog.e(T.MEDIA, "VolleyError uploading stock media: " + error); + UploadStockMediaError mediaError = new UploadStockMediaError( + UploadStockMediaErrorType.fromNetworkError(error), error.message); + UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaError); + mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); }); add(request); From 68aedbf998db2a41591e475fc3f731f39c373a87 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:40:40 +0300 Subject: [PATCH 04/87] Refactor: Replace anonymous classes with lambda on media xmlrpc client --- .../xmlrpc/media/MediaXMLRPCClient.java | 233 ++++++++---------- 1 file changed, 104 insertions(+), 129 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 5a730f0db9..8fdb28eb0e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -18,7 +18,6 @@ import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.network.BaseRequest; -import org.wordpress.android.fluxc.network.BaseRequest.BaseErrorListener; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; import org.wordpress.android.fluxc.network.BaseUploadRequestBody.ProgressListener; import org.wordpress.android.fluxc.network.HTTPAuthManager; @@ -101,39 +100,33 @@ public void pushMedia(final SiteModel site, final MediaModel media) { List params = getBasicParams(site, media); params.add(getEditMediaFields(media)); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.EDIT_POST, params, - new Listener() { - @Override - public void onResponse(Object response) { - // response should be a boolean indicating result of push request - if (response == null || !(response instanceof Boolean) || !(Boolean) response) { - String message = "could not parse XMLRPC.EDIT_MEDIA response: " + response; - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = message; - notifyMediaPushed(site, media, error); - return; - } + (Listener) response -> { + // response should be a boolean indicating result of push request + if (response == null || !(response instanceof Boolean) || !(Boolean) response) { + String message = "could not parse XMLRPC.EDIT_MEDIA response: " + response; + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = message; + notifyMediaPushed(site, media, error); + return; + } - // success! - AppLog.i(T.MEDIA, "Media updated on remote: " + media.getTitle()); + // success! + AppLog.i(T.MEDIA, "Media updated on remote: " + media.getTitle()); + notifyMediaPushed(site, media, null); + }, error -> { + String errorMessage = "error response to XMLRPC.EDIT_MEDIA request: " + error; + AppLog.e(T.MEDIA, errorMessage); + if (is404Response(error)) { + AppLog.e(T.MEDIA, "media does not exist, no need to report error"); notifyMediaPushed(site, media, null); + } else { + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.message = error.message; + mediaError.logMessage = errorMessage; + notifyMediaPushed(site, media, mediaError); } - }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String errorMessage = "error response to XMLRPC.EDIT_MEDIA request: " + error; - AppLog.e(T.MEDIA, errorMessage); - if (is404Response(error)) { - AppLog.e(T.MEDIA, "media does not exist, no need to report error"); - notifyMediaPushed(site, media, null); - } else { - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.message = error.message; - mediaError.logMessage = errorMessage; - notifyMediaPushed(site, media, mediaError); - } - } - })); + })); } /** @@ -285,33 +278,27 @@ public void fetchMediaList(final SiteModel site, final int number, final int off params.add(queryParams); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.GET_MEDIA_LIBRARY, params, - new Listener() { - @Override - public void onResponse(Object[] response) { - List mediaList = getMediaListFromXmlrpcResponse(response, site.getId()); - if (mediaList != null) { - AppLog.v(T.MEDIA, "Fetched media list for site via XMLRPC.GET_MEDIA_LIBRARY"); - boolean canLoadMore = mediaList.size() == number; - notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); - } else { - String message = "could not parse XMLRPC.GET_MEDIA_LIBRARY response: " - + Arrays.toString(response); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "XMLRPC: " + message; - notifyMediaListFetched(site, error, mimeType); - } + response -> { + List mediaList = getMediaListFromXmlrpcResponse(response, site.getId()); + if (mediaList != null) { + AppLog.v(T.MEDIA, "Fetched media list for site via XMLRPC.GET_MEDIA_LIBRARY"); + boolean canLoadMore = mediaList.size() == number; + notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); + } else { + String message = "could not parse XMLRPC.GET_MEDIA_LIBRARY response: " + + Arrays.toString(response); + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = "XMLRPC: " + message; + notifyMediaListFetched(site, error, mimeType); } - }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; - AppLog.e(T.MEDIA, message, error.volleyError); - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaListFetched(site, mediaError, mimeType); - } - })); + }, error -> { + String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; + AppLog.e(T.MEDIA, message, error.volleyError); + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaListFetched(site, mediaError, mimeType); + })); } public void fetchMedia(final SiteModel site, final MediaModel media) { @@ -336,55 +323,49 @@ private void fetchMedia(final SiteModel site, final MediaModel media, final bool List params = getBasicParams(site, media); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.GET_MEDIA_ITEM, params, - new Listener() { - @Override - public void onResponse(Object response) { - AppLog.v(T.MEDIA, "Fetched media for site via XMLRPC.GET_MEDIA_ITEM"); - MediaModel responseMedia = getMediaFromXmlrpcResponse((HashMap) response); - if (responseMedia != null) { - AppLog.v(T.MEDIA, "Fetched media with remoteId= " + media.getMediaId() - + " localId=" + media.getId()); - // Retain local IDs - responseMedia.setId(media.getId()); - responseMedia.setLocalSiteId(site.getId()); - responseMedia.setLocalPostId(media.getLocalPostId()); - responseMedia.setMarkedLocallyAsFeatured(media.getMarkedLocallyAsFeatured()); - - if (isFreshUpload) { - notifyMediaUploaded(responseMedia, null); - } else { - notifyMediaFetched(site, responseMedia, null); - } + (Listener) response -> { + AppLog.v(T.MEDIA, "Fetched media for site via XMLRPC.GET_MEDIA_ITEM"); + MediaModel responseMedia = getMediaFromXmlrpcResponse((HashMap) response); + if (responseMedia != null) { + AppLog.v(T.MEDIA, "Fetched media with remoteId= " + media.getMediaId() + + " localId=" + media.getId()); + // Retain local IDs + responseMedia.setId(media.getId()); + responseMedia.setLocalSiteId(site.getId()); + responseMedia.setLocalPostId(media.getLocalPostId()); + responseMedia.setMarkedLocallyAsFeatured(media.getMarkedLocallyAsFeatured()); + + if (isFreshUpload) { + notifyMediaUploaded(responseMedia, null); } else { - String message = "could not parse Fetch media response, ID: " + media.getMediaId(); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "XMLRPC: " + message; - if (isFreshUpload) { - notifyMediaUploaded(media, error); - } else { - notifyMediaFetched(site, media, error); - } + notifyMediaFetched(site, responseMedia, null); + } + } else { + String message = "could not parse Fetch media response, ID: " + media.getMediaId(); + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = "XMLRPC: " + message; + if (isFreshUpload) { + notifyMediaUploaded(media, error); + } else { + notifyMediaFetched(site, media, error); } } - }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "XMLRPC.GET_MEDIA_ITEM error response: " + error; - AppLog.e(T.MEDIA, message); - if (isFreshUpload) { - // we tried to fetch a media that's just uploaded but failed, so we should return - // an upload error and not a fetch error as initially parsing the upload response failed - MediaError mediaError = new MediaError(MediaErrorType.PARSE_ERROR); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaUploaded(media, mediaError); - } else { - MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaFetched(site, media, mediaError); - } - } - })); + }, error -> { + String message = "XMLRPC.GET_MEDIA_ITEM error response: " + error; + AppLog.e(T.MEDIA, message); + if (isFreshUpload) { + // we tried to fetch a media that's just uploaded but failed, so we should return + // an upload error and not a fetch error as initially parsing the upload response failed + MediaError mediaError = new MediaError(MediaErrorType.PARSE_ERROR); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaUploaded(media, mediaError); + } else { + MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaFetched(site, media, mediaError); + } + })); } public void deleteMedia(final SiteModel site, final MediaModel media) { @@ -398,33 +379,27 @@ public void deleteMedia(final SiteModel site, final MediaModel media) { List params = getBasicParams(site, media); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.DELETE_POST, params, - new Listener() { - @Override - public void onResponse(Object response) { - // response should be a boolean indicating result of push request - if (response == null || !(response instanceof Boolean) || !(Boolean) response) { - String message = "could not parse XMLRPC.DELETE_MEDIA response: " + response; - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "XMLRPC: " + message; - notifyMediaDeleted(site, media, error); - return; - } - - AppLog.v(T.MEDIA, "Successful response from XMLRPC.DELETE_MEDIA"); - notifyMediaDeleted(site, media, null); + (Listener) response -> { + // response should be a boolean indicating result of push request + if (response == null || !(response instanceof Boolean) || !(Boolean) response) { + String message = "could not parse XMLRPC.DELETE_MEDIA response: " + response; + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = "XMLRPC: " + message; + notifyMediaDeleted(site, media, error); + return; } - }, new BaseErrorListener() { - @Override - public void onErrorResponse(@NonNull BaseNetworkError error) { - String message = "Error response from XMLRPC.DELETE_MEDIA:" + error; - AppLog.e(T.MEDIA, message); - MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); - MediaError mediaError = new MediaError(mediaErrorType); - mediaError.logMessage = "XMLRPC: " + message; - notifyMediaDeleted(site, media, mediaError); - } - })); + + AppLog.v(T.MEDIA, "Successful response from XMLRPC.DELETE_MEDIA"); + notifyMediaDeleted(site, media, null); + }, error -> { + String message = "Error response from XMLRPC.DELETE_MEDIA:" + error; + AppLog.e(T.MEDIA, message); + MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); + MediaError mediaError = new MediaError(mediaErrorType); + mediaError.logMessage = "XMLRPC: " + message; + notifyMediaDeleted(site, media, mediaError); + })); } public void cancelUpload(final MediaModel media) { From 8afc67a50ac001a01edf518aea7c07cc4d5fb09a Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:42:54 +0300 Subject: [PATCH 05/87] Analysis: Add missing final to ok http client field on media clients Warning: "Field 'mOkHttpClient' may be 'final'" --- .../android/fluxc/network/rest/wpcom/media/MediaRestClient.java | 2 +- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index b57d725370..003b108c70 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -80,7 +80,7 @@ */ @Singleton public class MediaRestClient extends BaseWPComRestClient implements ProgressListener { - private OkHttpClient mOkHttpClient; + private final OkHttpClient mOkHttpClient; private MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 8fdb28eb0e..9fbc091cc9 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -74,7 +74,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe private static final String[] REQUIRED_UPLOAD_RESPONSE_FIELDS = { "attachment_id", "parent", "title", "caption", "description", "thumbnail", "date_created_gmt", "link"}; - private OkHttpClient mOkHttpClient; + private final OkHttpClient mOkHttpClient; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); From b7c74c1a55781cef476f5cc197ae1280d8d0c9c5 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:43:44 +0300 Subject: [PATCH 06/87] Analysis: Add missing final to media response utils field on media rest Warning: "Field 'mMediaResponseUtils' may be 'final'" --- .../android/fluxc/network/rest/wpcom/media/MediaRestClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 003b108c70..3d65f1fc06 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -81,7 +81,7 @@ @Singleton public class MediaRestClient extends BaseWPComRestClient implements ProgressListener { private final OkHttpClient mOkHttpClient; - private MediaResponseUtils mMediaResponseUtils; + private final MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); From 224c637f66df88092b09bae4f65837e055d618d0 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:44:30 +0300 Subject: [PATCH 07/87] Analysis: Add missing final to cnt upload calls field on media clients Warning: "Field 'mCurrentUploadCalls' may be 'final'" --- .../android/fluxc/network/rest/wpcom/media/MediaRestClient.java | 2 +- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 3d65f1fc06..5cf682ba01 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -84,7 +84,7 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList private final MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads - private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); + private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @Inject public MediaRestClient( Context appContext, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 9fbc091cc9..769c70a462 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -77,7 +77,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe private final OkHttpClient mOkHttpClient; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads - private ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); + private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @Inject public MediaXMLRPCClient( Dispatcher dispatcher, From 05c2fb5a9630512d6fb8792c29b34a76dbf00924 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:48:01 +0300 Subject: [PATCH 08/87] Analysis: Un-guard usages of media error on media rest client --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 5cf682ba01..5b3d7ca29f 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -263,7 +263,7 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO MediaError error = parseUploadError(response, site); - if (null != error && error.type == MediaErrorType.BAD_REQUEST) { + if (error.type == MediaErrorType.BAD_REQUEST) { AppLog.e(T.MEDIA, "media upload error message: " + error.message); } @@ -468,7 +468,10 @@ public void uploadStockMedia(@NonNull final SiteModel site, // // Helper methods to dispatch media actions // - private MediaError parseUploadError(Response response, SiteModel siteModel) { + @NonNull + private MediaError parseUploadError( + @NonNull Response response, + @NonNull SiteModel siteModel) { MediaError mediaError = new MediaError(MediaErrorType.fromHttpStatusCode(response.code())); mediaError.statusCode = response.code(); mediaError.logMessage = response.message(); From db21abff8fe8e0fdd5e2636ab48b3d873fcdb8e7 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:49:23 +0300 Subject: [PATCH 09/87] Analysis: Change type of request to include the missing generic type Warning: "Raw use of parameterized class 'WPComGsonRequest'" --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 5b3d7ca29f..7cf49576ce 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -447,7 +447,10 @@ public void uploadStockMedia(@NonNull final SiteModel site, body.put("service", "pexels"); body.put("external_ids", jsonBody); - WPComGsonRequest request = WPComGsonRequest.buildPostRequest(url, body, MultipleMediaResponse.class, + WPComGsonRequest request = WPComGsonRequest.buildPostRequest( + url, + body, + MultipleMediaResponse.class, response -> { // response is a list of media, exactly like that of MediaRestClient.fetchMediaList() List mediaList = From 46901f1588f2614822a3506fce7978dc0db54d38 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:51:24 +0300 Subject: [PATCH 10/87] Docs: Replace url with html link on media rest client Warning: "Link specified as plain text" --- .../android/fluxc/network/rest/wpcom/media/MediaRestClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 7cf49576ce..3bcb0377eb 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -587,7 +587,7 @@ private void notifyMediaUploadCanceled(MediaModel media) { * The current REST API call (v1.1) accepts 'title', 'description', 'caption', 'alt', * and 'parent_id' for all media. Audio media also accepts 'artist' and 'album' attributes. *

- * ref https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/ + * @see documentation */ private Map getEditRequestParams(final MediaModel media) { if (media == null) { From 0381ccc9f8306ea14d15586922f1637acdb00ebe Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 17 Oct 2023 17:55:36 +0300 Subject: [PATCH 11/87] Analysis: Guard usages of media list on media rest client --- .../network/rest/wpcom/media/MediaRestClient.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 3bcb0377eb..87555c6bdc 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -455,8 +455,16 @@ public void uploadStockMedia(@NonNull final SiteModel site, // response is a list of media, exactly like that of MediaRestClient.fetchMediaList() List mediaList = mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); - UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); - mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); + if (mediaList != null) { + UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); + mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); + } else { + AppLog.e(T.MEDIA, "Media list is null: " + response); + UploadStockMediaError mediaError = new UploadStockMediaError( + UploadStockMediaErrorType.GENERIC_ERROR, "Media list is null"); + UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaError); + mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); + } }, error -> { AppLog.e(T.MEDIA, "VolleyError uploading stock media: " + error); UploadStockMediaError mediaError = new UploadStockMediaError( From ea3a3fd5a2242073341007b2a0f7a178d8d2ea5c Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:28:18 +0300 Subject: [PATCH 12/87] Analysis: Remove unnecessary is response null checks on media xmlrpc clt Warning: "Condition 'response == null' covered by subsequent condition '!(response instanceof Boolean)'" --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 769c70a462..46417333c8 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -102,7 +102,7 @@ public void pushMedia(final SiteModel site, final MediaModel media) { add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.EDIT_POST, params, (Listener) response -> { // response should be a boolean indicating result of push request - if (response == null || !(response instanceof Boolean) || !(Boolean) response) { + if (!(response instanceof Boolean) || !(Boolean) response) { String message = "could not parse XMLRPC.EDIT_MEDIA response: " + response; AppLog.w(T.MEDIA, message); MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); @@ -381,7 +381,7 @@ public void deleteMedia(final SiteModel site, final MediaModel media) { add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.DELETE_POST, params, (Listener) response -> { // response should be a boolean indicating result of push request - if (response == null || !(response instanceof Boolean) || !(Boolean) response) { + if (!(response instanceof Boolean) || !(Boolean) response) { String message = "could not parse XMLRPC.DELETE_MEDIA response: " + response; AppLog.w(T.MEDIA, message); MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); From 935071b93a4d80ee3b3fdc13aa3a38f093a491a1 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:29:15 +0300 Subject: [PATCH 13/87] Docs: Replace urls with html links on media xmlrpc client Warning: "Link specified as plain text" --- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 46417333c8..5d8a96630f 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -130,7 +130,7 @@ public void pushMedia(final SiteModel site, final MediaModel media) { } /** - * ref: https://codex.wordpress.org/XML-RPC_WordPress_API/Media#wp.uploadFile + * @see documentation */ public void uploadMedia(final SiteModel site, final MediaModel media) { URL xmlrpcUrl; @@ -263,7 +263,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) { } /** - * ref: https://codex.wordpress.org/XML-RPC_WordPress_API/Media#wp.getMediaLibrary + * @see documentation */ public void fetchMediaList(final SiteModel site, final int number, final int offset, final MimeType.Type mimeType) { List params = getBasicParams(site, null); @@ -306,7 +306,7 @@ public void fetchMedia(final SiteModel site, final MediaModel media) { } /** - * ref: https://codex.wordpress.org/XML-RPC_WordPress_API/Media#wp.getMediaItem + * @see documentation */ private void fetchMedia(final SiteModel site, final MediaModel media, final boolean isFreshUpload) { if (media == null) { From 54b6c24d83cb0fbee46ab806ac8434cde6f3810b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:41:45 +0300 Subject: [PATCH 14/87] Analysis: Remove io exception from throws list on media xmlrpc client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warning: “Exception ‘java.io.IOException’ is never thrown in the method” --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 5d8a96630f..5b086f5be3 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -197,7 +197,7 @@ public void uploadMedia(final SiteModel site, final MediaModel media) { AppLog.d(T.MEDIA, "starting upload for: " + media.getId()); call.enqueue(new Callback() { @Override - public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == HttpURLConnection.HTTP_OK) { // HTTP_OK code doesn't mean the upload is successful, XML-RPC API returns code 200 with an // xml field "faultCode" on error. From 8e4e95cd9a9367c6c91cc8b78961438b400e0d20 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:45:01 +0300 Subject: [PATCH 15/87] Analysis: Suppress use of parameterized class map on media xmlrpc client Warnings: - "Raw use of parameterized class 'Map'" - "Raw use of parameterized class 'HashMap'" --- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 5b086f5be3..217376626c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -197,6 +197,7 @@ public void uploadMedia(final SiteModel site, final MediaModel media) { AppLog.d(T.MEDIA, "starting upload for: " + media.getId()); call.enqueue(new Callback() { @Override + @SuppressWarnings("rawtypes") public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == HttpURLConnection.HTTP_OK) { // HTTP_OK code doesn't mean the upload is successful, XML-RPC API returns code 200 with an @@ -308,6 +309,7 @@ public void fetchMedia(final SiteModel site, final MediaModel media) { /** * @see documentation */ + @SuppressWarnings("rawtypes") private void fetchMedia(final SiteModel site, final MediaModel media, final boolean isFreshUpload) { if (media == null) { // caller may be expecting a notification @@ -487,6 +489,7 @@ private void notifyMediaUploadCanceled(MediaModel media) { // // media list responses should be of type Object[] with each media item in the array represented by a HashMap + @SuppressWarnings("rawtypes") private List getMediaListFromXmlrpcResponse(Object[] response, int localSiteId) { if (response == null) { return null; @@ -507,6 +510,7 @@ private List getMediaListFromXmlrpcResponse(Object[] response, int l return responseMedia; } + @SuppressWarnings("rawtypes") private MediaModel getMediaFromXmlrpcResponse(Map response) { if (response == null || response.isEmpty()) { return null; @@ -543,6 +547,7 @@ private MediaModel getMediaFromXmlrpcResponse(Map response) { return media; } + @SuppressWarnings("rawtypes") private String getFileUrlForSize(String mediaUrl, Map metadataMap, String size) { if (metadataMap == null || TextUtils.isEmpty(mediaUrl) || !mediaUrl.contains("/")) { return null; @@ -562,6 +567,7 @@ private String getFileUrlForSize(String mediaUrl, Map metadataMap, String size) return baseURL + fileName; } + @SuppressWarnings("rawtypes") private String getFileForSize(Map metadataMap, String size) { if (metadataMap == null) { return null; @@ -601,6 +607,7 @@ private MediaError getMediaErrorFromXMLRPCException(XMLRPCException exception) { return mediaError; } + @SuppressWarnings("rawtypes") private static Map getMapFromUploadResponse(Response response) throws XMLRPCException { try { ResponseBody responseBody = response.body(); @@ -621,6 +628,7 @@ private static Map getMapFromUploadResponse(Response response) throws XMLRPCExce return null; } + @SuppressWarnings("rawtypes") private static boolean isDeprecatedUploadResponse(Map responseMap) { for (String requiredResponseField : REQUIRED_UPLOAD_RESPONSE_FIELDS) { if (!responseMap.containsKey(requiredResponseField)) { From d87de3d495d7fe9fe65ddb8ff5ba9da53c27d5fa Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:49:57 +0300 Subject: [PATCH 16/87] Analysis: Replace string/charset with std charsets utf8 on media xmlrpc Warning: "StandardCharsets.UTF_8 can be used instead" --- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 217376626c..f700fab136 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -47,7 +47,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -615,8 +615,8 @@ private static Map getMapFromUploadResponse(Response response) throws XMLRPCExce AppLog.e(T.MEDIA, "Failed to parse XMLRPC.wpUploadFile response - body was empty: " + response); return null; } - String data = new String(responseBody.bytes(), "UTF-8"); - InputStream is = new ByteArrayInputStream(data.getBytes(Charset.forName("UTF-8"))); + String data = new String(responseBody.bytes(), StandardCharsets.UTF_8); + InputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); Object responseObject = XMLSerializerUtils.deserialize(XMLSerializerUtils.scrubXmlResponse(is)); if (responseObject instanceof Map) { return (Map) responseObject; From 78538652775b8e3c6c800ffa029244319eea9eab Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:54:46 +0300 Subject: [PATCH 17/87] Analysis: Simplify if/else on media xmlrpc client Warning: "'if' statement can be simplified" --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index f700fab136..f373c3f76b 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -662,9 +662,7 @@ private boolean is404Response(BaseNetworkError error) { } if (volleyError.getCause() instanceof XMLRPCFault) { - if (((XMLRPCFault) volleyError.getCause()).getFaultCode() == HttpURLConnection.HTTP_NOT_FOUND) { - return true; - } + return ((XMLRPCFault) volleyError.getCause()).getFaultCode() == HttpURLConnection.HTTP_NOT_FOUND; } } From 24f609316f9601934b9898d6daf5514e00ffd39f Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 12:58:21 +0300 Subject: [PATCH 18/87] Analysis: Add missing nn-a to ok http client field on media clients FYI: 'nn-a' stands for 'non-null annotation'. --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 4 ++-- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 87555c6bdc..a1103536f5 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -80,7 +80,7 @@ */ @Singleton public class MediaRestClient extends BaseWPComRestClient implements ProgressListener { - private final OkHttpClient mOkHttpClient; + @NonNull private final OkHttpClient mOkHttpClient; private final MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads @@ -90,7 +90,7 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList Context appContext, Dispatcher dispatcher, @Named("regular") RequestQueue requestQueue, - @Named("regular") OkHttpClient okHttpClient, + @NonNull @Named("regular") OkHttpClient okHttpClient, AccessToken accessToken, UserAgent userAgent, MediaResponseUtils mediaResponseUtils) { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index f373c3f76b..3b5f5e66fb 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -74,7 +74,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe private static final String[] REQUIRED_UPLOAD_RESPONSE_FIELDS = { "attachment_id", "parent", "title", "caption", "description", "thumbnail", "date_created_gmt", "link"}; - private final OkHttpClient mOkHttpClient; + @NonNull private final OkHttpClient mOkHttpClient; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @@ -82,7 +82,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe @Inject public MediaXMLRPCClient( Dispatcher dispatcher, @Named("custom-ssl") RequestQueue requestQueue, - @Named("custom-ssl") OkHttpClient okHttpClient, + @NonNull @Named("custom-ssl") OkHttpClient okHttpClient, UserAgent userAgent, HTTPAuthManager httpAuthManager) { super(dispatcher, requestQueue, userAgent, httpAuthManager); From e06b98624e400a98f53c2d7f9efea0d660e96e5d Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 13:02:33 +0300 Subject: [PATCH 19/87] Analysis: Add missing nn-a to media response utils field on media rest FYI: 'nn-a' stands for 'non-null annotation'. --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index a1103536f5..ce182b3c6c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -81,7 +81,7 @@ @Singleton public class MediaRestClient extends BaseWPComRestClient implements ProgressListener { @NonNull private final OkHttpClient mOkHttpClient; - private final MediaResponseUtils mMediaResponseUtils; + @NonNull private final MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @@ -93,7 +93,7 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList @NonNull @Named("regular") OkHttpClient okHttpClient, AccessToken accessToken, UserAgent userAgent, - MediaResponseUtils mediaResponseUtils) { + @NonNull MediaResponseUtils mediaResponseUtils) { super(appContext, dispatcher, requestQueue, accessToken, userAgent); mOkHttpClient = okHttpClient; mMediaResponseUtils = mediaResponseUtils; From 3db2009965d3cd016a080f6e73ed5b7881203126 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 13:03:18 +0300 Subject: [PATCH 20/87] Analysis: Add missing nn-a to current upload calls field on media clts FYI: 'nn-a' stands for 'non-null annotation'. --- .../android/fluxc/network/rest/wpcom/media/MediaRestClient.java | 2 +- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index ce182b3c6c..5b75d81f26 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -84,7 +84,7 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList @NonNull private final MediaResponseUtils mMediaResponseUtils; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads - private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); + @NonNull private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @Inject public MediaRestClient( Context appContext, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 3b5f5e66fb..107eac4997 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -77,7 +77,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe @NonNull private final OkHttpClient mOkHttpClient; // this will hold which media is being uploaded by which call, in order to be able // to monitor multiple uploads - private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); + @NonNull private final ConcurrentHashMap mCurrentUploadCalls = new ConcurrentHashMap<>(); @Inject public MediaXMLRPCClient( Dispatcher dispatcher, From 1f879abf1372fe7f2db1a22b5146242409eae1fc Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 14:43:43 +0300 Subject: [PATCH 21/87] Analysis: Add missing n-a to on progress on media clients FYI: 'n-a' stands for 'nullability annotations'. --- .../fluxc/network/BaseUploadRequestBody.java | 30 ++++++++----------- .../rest/wpcom/media/MediaRestClient.java | 11 +++---- .../wpcom/media/RestUploadRequestBody.java | 11 +++++-- .../xmlrpc/media/MediaXMLRPCClient.java | 4 +-- .../xmlrpc/media/XmlrpcUploadRequestBody.java | 8 +++-- .../android/fluxc/utils/MediaUtils.java | 2 ++ 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java index e497bb9284..539be09eaf 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java @@ -29,7 +29,7 @@ public abstract class BaseUploadRequestBody extends RequestBody { * Callback to report upload progress as body data is written to the sink for network delivery. */ public interface ProgressListener { - void onProgress(MediaModel media, float progress); + void onProgress(@NonNull MediaModel media, float progress); } /** @@ -40,15 +40,15 @@ public interface ProgressListener { *
  • define a file path to a valid local file
  • * * - * @return null if {@code media} is valid, otherwise a string describing why it's invalid + * @return a string describing why {@code media} is invalid */ - public static String hasRequiredData(MediaModel media) { + @NonNull + public static String hasRequiredData(@NonNull MediaModel media) { return checkMediaArg(media).getType().getErrorLogDescription(); } - public static MalformedMediaArgSubType checkMediaArg(MediaModel media) { - if (media == null) return new MalformedMediaArgSubType(Type.MEDIA_WAS_NULL); - + @NonNull + public static MalformedMediaArgSubType checkMediaArg(@NonNull MediaModel media) { // validate MIME type is recognized String mimeType = media.getMimeType(); if (!MediaUtils.isSupportedMimeType(mimeType)) { @@ -72,25 +72,19 @@ public static MalformedMediaArgSubType checkMediaArg(MediaModel media) { return new MalformedMediaArgSubType(Type.NO_ERROR); } - private final MediaModel mMedia; - private final ProgressListener mListener; - - public BaseUploadRequestBody(MediaModel media, ProgressListener listener) { - // validate arguments - if (listener == null) { - throw new IllegalArgumentException("progress listener cannot be null"); - } - String mediaError = hasRequiredData(media); - if (mediaError != null) { - throw new IllegalArgumentException(mediaError); - } + @NonNull private final MediaModel mMedia; + @NonNull private final ProgressListener mListener; + public BaseUploadRequestBody( + @NonNull MediaModel media, + @NonNull ProgressListener listener) { mMedia = media; mListener = listener; } protected abstract float getProgress(long bytesWritten); + @NonNull public MediaModel getMedia() { return mMedia; } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 5b75d81f26..f435f8180a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -100,7 +100,7 @@ public class MediaRestClient extends BaseWPComRestClient implements ProgressList } @Override - public void onProgress(MediaModel media, float progress) { + public void onProgress(@NonNull MediaModel media, float progress) { if (mCurrentUploadCalls.containsKey(media.getId())) { notifyMediaProgress(media, Math.min(progress, 0.99f)); } @@ -542,7 +542,7 @@ private void notifyMediaPushed(SiteModel site, MediaModel media, MediaError erro mDispatcher.dispatch(MediaActionBuilder.newPushedMediaAction(payload)); } - private void notifyMediaProgress(MediaModel media, float progress) { + private void notifyMediaProgress(@NonNull MediaModel media, float progress) { ProgressPayload payload = new ProgressPayload(media, progress, false, null); mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } @@ -597,11 +597,8 @@ private void notifyMediaUploadCanceled(MediaModel media) { *

    * @see documentation */ - private Map getEditRequestParams(final MediaModel media) { - if (media == null) { - return null; - } - + @NonNull + private Map getEditRequestParams(@NonNull final MediaModel media) { MediaFields[] fieldsToUpdate = media.getFieldsToUpdate(); final Map params = new HashMap<>(); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java index 6bc6485ee2..97e6d2f401 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java @@ -30,9 +30,12 @@ public class RestUploadRequestBody extends BaseUploadRequestBody { private static final String MEDIA_ATTRIBUTES_KEY = "attrs[0]"; private static final String MEDIA_PARAM_FORMAT = MEDIA_ATTRIBUTES_KEY + "[%s]"; - private final MultipartBody mMultipartBody; + @NonNull private final MultipartBody mMultipartBody; - public RestUploadRequestBody(MediaModel media, Map params, ProgressListener listener) { + public RestUploadRequestBody( + @NonNull MediaModel media, + @NonNull Map params, + @NonNull ProgressListener listener) { super(media, listener); mMultipartBody = buildMultipartBody(params); } @@ -52,6 +55,7 @@ public long contentLength() { return -1L; } + @NonNull @Override public MediaType contentType() { return mMultipartBody.contentType(); @@ -65,7 +69,8 @@ public void writeTo(@NonNull BufferedSink sink) throws IOException { bufferedSink.flush(); } - private MultipartBody buildMultipartBody(Map params) { + @NonNull + private MultipartBody buildMultipartBody(@NonNull Map params) { MediaModel media = getMedia(); MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 107eac4997..32915736c2 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -90,7 +90,7 @@ public class MediaXMLRPCClient extends BaseXMLRPCClient implements ProgressListe } @Override - public void onProgress(MediaModel media, float progress) { + public void onProgress(@NonNull MediaModel media, float progress) { if (mCurrentUploadCalls.containsKey(media.getId())) { notifyMediaProgress(media, Math.min(progress, 0.99f)); } @@ -439,7 +439,7 @@ private void notifyMediaPushed(SiteModel site, MediaModel media, MediaError erro mDispatcher.dispatch(MediaActionBuilder.newPushedMediaAction(payload)); } - private void notifyMediaProgress(MediaModel media, float progress) { + private void notifyMediaProgress(@NonNull MediaModel media, float progress) { ProgressPayload payload = new ProgressPayload(media, progress, false, null); mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java index 3c23f28718..e8b6cd527d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java @@ -39,12 +39,15 @@ public class XmlrpcUploadRequestBody extends BaseUploadRequestBody { private static final String APPEND_XML = ""; - private final String mPrependString; + @NonNull private final String mPrependString; private long mMediaSize; private long mContentSize = -1; private long mMediaBytesWritten = 0; - public XmlrpcUploadRequestBody(MediaModel media, ProgressListener listener, SiteModel site) { + public XmlrpcUploadRequestBody( + @NonNull MediaModel media, + @NonNull ProgressListener listener, + @NonNull SiteModel site) { super(media, listener); // TODO: we should use the XMLRPCSerializer instead of doing this @@ -69,6 +72,7 @@ protected float getProgress(long bytesWritten) { return (float) mMediaBytesWritten / mMediaSize; } + @NonNull @Override public MediaType contentType() { return MEDIA_TYPE; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java index 789e858c71..9fccb7568c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java @@ -65,10 +65,12 @@ public static String getMimeTypeForExtension(String extension) { // File operations // + @NonNull public static String getMediaValidationError(@NonNull MediaModel media) { return BaseUploadRequestBody.hasRequiredData(media); } + @NonNull public static MalformedMediaArgSubType getMediaValidationErrorType(@NonNull MediaModel media) { return BaseUploadRequestBody.checkMediaArg(media); } From 02345c96eb1f827966271d6395bcfeaee3da4701 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 15:31:55 +0300 Subject: [PATCH 22/87] Analysis: Add missing n-a to push media on media clients FYI: 'n-a' stands for 'nullability annotations'. --- .../network/rest/wpcom/media/MediaRestClient.java | 8 ++++++-- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 11 ++++++++--- .../org/wordpress/android/fluxc/store/MediaStore.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index f435f8180a..0dd83794ca 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -4,6 +4,7 @@ import android.text.TextUtils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.RequestQueue; import com.google.gson.Gson; @@ -106,7 +107,7 @@ public void onProgress(@NonNull MediaModel media, float progress) { } } - public void pushMedia(final SiteModel site, final MediaModel media) { + public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { if (media == null) { // caller may be expecting a notification MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); @@ -537,7 +538,10 @@ private MediaError parseUploadError( return mediaError; } - private void notifyMediaPushed(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaPushed( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newPushedMediaAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 32915736c2..77be4d1498 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -4,6 +4,7 @@ import android.util.Base64; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; @@ -96,7 +97,7 @@ public void onProgress(@NonNull MediaModel media, float progress) { } } - public void pushMedia(final SiteModel site, final MediaModel media) { + public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { List params = getBasicParams(site, media); params.add(getEditMediaFields(media)); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.EDIT_POST, params, @@ -434,7 +435,10 @@ private void removeCallFromCurrentUploadsMap(int id) { // Helper methods to dispatch media actions // - private void notifyMediaPushed(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaPushed( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newPushedMediaAction(payload)); } @@ -638,7 +642,8 @@ private static boolean isDeprecatedUploadResponse(Map responseMap) { return false; } - private Map getEditMediaFields(final MediaModel media) { + @Nullable + private Map getEditMediaFields(@Nullable final MediaModel media) { if (media == null) { return null; } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index ab39f82fca..eb518f6e0a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -752,7 +752,7 @@ private void removeMedia(MediaModel media) { // Helper methods that choose the appropriate network client to perform an action // - private void performPushMedia(MediaPayload payload) { + private void performPushMedia(@NonNull MediaPayload payload) { if (payload.media == null) { // null or empty media list -or- list contains a null value notifyMediaError(MediaErrorType.NULL_MEDIA_ARG, MediaAction.PUSH_MEDIA, null); From 806ae6e718138138decd70a374de3a1112652b22 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 15:45:48 +0300 Subject: [PATCH 23/87] Analysis: Add missing n-a to upload media on media clients FYI: 'n-a' stands for 'nullability annotations'. --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 4 ++-- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 9 ++++++--- .../org/wordpress/android/fluxc/store/MediaStore.java | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 0dd83794ca..a43a235445 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -142,7 +142,7 @@ public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel /** * Uploads a single media item to a WP.com site. */ - public void uploadMedia(final SiteModel site, final MediaModel media) { + public void uploadMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { if (media == null || media.getId() == 0) { // we can't have a MediaModel without an ID - otherwise we can't keep track of them. MediaError error = new MediaError(MediaErrorType.INVALID_ID); @@ -551,7 +551,7 @@ private void notifyMediaProgress(@NonNull MediaModel media, float progress) { mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } - private void notifyMediaUploaded(MediaModel media, MediaError error) { + private void notifyMediaUploaded(@Nullable MediaModel media, @Nullable MediaError error) { if (media != null) { media.setUploadState(error == null ? MediaUploadState.UPLOADED : MediaUploadState.FAILED); removeCallFromCurrentUploadsMap(media.getId()); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 77be4d1498..610fa22da3 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -133,7 +133,7 @@ public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel /** * @see documentation */ - public void uploadMedia(final SiteModel site, final MediaModel media) { + public void uploadMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { URL xmlrpcUrl; try { xmlrpcUrl = new URL(site.getXmlRpcUrl()); @@ -311,7 +311,10 @@ public void fetchMedia(final SiteModel site, final MediaModel media) { * @see documentation */ @SuppressWarnings("rawtypes") - private void fetchMedia(final SiteModel site, final MediaModel media, final boolean isFreshUpload) { + private void fetchMedia( + @NonNull final SiteModel site, + @Nullable final MediaModel media, + final boolean isFreshUpload) { if (media == null) { // caller may be expecting a notification MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); @@ -448,7 +451,7 @@ private void notifyMediaProgress(@NonNull MediaModel media, float progress) { mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } - private void notifyMediaUploaded(MediaModel media, MediaError error) { + private void notifyMediaUploaded(@Nullable MediaModel media, @Nullable MediaError error) { if (media != null) { media.setUploadState(error == null ? MediaUploadState.UPLOADED : MediaUploadState.FAILED); removeCallFromCurrentUploadsMap(media.getId()); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index eb518f6e0a..3baf4ba461 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -779,7 +779,7 @@ private void notifyMediaUploadError(MediaErrorType errorType, String errorMessag emitChange(onMediaUploaded); } - private void performUploadMedia(UploadMediaPayload payload) { + private void performUploadMedia(@NonNull UploadMediaPayload payload) { MalformedMediaArgSubType argError = MediaUtils.getMediaValidationErrorType(payload.media); if (argError.getType() != Type.NO_ERROR) { From 95eb024cc0c56e61a256cfce6539607658db4775 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:07:31 +0300 Subject: [PATCH 24/87] Analysis: Add missing n-a to fetch media list on media clients FYI: 'n-a' stands for 'nullability annotations'. --- .../rest/wpcom/media/MediaRestClient.java | 22 +++++++++++++------ .../xmlrpc/media/MediaXMLRPCClient.java | 22 +++++++++++++------ .../android/fluxc/store/MediaStore.java | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index a43a235445..2d6bbccd72 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -295,7 +295,11 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) { * NOTE: Only media item data is gathered, the actual media file can be downloaded from the URL * provided in the response {@link MediaModel}'s (via {@link MediaModel#getUrl()}). */ - public void fetchMediaList(final SiteModel site, final int number, final int offset, final MimeType.Type mimeType) { + public void fetchMediaList( + @NonNull final SiteModel site, + final int number, + final int offset, + @Nullable final MimeType.Type mimeType) { final Map params = new HashMap<>(); params.put("number", String.valueOf(number)); if (offset > 0) { @@ -561,17 +565,21 @@ private void notifyMediaUploaded(@Nullable MediaModel media, @Nullable MediaErro mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } - private void notifyMediaListFetched(SiteModel site, - @NonNull List media, - boolean loadedMore, - boolean canLoadMore, - MimeType.Type mimeType) { + private void notifyMediaListFetched( + @NonNull SiteModel site, + @NonNull List media, + boolean loadedMore, + boolean canLoadMore, + @Nullable MimeType.Type mimeType) { FetchMediaListResponsePayload payload = new FetchMediaListResponsePayload(site, media, loadedMore, canLoadMore, mimeType); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } - private void notifyMediaListFetched(SiteModel site, MediaError error, MimeType.Type mimeType) { + private void notifyMediaListFetched( + @NonNull SiteModel site, + @NonNull MediaError error, + @Nullable MimeType.Type mimeType) { FetchMediaListResponsePayload payload = new FetchMediaListResponsePayload(site, error, mimeType); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 610fa22da3..b9ccdc7839 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -267,7 +267,11 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) { /** * @see documentation */ - public void fetchMediaList(final SiteModel site, final int number, final int offset, final MimeType.Type mimeType) { + public void fetchMediaList( + @NonNull final SiteModel site, + final int number, + final int offset, + @Nullable final MimeType.Type mimeType) { List params = getBasicParams(site, null); Map queryParams = new HashMap<>(); queryParams.put("number", number); @@ -461,17 +465,21 @@ private void notifyMediaUploaded(@Nullable MediaModel media, @Nullable MediaErro mDispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)); } - private void notifyMediaListFetched(SiteModel site, - @NonNull List media, - boolean loadedMore, - boolean canLoadMore, - MimeType.Type mimeType) { + private void notifyMediaListFetched( + @NonNull SiteModel site, + @NonNull List media, + boolean loadedMore, + boolean canLoadMore, + @Nullable MimeType.Type mimeType) { FetchMediaListResponsePayload payload = new FetchMediaListResponsePayload(site, media, loadedMore, canLoadMore, mimeType); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } - private void notifyMediaListFetched(SiteModel site, MediaError error, MimeType.Type mimeType) { + private void notifyMediaListFetched( + @NonNull SiteModel site, + @NonNull MediaError error, + @Nullable MimeType.Type mimeType) { FetchMediaListResponsePayload payload = new FetchMediaListResponsePayload(site, error, mimeType); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 3baf4ba461..f64ac22374 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -816,7 +816,7 @@ private void performUploadMedia(@NonNull UploadMediaPayload payload) { } } - private void performFetchMediaList(FetchMediaListPayload payload) { + private void performFetchMediaList(@NonNull FetchMediaListPayload payload) { int offset = 0; if (payload.loadMore) { List list = new ArrayList<>(); From e01e7c1db772106edad7789ed8952e521fb9f01b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:11:54 +0300 Subject: [PATCH 25/87] Refactor: Reformat error responses on media clients --- .../rest/wpcom/media/MediaRestClient.java | 16 +++++++++++----- .../network/xmlrpc/media/MediaXMLRPCClient.java | 12 ++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 2d6bbccd72..23032cd2e1 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -130,7 +130,8 @@ public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel error.logMessage = "Parsed media is null"; notifyMediaPushed(site, media, error); } - }, error -> { + }, + error -> { String errorMessage = "error editing remote media: " + error; AppLog.e(T.MEDIA, errorMessage); MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); @@ -324,7 +325,8 @@ public void fetchMediaList( error.logMessage = errorMessage; notifyMediaListFetched(site, error, mimeType); } - }, error -> { + }, + error -> { String errorMessage = "VolleyError Fetching media: " + error; AppLog.e(T.MEDIA, errorMessage); MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); @@ -361,7 +363,8 @@ public void fetchMedia(final SiteModel site, final MediaModel media) { error.logMessage = message; notifyMediaFetched(site, media, error); } - }, error -> { + }, + error -> { AppLog.e(T.MEDIA, "VolleyError Fetching media: " + error); MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); mediaError.message = error.message; @@ -396,7 +399,8 @@ public void deleteMedia(final SiteModel site, final MediaModel media) { error.logMessage = message; notifyMediaDeleted(site, media, error); } - }, error -> { + }, + error -> { AppLog.e(T.MEDIA, "VolleyError deleting media (ID=" + media.getMediaId() + "): " + error); MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); if (mediaErrorType == MediaErrorType.NOT_FOUND) { @@ -470,7 +474,8 @@ public void uploadStockMedia(@NonNull final SiteModel site, UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaError); mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); } - }, error -> { + }, + error -> { AppLog.e(T.MEDIA, "VolleyError uploading stock media: " + error); UploadStockMediaError mediaError = new UploadStockMediaError( UploadStockMediaErrorType.fromNetworkError(error), error.message); @@ -607,6 +612,7 @@ private void notifyMediaUploadCanceled(MediaModel media) { * The current REST API call (v1.1) accepts 'title', 'description', 'caption', 'alt', * and 'parent_id' for all media. Audio media also accepts 'artist' and 'album' attributes. *

    + * * @see documentation */ @NonNull diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index b9ccdc7839..6ae0e75958 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -115,7 +115,8 @@ public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel // success! AppLog.i(T.MEDIA, "Media updated on remote: " + media.getTitle()); notifyMediaPushed(site, media, null); - }, error -> { + }, + error -> { String errorMessage = "error response to XMLRPC.EDIT_MEDIA request: " + error; AppLog.e(T.MEDIA, errorMessage); if (is404Response(error)) { @@ -298,7 +299,8 @@ public void fetchMediaList( error.logMessage = "XMLRPC: " + message; notifyMediaListFetched(site, error, mimeType); } - }, error -> { + }, + error -> { String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; AppLog.e(T.MEDIA, message, error.volleyError); MediaError mediaError = new MediaError(MediaErrorType.fromBaseNetworkError(error)); @@ -361,7 +363,8 @@ private void fetchMedia( notifyMediaFetched(site, media, error); } } - }, error -> { + }, + error -> { String message = "XMLRPC.GET_MEDIA_ITEM error response: " + error; AppLog.e(T.MEDIA, message); if (isFreshUpload) { @@ -402,7 +405,8 @@ public void deleteMedia(final SiteModel site, final MediaModel media) { AppLog.v(T.MEDIA, "Successful response from XMLRPC.DELETE_MEDIA"); notifyMediaDeleted(site, media, null); - }, error -> { + }, + error -> { String message = "Error response from XMLRPC.DELETE_MEDIA:" + error; AppLog.e(T.MEDIA, message); MediaErrorType mediaErrorType = MediaErrorType.fromBaseNetworkError(error); From b9c247b776a2cf60d09fe8b5f56504d93c462ddd Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:16:19 +0300 Subject: [PATCH 26/87] Analysis: Add missing n-a to fetch media on media clients FYI: 'n-a' stands for 'nullability annotations' --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 7 +++++-- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 7 +++++-- .../java/org/wordpress/android/fluxc/store/MediaStore.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 23032cd2e1..3ab8215a9b 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -339,7 +339,7 @@ public void fetchMediaList( /** * Gets a list of media items whose media IDs match the provided list. */ - public void fetchMedia(final SiteModel site, final MediaModel media) { + public void fetchMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { if (media == null) { // caller may be expecting a notification MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); @@ -589,7 +589,10 @@ private void notifyMediaListFetched( mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } - private void notifyMediaFetched(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaFetched( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 6ae0e75958..999accb94b 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -309,7 +309,7 @@ public void fetchMediaList( })); } - public void fetchMedia(final SiteModel site, final MediaModel media) { + public void fetchMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { fetchMedia(site, media, false); } @@ -488,7 +488,10 @@ private void notifyMediaListFetched( mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaListAction(payload)); } - private void notifyMediaFetched(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaFetched( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index f64ac22374..a045b36dd5 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -840,7 +840,7 @@ private void performFetchMediaList(@NonNull FetchMediaListPayload payload) { } } - private void performFetchMedia(MediaPayload payload) { + private void performFetchMedia(@NonNull MediaPayload payload) { if (payload.site == null || payload.media == null) { // null or empty media list -or- list contains a null value notifyMediaError(MediaErrorType.NULL_MEDIA_ARG, MediaAction.FETCH_MEDIA, payload.media); From 2175a474e2925da2c23fbb7162a764bfe94f303e Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:19:21 +0300 Subject: [PATCH 27/87] Analysis: Add missing n-a to delete media on media clients FYI: 'n-a' stands for 'nullability annotations' --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 7 +++++-- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 3ab8215a9b..c5fa81b3f4 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -376,7 +376,7 @@ public void fetchMedia(@NonNull final SiteModel site, @Nullable final MediaModel /** * Deletes media from a WP.com site whose media ID is in the provided list. */ - public void deleteMedia(final SiteModel site, final MediaModel media) { + public void deleteMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { if (media == null) { // caller may be expecting a notification MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); @@ -597,7 +597,10 @@ private void notifyMediaFetched( mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaAction(payload)); } - private void notifyMediaDeleted(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaDeleted( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newDeletedMediaAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 999accb94b..90c209a7fc 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -381,7 +381,7 @@ private void fetchMedia( })); } - public void deleteMedia(final SiteModel site, final MediaModel media) { + public void deleteMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { if (media == null) { // caller may be expecting a notification MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); @@ -496,7 +496,10 @@ private void notifyMediaFetched( mDispatcher.dispatch(MediaActionBuilder.newFetchedMediaAction(payload)); } - private void notifyMediaDeleted(SiteModel site, MediaModel media, MediaError error) { + private void notifyMediaDeleted( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error) { MediaPayload payload = new MediaPayload(site, media, error); mDispatcher.dispatch(MediaActionBuilder.newDeletedMediaAction(payload)); } From 03a3cbeb30ea78c0d97cd6565ce99daef2be6138 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:23:58 +0300 Subject: [PATCH 28/87] Analysis: Add missing n-a to cancel upload on media clients FYI: 'n-a' stands for 'nullability annotations' --- .../fluxc/network/rest/wpcom/media/MediaRestClient.java | 4 ++-- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index c5fa81b3f4..534fe5aa48 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -413,7 +413,7 @@ public void deleteMedia(@NonNull final SiteModel site, @Nullable final MediaMode })); } - public void cancelUpload(final MediaModel media) { + public void cancelUpload(@Nullable final MediaModel media) { if (media == null) { MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); error.logMessage = "Null media on cancel upload"; @@ -605,7 +605,7 @@ private void notifyMediaDeleted( mDispatcher.dispatch(MediaActionBuilder.newDeletedMediaAction(payload)); } - private void notifyMediaUploadCanceled(MediaModel media) { + private void notifyMediaUploadCanceled(@NonNull MediaModel media) { ProgressPayload payload = new ProgressPayload(media, 0.f, false, true); mDispatcher.dispatch(MediaActionBuilder.newCanceledMediaUploadAction(payload)); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 90c209a7fc..57185cbb39 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -416,7 +416,7 @@ public void deleteMedia(@NonNull final SiteModel site, @Nullable final MediaMode })); } - public void cancelUpload(final MediaModel media) { + public void cancelUpload(@Nullable final MediaModel media) { if (media == null) { MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); error.logMessage = "XMLRPC: empty media on cancel upload"; @@ -504,7 +504,7 @@ private void notifyMediaDeleted( mDispatcher.dispatch(MediaActionBuilder.newDeletedMediaAction(payload)); } - private void notifyMediaUploadCanceled(MediaModel media) { + private void notifyMediaUploadCanceled(@NonNull MediaModel media) { ProgressPayload payload = new ProgressPayload(media, 0.f, false, true); mDispatcher.dispatch(MediaActionBuilder.newCanceledMediaUploadAction(payload)); } From 605dad921760386f42a7d5b2758a3b3cada3338a Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 16:33:22 +0300 Subject: [PATCH 29/87] Analysis: Add missing n-a to get media list frm response on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../xmlrpc/media/MediaXMLRPCClient.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 57185cbb39..0986494927 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -50,7 +50,6 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -287,18 +286,9 @@ public void fetchMediaList( add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.GET_MEDIA_LIBRARY, params, response -> { List mediaList = getMediaListFromXmlrpcResponse(response, site.getId()); - if (mediaList != null) { - AppLog.v(T.MEDIA, "Fetched media list for site via XMLRPC.GET_MEDIA_LIBRARY"); - boolean canLoadMore = mediaList.size() == number; - notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); - } else { - String message = "could not parse XMLRPC.GET_MEDIA_LIBRARY response: " - + Arrays.toString(response); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "XMLRPC: " + message; - notifyMediaListFetched(site, error, mimeType); - } + AppLog.v(T.MEDIA, "Fetched media list for site via XMLRPC.GET_MEDIA_LIBRARY"); + boolean canLoadMore = mediaList.size() == number; + notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); }, error -> { String message = "XMLRPC.GET_MEDIA_LIBRARY error response:"; @@ -514,12 +504,9 @@ private void notifyMediaUploadCanceled(@NonNull MediaModel media) { // // media list responses should be of type Object[] with each media item in the array represented by a HashMap + @NonNull @SuppressWarnings("rawtypes") - private List getMediaListFromXmlrpcResponse(Object[] response, int localSiteId) { - if (response == null) { - return null; - } - + private List getMediaListFromXmlrpcResponse(@NonNull Object[] response, int localSiteId) { List responseMedia = new ArrayList<>(); for (Object mediaObject : response) { if (!(mediaObject instanceof HashMap)) { @@ -531,7 +518,6 @@ private List getMediaListFromXmlrpcResponse(Object[] response, int l responseMedia.add(media); } } - return responseMedia; } From 1b14ce10b26da30f69bc02ec95dbd3cfffe9579f Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:13:10 +0300 Subject: [PATCH 30/87] Analysis: Add missing n-a to get map frm upload response on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 0986494927..9ddd24ca71 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -618,8 +618,9 @@ private MediaError getMediaErrorFromXMLRPCException(XMLRPCException exception) { return mediaError; } + @Nullable @SuppressWarnings("rawtypes") - private static Map getMapFromUploadResponse(Response response) throws XMLRPCException { + private static Map getMapFromUploadResponse(@NonNull Response response) throws XMLRPCException { try { ResponseBody responseBody = response.body(); if (responseBody == null) { From 5a21c037aa15d68cb72d1d377808a9820f7fb289 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:15:12 +0300 Subject: [PATCH 31/87] Analysis: Add missing n-a to deprecated upload response on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 9ddd24ca71..a3db9d52fe 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -641,7 +641,7 @@ private static Map getMapFromUploadResponse(@NonNull Response response) throws X } @SuppressWarnings("rawtypes") - private static boolean isDeprecatedUploadResponse(Map responseMap) { + private static boolean isDeprecatedUploadResponse(@NonNull Map responseMap) { for (String requiredResponseField : REQUIRED_UPLOAD_RESPONSE_FIELDS) { if (!responseMap.containsKey(requiredResponseField)) { return true; From a8480342d0493d2ae9a0d09318d34081e83b1b28 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:20:56 +0300 Subject: [PATCH 32/87] Analysis: Add missing n-a to media from xmlrpc response on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../xmlrpc/media/MediaXMLRPCClient.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index a3db9d52fe..99d9f913bb 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -216,13 +216,21 @@ public void onResponse(@NonNull Call call, @NonNull Response response) { fetchMedia(site, media, true); } else { MediaModel responseMedia = getMediaFromXmlrpcResponse(responseMap); - // Retain local IDs - responseMedia.setId(media.getId()); - responseMedia.setLocalSiteId(site.getId()); - responseMedia.setLocalPostId(media.getLocalPostId()); - responseMedia.setMarkedLocallyAsFeatured(media.getMarkedLocallyAsFeatured()); - - notifyMediaUploaded(responseMedia, null); + if (responseMedia != null) { + // Retain local IDs + responseMedia.setId(media.getId()); + responseMedia.setLocalSiteId(site.getId()); + responseMedia.setLocalPostId(media.getLocalPostId()); + responseMedia.setMarkedLocallyAsFeatured(media.getMarkedLocallyAsFeatured()); + + notifyMediaUploaded(responseMedia, null); + } else { + String message = "could not parse Upload media response, ID: " + media.getMediaId(); + AppLog.w(T.MEDIA, message); + MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); + error.logMessage = "XMLRPC: " + message; + notifyMediaUploaded(media, error); + } } } else { String message = "error uploading media - malformed response: " + response.message(); @@ -521,9 +529,10 @@ private List getMediaListFromXmlrpcResponse(@NonNull Object[] respon return responseMedia; } + @Nullable @SuppressWarnings("rawtypes") - private MediaModel getMediaFromXmlrpcResponse(Map response) { - if (response == null || response.isEmpty()) { + private MediaModel getMediaFromXmlrpcResponse(@NonNull Map response) { + if (response.isEmpty()) { return null; } From 79bd324af358bec2afaa44a15302dbfd12d0a294 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:22:39 +0300 Subject: [PATCH 33/87] Analysis: Add missing n-a to get basic params on media xmlrpc client FYI: 'n-a' stands for 'nullability annotations' --- .../network/xmlrpc/media/MediaXMLRPCClient.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 99d9f913bb..3e8ef2a1bd 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -692,15 +692,13 @@ private boolean is404Response(BaseNetworkError error) { } @NonNull - private List getBasicParams(final SiteModel site, final MediaModel media) { + private List getBasicParams(@NonNull final SiteModel site, @Nullable final MediaModel media) { List params = new ArrayList<>(); - if (site != null) { - params.add(site.getSelfHostedSiteId()); - params.add(site.getUsername()); - params.add(site.getPassword()); - if (media != null) { - params.add(media.getMediaId()); - } + params.add(site.getSelfHostedSiteId()); + params.add(site.getUsername()); + params.add(site.getPassword()); + if (media != null) { + params.add(media.getMediaId()); } return params; } From 3f3b66492786e421ab6b87c6716ea66a3a3d752f Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:24:32 +0300 Subject: [PATCH 34/87] Analysis: Add missing n-a to is 404 response on media xmlrpc client FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 3e8ef2a1bd..675fac456a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -671,7 +671,7 @@ private Map getEditMediaFields(@Nullable final MediaModel media) return mediaFields; } - private boolean is404Response(BaseNetworkError error) { + private boolean is404Response(@NonNull BaseNetworkError error) { if (error.isGeneric() && error.type == BaseRequest.GenericErrorType.NOT_FOUND) { return true; } From e7500da6e4eafbe529e855af8951ff589bcd7c6c Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:25:37 +0300 Subject: [PATCH 35/87] Analysis: Add missing n-a to media error from exception on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 675fac456a..6688e208cc 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -604,7 +604,8 @@ private String getFileForSize(Map metadataMap, String size) { return null; } - private MediaError getMediaErrorFromXMLRPCException(XMLRPCException exception) { + @NonNull + private MediaError getMediaErrorFromXMLRPCException(@NonNull XMLRPCException exception) { MediaError mediaError = new MediaError(MediaErrorType.GENERIC_ERROR); mediaError.message = exception.getLocalizedMessage(); mediaError.logMessage = exception.getMessage(); From c00fa5ca98c77a6d2cc8ebfe97e691a398a76e32 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:29:21 +0300 Subject: [PATCH 36/87] Analysis: Add missing n-a to get file (url) for size on media xmlrpc FYI: 'n-a' stands for 'nullability annotations' --- .../network/xmlrpc/media/MediaXMLRPCClient.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 6688e208cc..559c7b9a99 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -567,9 +567,13 @@ private MediaModel getMediaFromXmlrpcResponse(@NonNull Map response) { return media; } + @Nullable @SuppressWarnings("rawtypes") - private String getFileUrlForSize(String mediaUrl, Map metadataMap, String size) { - if (metadataMap == null || TextUtils.isEmpty(mediaUrl) || !mediaUrl.contains("/")) { + private String getFileUrlForSize( + @NonNull String mediaUrl, + @NonNull Map metadataMap, + @NonNull String size) { + if (TextUtils.isEmpty(mediaUrl) || !mediaUrl.contains("/")) { return null; } @@ -587,11 +591,11 @@ private String getFileUrlForSize(String mediaUrl, Map metadataMap, String size) return baseURL + fileName; } + @Nullable @SuppressWarnings("rawtypes") - private String getFileForSize(Map metadataMap, String size) { - if (metadataMap == null) { - return null; - } + private String getFileForSize( + @NonNull Map metadataMap, + @NonNull String size) { Object sizesObject = metadataMap.get("sizes"); if (sizesObject instanceof Map) { Map sizesMap = (Map) sizesObject; From 2a6e10e0eceabc680557768ace3f7057acf29767 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 17:40:56 +0300 Subject: [PATCH 37/87] Analysis: Guard usages of media title on media xmlrpc client --- .../fluxc/network/xmlrpc/media/MediaXMLRPCClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 559c7b9a99..169c7650ba 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -97,6 +97,14 @@ public void onProgress(@NonNull MediaModel media, float progress) { } public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel media) { + if (media == null) { + // caller may be expecting a notification + MediaError error = new MediaError(MediaErrorType.NULL_MEDIA_ARG); + error.logMessage = "Pushed media is null"; + notifyMediaPushed(site, null, error); + return; + } + List params = getBasicParams(site, media); params.add(getEditMediaFields(media)); add(new XMLRPCRequest(site.getXmlRpcUrl(), XMLRPC.EDIT_POST, params, From 315a7ccb92d3d3d41ed875960677a274ae239a0a Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 18:11:15 +0300 Subject: [PATCH 38/87] Analysis: Create missing switch cases for media store errors Warning: "'switch' statement on enum type 'org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType' misses cases: 'NO_CONNECTION', 'NETWORK_ERROR', 'CENSORED', 'INVALID_SSL_CERTIFICATE', 'HTTP_AUTH_ERROR', 'INVALID_RESPONSE' and 'UNKNOWN'" --- .../java/org/wordpress/android/fluxc/store/MediaStore.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index a045b36dd5..883ed8198d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -416,6 +416,13 @@ public static MediaErrorType fromBaseNetworkError(BaseNetworkError baseError) { return MediaErrorType.SERVER_ERROR; case TIMEOUT: return MediaErrorType.TIMEOUT; + case NO_CONNECTION: + case NETWORK_ERROR: + case CENSORED: + case INVALID_SSL_CERTIFICATE: + case HTTP_AUTH_ERROR: + case INVALID_RESPONSE: + case UNKNOWN: default: return MediaErrorType.GENERIC_ERROR; } From 1679912dc538be0ba8fcc381560986bd5ee6ed53 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:05:45 +0300 Subject: [PATCH 39/87] Analysis: Remove unnecessary is split msg null checks on media store Warning: "Condition 'null != splitMsg' is always 'true'" --- .../main/java/org/wordpress/android/fluxc/store/MediaStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 883ed8198d..2cc498a16a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -274,7 +274,7 @@ public String getApiUserMessageIfAvailable() { if (type == MediaErrorType.BAD_REQUEST) { String[] splitMsg = message.split("\\|", 2); - if (null != splitMsg && splitMsg.length > 1) { + if (splitMsg.length > 1) { String userMessage = splitMsg[1]; if (TextUtils.isEmpty(userMessage)) { From 69ef729f2e575dbb82ce246aa181436ea9912b8e Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:07:27 +0300 Subject: [PATCH 40/87] Analysis: Replace explicit type argument with <> on on media changed Warning: "Explicit type argument MediaModel can be replaced with <>" --- .../java/org/wordpress/android/fluxc/store/MediaStore.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 2cc498a16a..4df61036a0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -309,13 +309,13 @@ public static class OnMediaChanged extends OnChanged { public MediaAction cause; public List mediaList; public OnMediaChanged(MediaAction cause) { - this(cause, new ArrayList(), null); + this(cause, new ArrayList<>(), null); } public OnMediaChanged(MediaAction cause, @NonNull List mediaList) { this(cause, mediaList, null); } public OnMediaChanged(MediaAction cause, MediaError error) { - this(cause, new ArrayList(), error); + this(cause, new ArrayList<>(), error); } public OnMediaChanged(MediaAction cause, @NonNull List mediaList, MediaError error) { this.cause = cause; From ed685c15109d8d402e9112f0d316e03c49c7cb02 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:08:14 +0300 Subject: [PATCH 41/87] Analysis: Suppress raw types warning on media store Warning: "Raw use of parameterized class 'Action'" --- .../main/java/org/wordpress/android/fluxc/store/MediaStore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 4df61036a0..3459a92d68 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -504,6 +504,7 @@ public static UploadStockMediaErrorType fromNetworkError(WPComGsonNetworkError w @Subscribe(threadMode = ThreadMode.ASYNC) @Override + @SuppressWarnings("rawtypes") public void onAction(Action action) { IAction actionType = action.getType(); if (!(actionType instanceof MediaAction)) { From 26ecb150b2e71b0bf7cafa96f1f63b38b2e103d8 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:10:19 +0300 Subject: [PATCH 42/87] Analysis: Use inserted media on instantiate media model store method Warning: "Variable is already assigned to this value" --- .../org/wordpress/android/fluxc/store/MediaStore.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 3459a92d68..25b6555f96 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -578,13 +578,13 @@ public void onRegister() { public MediaModel instantiateMediaModel() { MediaModel media = new MediaModel(); - media = MediaSqlUtils.insertMediaForResult(media); + MediaModel insertedMedia = MediaSqlUtils.insertMediaForResult(media); - if (media.getId() == -1) { - media = null; + if (insertedMedia.getId() == -1) { + return null; } - return media; + return insertedMedia; } public List getAllSiteMedia(SiteModel siteModel) { From 590c55d860870657918c5d73fd507cda2ca3f9b4 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:14:04 +0300 Subject: [PATCH 43/87] Analysis: Suppress unused warning on media related payload constructor All, some or none of those suppressed on 'unused' media related payload constructors, although seemingly unused, because they are 'public', client apps like JP/WPAndroid can actually be using those. Thus, they shouldn't be removed as 'unused'. Instead, and in order to avoid having them removed, this 'unused' warning is being suppressed instead. --- .../main/java/org/wordpress/android/fluxc/store/MediaStore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 25b6555f96..0c55fe3027 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -96,6 +96,7 @@ public static class FetchMediaListPayload extends Payload { public MimeType.Type mimeType; public int number = DEFAULT_NUM_MEDIA_PER_FETCH; + @SuppressWarnings("unused") public FetchMediaListPayload(SiteModel site) { this.site = site; } From 3501ffbde52952fc025bd12ca9f75aaba6a6e740 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:14:29 +0300 Subject: [PATCH 44/87] Analysis: Suppress unused warnings on get related media methods All, some or none of those suppressed on 'unused' get related media store methods, although seemingly unused, because they are 'public', client apps like JP/WPAndroid can actually be using those. Thus, they shouldn't be removed as 'unused'. Instead, and in order to avoid having them removed, this 'unused' warning is being suppressed instead. --- .../java/org/wordpress/android/fluxc/store/MediaStore.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 0c55fe3027..f660c2b67d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -626,14 +626,17 @@ public List getSiteImages(SiteModel siteModel) { return MediaSqlUtils.getSiteImages(siteModel); } + @SuppressWarnings("unused") public List getSiteVideos(SiteModel siteModel) { return MediaSqlUtils.getSiteVideos(siteModel); } + @SuppressWarnings("unused") public List getSiteAudio(SiteModel siteModel) { return MediaSqlUtils.getSiteAudio(siteModel); } + @SuppressWarnings("unused") public List getSiteDocuments(SiteModel siteModel) { return MediaSqlUtils.getSiteDocuments(siteModel); } @@ -703,6 +706,7 @@ public List getMediaForPost(PostImmutableModel postModel) { return MediaSqlUtils.matchPostMedia(postModel.getId()); } + @SuppressWarnings("unused") public List getMediaForPostWithState(PostImmutableModel postModel, MediaUploadState expectedState) { return MediaSqlUtils.matchPostMedia(postModel.getId(), MediaModelTable.UPLOAD_STATE, expectedState); From 0bfd72c69854685570b34f43cea00de87ac0acc8 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:18:41 +0300 Subject: [PATCH 45/87] Analysis: Suppress same parameter value warning on media store Warning: "Actual value of parameter 'errorType' is always 'MediaErrorType.MALFORMED_MEDIA_ARG' " ------------------------------------------------------------------------ 'notifyMediaUploadError(MediaErrorType.MALFORMED_MEDIA_ARG, ...)' is currently used once and no other usage of this private method is recorder, but this doesn't mean it will not be used in the future, or wasn't used in the past. As such, keeping this method signature and suppressing this warning for the time being seems to be the better approach here. --- .../main/java/org/wordpress/android/fluxc/store/MediaStore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index f660c2b67d..823efb7315 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -783,6 +783,7 @@ private void performPushMedia(@NonNull MediaPayload payload) { } } + @SuppressWarnings("SameParameterValue") private void notifyMediaUploadError(MediaErrorType errorType, String errorMessage, MediaModel media, String logMessage, MalformedMediaArgSubType argErrorType) { OnMediaUploaded onMediaUploaded = new OnMediaUploaded(media, 1, false, false); From 339e9091f202c1172e952f5ac1339e8d4327e50c Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Wed, 18 Oct 2023 18:07:39 +0300 Subject: [PATCH 46/87] Analysis: Add missing n-a to media payload on media store FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/store/MediaStore.java | 40 ++++++++++--------- .../android/fluxc/store/UploadStore.java | 7 +++- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 823efb7315..c6f9b7729d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -58,12 +58,14 @@ public class MediaStore extends Store { * Actions: FETCH(ED)_MEDIA, PUSH(ED)_MEDIA, UPLOADED_MEDIA, DELETE(D)_MEDIA, UPDATE_MEDIA, and REMOVE_MEDIA */ public static class MediaPayload extends Payload { - public SiteModel site; - public MediaModel media; - public MediaPayload(SiteModel site, MediaModel media) { + @NonNull public SiteModel site; + @Nullable public MediaModel media; + + public MediaPayload(@NonNull SiteModel site, @NonNull MediaModel media) { this(site, media, null); } - public MediaPayload(SiteModel site, MediaModel media, MediaError error) { + + public MediaPayload(@NonNull SiteModel site, @Nullable MediaModel media, @Nullable MediaError error) { this.site = site; this.media = media; this.error = error; @@ -794,6 +796,12 @@ private void notifyMediaUploadError(MediaErrorType errorType, String errorMessag } private void performUploadMedia(@NonNull UploadMediaPayload payload) { + if (payload.media == null) { + // null or empty media list -or- list contains a null value + notifyMediaError(MediaErrorType.NULL_MEDIA_ARG, MediaAction.UPLOAD_MEDIA, null); + return; + } + MalformedMediaArgSubType argError = MediaUtils.getMediaValidationErrorType(payload.media); if (argError.getType() != Type.NO_ERROR) { @@ -855,9 +863,9 @@ private void performFetchMediaList(@NonNull FetchMediaListPayload payload) { } private void performFetchMedia(@NonNull MediaPayload payload) { - if (payload.site == null || payload.media == null) { + if (payload.media == null) { // null or empty media list -or- list contains a null value - notifyMediaError(MediaErrorType.NULL_MEDIA_ARG, MediaAction.FETCH_MEDIA, payload.media); + notifyMediaError(MediaErrorType.NULL_MEDIA_ARG, MediaAction.FETCH_MEDIA, null); return; } @@ -1005,21 +1013,15 @@ private void handleMediaDeleted(@NonNull MediaPayload payload) { emitChange(onMediaChanged); } - private void notifyMediaError(MediaErrorType errorType, String errorMessage, MediaAction cause, - List media) { - OnMediaChanged mediaChange = new OnMediaChanged(cause, media); - mediaChange.error = new MediaError(errorType, errorMessage); - emitChange(mediaChange); - } - - private void notifyMediaError(MediaErrorType errorType, MediaAction cause, MediaModel media) { - notifyMediaError(errorType, null, cause, media); - } - - private void notifyMediaError(MediaErrorType errorType, String errorMessage, MediaAction cause, MediaModel media) { + private void notifyMediaError( + @NonNull MediaErrorType errorType, + @NonNull MediaAction cause, + @Nullable MediaModel media) { List mediaList = new ArrayList<>(); mediaList.add(media); - notifyMediaError(errorType, errorMessage, cause, mediaList); + OnMediaChanged mediaChange = new OnMediaChanged(cause, mediaList); + mediaChange.error = new MediaError(errorType, null); + emitChange(mediaChange); } private void performUploadStockMedia(UploadStockMediaPayload payload) { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java index c9f019e6bb..95350623df 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java @@ -131,7 +131,7 @@ private void onUploadAction(UploadAction actionType, Object payload) { } @SuppressWarnings("EnumSwitchStatementWhichMissesCases") - private void onMediaAction(MediaAction actionType, Object payload) { + private void onMediaAction(MediaAction actionType, @NonNull Object payload) { switch (actionType) { case UPLOAD_MEDIA: handleUploadMedia((MediaPayload) payload); @@ -267,7 +267,10 @@ public float getUploadProgressForMedia(MediaModel mediaModel) { return 0; } - private void handleUploadMedia(MediaPayload payload) { + private void handleUploadMedia(@NonNull MediaPayload payload) { + if (payload.media == null) { + return; + } MediaUploadModel mediaUploadModel = new MediaUploadModel(payload.media.getId()); MalformedMediaArgSubType argError = MediaUtils.getMediaValidationErrorType(payload.media); From 48d95acf120ebc6b2b93cbf73eb75cbed5381209 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:27:00 +0300 Subject: [PATCH 47/87] Analysis: Add missing n-a to upload mediaPayload on media store FYI: 'n-a' stands for 'nullability annotations' --- .../org/wordpress/android/fluxc/store/MediaStore.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index c6f9b7729d..238369f2e0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -78,12 +78,19 @@ public MediaPayload(@NonNull SiteModel site, @Nullable MediaModel media, @Nullab public static class UploadMediaPayload extends MediaPayload { public final boolean stripLocation; - public UploadMediaPayload(SiteModel site, MediaModel media, boolean stripLocation) { + public UploadMediaPayload( + @NonNull SiteModel site, + @Nullable MediaModel media, + boolean stripLocation) { super(site, media, null); this.stripLocation = stripLocation; } - public UploadMediaPayload(SiteModel site, MediaModel media, MediaError error, boolean stripLocation) { + public UploadMediaPayload( + @NonNull SiteModel site, + @Nullable MediaModel media, + @Nullable MediaError error, + boolean stripLocation) { super(site, media, error); this.stripLocation = stripLocation; } From 0adabd367c01a25d0e96500613e86fa4d2850ba7 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:47:59 +0300 Subject: [PATCH 48/87] Analysis: Add missing n-a to fetch media list payload on media store FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/store/MediaStore.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 238369f2e0..7cf164ffcd 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -100,23 +100,30 @@ public UploadMediaPayload( * Actions: FETCH_MEDIA_LIST */ public static class FetchMediaListPayload extends Payload { - public SiteModel site; + @NonNull public SiteModel site; public boolean loadMore; - public MimeType.Type mimeType; + @Nullable public MimeType.Type mimeType; public int number = DEFAULT_NUM_MEDIA_PER_FETCH; @SuppressWarnings("unused") - public FetchMediaListPayload(SiteModel site) { + public FetchMediaListPayload(@NonNull SiteModel site) { this.site = site; } - public FetchMediaListPayload(SiteModel site, int number, boolean loadMore) { + public FetchMediaListPayload( + @NonNull SiteModel site, + int number, + boolean loadMore) { this.site = site; this.loadMore = loadMore; this.number = number; } - public FetchMediaListPayload(SiteModel site, int number, boolean loadMore, MimeType.Type mimeType) { + public FetchMediaListPayload( + @NonNull SiteModel site, + int number, + boolean loadMore, + @NonNull MimeType.Type mimeType) { this.site = site; this.loadMore = loadMore; this.mimeType = mimeType; From 208574228b1127857a64504d66f5d0fa0344a9b2 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 16:56:24 +0300 Subject: [PATCH 49/87] Analysis: Add missing n-a to fetch media list response pl on media store FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/store/MediaStore.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 7cf164ffcd..734545794c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -135,16 +135,18 @@ public FetchMediaListPayload( * Actions: FETCHED_MEDIA_LIST */ public static class FetchMediaListResponsePayload extends Payload { - public SiteModel site; - public List mediaList; + @NonNull public SiteModel site; + @NonNull public List mediaList; public boolean loadedMore; public boolean canLoadMore; - public MimeType.Type mimeType; - public FetchMediaListResponsePayload(SiteModel site, - @NonNull List mediaList, - boolean loadedMore, - boolean canLoadMore, - MimeType.Type mimeType) { + @Nullable public MimeType.Type mimeType; + + public FetchMediaListResponsePayload( + @NonNull SiteModel site, + @NonNull List mediaList, + boolean loadedMore, + boolean canLoadMore, + @Nullable MimeType.Type mimeType) { this.site = site; this.mediaList = mediaList; this.loadedMore = loadedMore; @@ -152,7 +154,10 @@ public FetchMediaListResponsePayload(SiteModel site, this.mimeType = mimeType; } - public FetchMediaListResponsePayload(SiteModel site, MediaError error, MimeType.Type mimeType) { + public FetchMediaListResponsePayload( + @NonNull SiteModel site, + @NonNull MediaError error, + @Nullable MimeType.Type mimeType) { this.mediaList = new ArrayList<>(); this.site = site; this.error = error; From 01894777992ee4ab51d071b8143f28417b28f5c1 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 19 Oct 2023 17:05:04 +0300 Subject: [PATCH 50/87] Analysis: Add missing n-a to progress payload on media store FYI: 'n-a' stands for 'nullability annotations' --- .../android/fluxc/store/MediaStore.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 734545794c..b054c3fc2d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -169,15 +169,25 @@ public FetchMediaListResponsePayload( * Actions: UPLOADED_MEDIA, CANCELED_MEDIA_UPLOAD */ public static class ProgressPayload extends Payload { - public MediaModel media; + @Nullable public MediaModel media; public float progress; public boolean completed; public boolean canceled; - public ProgressPayload(MediaModel media, float progress, boolean completed, boolean canceled) { + + public ProgressPayload( + @NonNull MediaModel media, + float progress, + boolean completed, + boolean canceled) { this(media, progress, completed, null); this.canceled = canceled; } - public ProgressPayload(MediaModel media, float progress, boolean completed, MediaError error) { + + public ProgressPayload( + @Nullable MediaModel media, + float progress, + boolean completed, + @Nullable MediaError error) { this.media = media; this.progress = progress; this.completed = completed; @@ -753,7 +763,7 @@ private void removeAllMedia() { // Action implementations // - void updateMedia(MediaModel media, boolean emit) { + void updateMedia(@Nullable MediaModel media, boolean emit) { OnMediaChanged event = new OnMediaChanged(MediaAction.UPDATE_MEDIA); if (media == null) { From 7d49bffe7eccb0a1d6fba18d04ee7c5b942f6a99 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:27:23 +0300 Subject: [PATCH 51/87] Analysis: Add missing n-a to cancel media payload on media store FYI: 'n-a' stands for 'nullability annotations' --- .../wordpress/android/fluxc/store/MediaStore.java | 12 ++++-------- .../wordpress/android/fluxc/store/UploadStore.java | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index b054c3fc2d..f57b2c1b69 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -199,15 +199,15 @@ public ProgressPayload( * Actions: CANCEL_MEDIA_UPLOAD */ public static class CancelMediaPayload extends Payload { - public SiteModel site; - public MediaModel media; + @NonNull public SiteModel site; + @NonNull public MediaModel media; public boolean delete; - public CancelMediaPayload(SiteModel site, MediaModel media) { + public CancelMediaPayload(@NonNull SiteModel site, @NonNull MediaModel media) { this(site, media, true); } - public CancelMediaPayload(SiteModel site, MediaModel media, boolean delete) { + public CancelMediaPayload(@NonNull SiteModel site, @NonNull MediaModel media, boolean delete) { this.site = site; this.media = media; this.delete = delete; @@ -919,10 +919,6 @@ private void performDeleteMedia(@NonNull MediaPayload payload) { } private void performCancelUpload(@NonNull CancelMediaPayload payload) { - if (payload.media == null) { - return; - } - MediaModel media = payload.media; if (payload.delete) { MediaSqlUtils.deleteMedia(media); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java index 95350623df..b362381670 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java @@ -329,10 +329,6 @@ private void handleMediaUploaded(@NonNull ProgressPayload payload) { } private void handleCancelMedia(@NonNull CancelMediaPayload payload) { - if (payload.media == null) { - return; - } - // If the cancel action has the delete flag, the corresponding MediaModel will be deleted once this action // reaches the MediaStore, along with the MediaUploadModel (because of the FOREIGN KEY association) // Otherwise, we should mark the MediaUploadModel as FAILED From da9a621efa50e50e2577231fc18301b8bbe5facf Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:41:38 +0300 Subject: [PATCH 52/87] Refactor: Reformat media store --- .../wordpress/android/fluxc/store/MediaStore.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index f57b2c1b69..6bc17dacff 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -257,9 +257,11 @@ public static class MediaError implements OnChangedError { public String message; public int statusCode; public String logMessage; + public MediaError(MediaErrorType type) { this.type = type; } + public MediaError(MediaErrorType type, String message) { this.type = type; this.message = message; @@ -331,6 +333,7 @@ public String getApiUserMessageIfAvailable() { public static class UploadStockMediaError implements OnChangedError { public UploadStockMediaErrorType type; public String message; + public UploadStockMediaError(UploadStockMediaErrorType type, String message) { this.type = type; this.message = message; @@ -340,15 +343,19 @@ public UploadStockMediaError(UploadStockMediaErrorType type, String message) { public static class OnMediaChanged extends OnChanged { public MediaAction cause; public List mediaList; + public OnMediaChanged(MediaAction cause) { this(cause, new ArrayList<>(), null); } + public OnMediaChanged(MediaAction cause, @NonNull List mediaList) { this(cause, mediaList, null); } + public OnMediaChanged(MediaAction cause, MediaError error) { this(cause, new ArrayList<>(), error); } + public OnMediaChanged(MediaAction cause, @NonNull List mediaList, MediaError error) { this.cause = cause; this.mediaList = mediaList; @@ -360,11 +367,13 @@ public static class OnMediaListFetched extends OnChanged { public SiteModel site; public boolean canLoadMore; public MimeType.Type mimeType; + public OnMediaListFetched(SiteModel site, boolean canLoadMore, MimeType.Type mimeType) { this.site = site; this.canLoadMore = canLoadMore; this.mimeType = mimeType; } + public OnMediaListFetched(SiteModel site, MediaError error, MimeType.Type mimeType) { this.site = site; this.error = error; @@ -377,6 +386,7 @@ public static class OnMediaUploaded extends OnChanged { public float progress; public boolean completed; public boolean canceled; + public OnMediaUploaded(MediaModel media, float progress, boolean completed, boolean canceled) { this.media = media; this.progress = progress; @@ -394,6 +404,7 @@ public OnStockMediaUploaded(@NonNull SiteModel site, @NonNull List m this.site = site; this.mediaList = mediaList; } + public OnStockMediaUploaded(@NonNull SiteModel site, @NonNull UploadStockMediaError error) { this.site = site; this.error = error; @@ -624,6 +635,7 @@ public List getAllSiteMedia(SiteModel siteModel) { } public static final List NOT_DELETED_STATES = new ArrayList<>(); + static { NOT_DELETED_STATES.add(MediaUploadState.DELETING.toString()); NOT_DELETED_STATES.add(MediaUploadState.FAILED.toString()); @@ -843,8 +855,7 @@ private void performUploadMedia(@NonNull UploadMediaPayload payload) { argError.getType().getErrorLogDescription(), payload.media, message, - argError - ); + argError); return; } From 9ddce58d1347b8534664338d0f8b583fa763e9bc Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:40:57 +0300 Subject: [PATCH 53/87] Test: Suppress kotlin internal in java on media store test Warning: "Usage of Kotlin internal declaration from different module" --- .../org/wordpress/android/fluxc/media/MediaStoreTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java index 210ec4d0ef..99fac1d7ee 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java @@ -16,7 +16,6 @@ import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState; import org.wordpress.android.fluxc.model.PostModel; import org.wordpress.android.fluxc.model.SiteModel; -import org.wordpress.android.fluxc.network.rest.wpapi.applicationpasswords.ApplicationPasswordsConfiguration; import org.wordpress.android.fluxc.network.rest.wpapi.media.ApplicationPasswordsMediaRestClient; import org.wordpress.android.fluxc.network.rest.wpcom.media.MediaRestClient; import org.wordpress.android.fluxc.network.rest.wpcom.media.wpv2.WPComV2MediaRestClient; @@ -43,12 +42,15 @@ @RunWith(RobolectricTestRunner.class) public class MediaStoreTest { + @SuppressWarnings("KotlinInternalInJava") private MediaStore mMediaStore = new MediaStore(new Dispatcher(), Mockito.mock(MediaRestClient.class), Mockito.mock(MediaXMLRPCClient.class), Mockito.mock(WPComV2MediaRestClient.class), Mockito.mock(ApplicationPasswordsMediaRestClient.class), - Mockito.mock(ApplicationPasswordsConfiguration.class)); + Mockito.mock(org.wordpress.android.fluxc.network.rest.wpapi.applicationpasswords + .ApplicationPasswordsConfiguration.class) + ); @Before public void setUp() { From 88f415fc8397f526c81c1096458c307045dc71d8 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:43:01 +0300 Subject: [PATCH 54/87] Test: Add missing final to media store on media store test Warning: "Field 'mMediaStore' may be 'final'" --- .../java/org/wordpress/android/fluxc/media/MediaStoreTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java index 99fac1d7ee..deee5d3720 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java @@ -43,7 +43,7 @@ @RunWith(RobolectricTestRunner.class) public class MediaStoreTest { @SuppressWarnings("KotlinInternalInJava") - private MediaStore mMediaStore = new MediaStore(new Dispatcher(), + private final MediaStore mMediaStore = new MediaStore(new Dispatcher(), Mockito.mock(MediaRestClient.class), Mockito.mock(MediaXMLRPCClient.class), Mockito.mock(WPComV2MediaRestClient.class), From 572bf851658e15359882563cef39a1fd913ca745 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:44:48 +0300 Subject: [PATCH 55/87] Test: Resolve robolectric related application deprecation warnings Warning: "'application' is deprecated" Explanation: Accessing this field directly is inherently incompatible with 'org.robolectric.annotation.experimental.LazyApplication' and Robolectric makes no guarantees if a test modifies this field during execution. Replacing 'application' with 'getApplication()' resolves this deprecation warning. --- .../org/wordpress/android/fluxc/media/MediaSqlUtilsTest.java | 2 +- .../java/org/wordpress/android/fluxc/media/MediaStoreTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/media/MediaSqlUtilsTest.java b/example/src/test/java/org/wordpress/android/fluxc/media/MediaSqlUtilsTest.java index 2734032ac3..8696b94f41 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/media/MediaSqlUtilsTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/media/MediaSqlUtilsTest.java @@ -35,7 +35,7 @@ public class MediaSqlUtilsTest { @Before public void setUp() { - Context appContext = RuntimeEnvironment.application.getApplicationContext(); + Context appContext = RuntimeEnvironment.getApplication().getApplicationContext(); WellSqlConfig config = new SingleStoreWellSqlConfigForTests(appContext, MediaModel.class); WellSql.init(config); diff --git a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java index deee5d3720..0d167f9cff 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java @@ -54,7 +54,7 @@ public class MediaStoreTest { @Before public void setUp() { - Context context = RuntimeEnvironment.application.getApplicationContext(); + Context context = RuntimeEnvironment.getApplication().getApplicationContext(); WellSqlConfig config = new SingleStoreWellSqlConfigForTests(context, MediaModel.class); WellSql.init(config); config.reset(); From ad21ea5ef68e7e0a5ab4a1c357bd1b4e52b8577b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:48:10 +0300 Subject: [PATCH 56/87] Test: Simplify assert true assertions on media store test Warning: "'assertTrue()' can be simplified to 'assertEquals()'" --- .../android/fluxc/media/MediaStoreTest.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java index 0d167f9cff..33e4ded8d4 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/media/MediaStoreTest.java @@ -81,19 +81,19 @@ public void testGetAllMedia() { public void testMediaCount() { final int testSiteId = 2; SiteModel testSite = getTestSiteWithLocalId(testSiteId); - assertTrue(mMediaStore.getSiteMediaCount(testSite) == 0); + assertEquals(0, mMediaStore.getSiteMediaCount(testSite)); // count after insertion insertRandomMediaIntoDatabase(testSiteId, 5); - assertTrue(mMediaStore.getSiteMediaCount(testSite) == 5); + assertEquals(5, mMediaStore.getSiteMediaCount(testSite)); // count after inserting with different site ID final int wrongSiteId = testSiteId + 1; SiteModel wrongSite = getTestSiteWithLocalId(wrongSiteId); - assertTrue(mMediaStore.getSiteMediaCount(wrongSite) == 0); + assertEquals(0, mMediaStore.getSiteMediaCount(wrongSite)); insertRandomMediaIntoDatabase(wrongSiteId, 1); - assertTrue(mMediaStore.getSiteMediaCount(wrongSite) == 1); - assertTrue(mMediaStore.getSiteMediaCount(testSite) == 5); + assertEquals(1, mMediaStore.getSiteMediaCount(wrongSite)); + assertEquals(5, mMediaStore.getSiteMediaCount(testSite)); } @Test @@ -101,17 +101,17 @@ public void testHasSiteMediaWithId() { final int testSiteId = 24; final long testMediaId = 22; SiteModel testSite = getTestSiteWithLocalId(testSiteId); - assertTrue(mMediaStore.getSiteMediaCount(testSite) == 0); + assertEquals(0, mMediaStore.getSiteMediaCount(testSite)); assertFalse(mMediaStore.hasSiteMediaWithId(testSite, testMediaId)); // add test media MediaModel testMedia = getBasicMedia(); testMedia.setLocalSiteId(testSiteId); testMedia.setMediaId(testMediaId); - assertTrue(insertMediaIntoDatabase(testMedia) == 1); + assertEquals(1, insertMediaIntoDatabase(testMedia)); // verify store has inserted media - assertTrue(mMediaStore.getSiteMediaCount(testSite) == 1); + assertEquals(1, mMediaStore.getSiteMediaCount(testSite)); assertTrue(mMediaStore.hasSiteMediaWithId(testSite, testMediaId)); } @@ -126,7 +126,7 @@ public void testGetSpecificSiteMedia() { MediaModel testMedia = getBasicMedia(); testMedia.setLocalSiteId(testSiteId); testMedia.setMediaId(testMediaId); - assertTrue(insertMediaIntoDatabase(testMedia) == 1); + assertEquals(1, insertMediaIntoDatabase(testMedia)); // cannot get media with incorrect site ID final int wrongSiteId = testSiteId + 1; @@ -146,7 +146,7 @@ public void testGetListOfSiteMedia() { final int testSiteId = 55; SiteModel testSite = getTestSiteWithLocalId(testSiteId); List insertedMedia = insertRandomMediaIntoDatabase(testSiteId, testListSize); - assertTrue(mMediaStore.getSiteMediaCount(testSite) == testListSize); + assertEquals(testListSize, mMediaStore.getSiteMediaCount(testSite)); // create whitelist List whitelist = new ArrayList<>(testListSize / 2); @@ -156,7 +156,7 @@ public void testGetListOfSiteMedia() { final List storeMedia = mMediaStore.getSiteMediaWithIds(testSite, whitelist); assertNotNull(storeMedia); - assertTrue(storeMedia.size() == whitelist.size()); + assertEquals(storeMedia.size(), whitelist.size()); for (MediaModel media : storeMedia) { assertTrue(whitelist.contains(media.getMediaId())); } @@ -180,7 +180,7 @@ public void testGetSiteImages() { final List storeImages = mMediaStore.getSiteImages(getTestSiteWithLocalId(testSiteId)); assertNotNull(storeImages); - assertTrue(storeImages.size() == 1); + assertEquals(1, storeImages.size()); assertEquals(testImageId, storeImages.get(0).getMediaId()); assertTrue(MediaUtils.isImageMimeType(storeImages.get(0).getMimeType())); } @@ -189,7 +189,7 @@ public void testGetSiteImages() { public void testGetSiteImageCount() { final int testSiteId = 9001; SiteModel testSite = getTestSiteWithLocalId(testSiteId); - assertTrue(mMediaStore.getSiteImageCount(testSite) == 0); + assertEquals(0, mMediaStore.getSiteImageCount(testSite)); // insert both images and videos final int testListSize = 10; @@ -200,31 +200,31 @@ public void testGetSiteImageCount() { for (int i = 0; i < testListSize; ++i) { MediaModel testImage = generateMediaFromPath(testSiteId, i, String.format(testImagePath, i)); MediaModel testVideo = generateMediaFromPath(testSiteId, i + testListSize, String.format(testVideoPath, i)); - assertTrue(insertMediaIntoDatabase(testImage) == 1); - assertTrue(insertMediaIntoDatabase(testVideo) == 1); + assertEquals(1, insertMediaIntoDatabase(testImage)); + assertEquals(1, insertMediaIntoDatabase(testVideo)); testImages.add(testImage); testVideos.add(testVideo); } - assertTrue(mMediaStore.getSiteMediaCount(testSite) == testImages.size() + testVideos.size()); - assertTrue(mMediaStore.getSiteImageCount(testSite) == testImages.size()); + assertEquals(mMediaStore.getSiteMediaCount(testSite), testImages.size() + testVideos.size()); + assertEquals(mMediaStore.getSiteImageCount(testSite), testImages.size()); } @Test public void testGetSiteImagesBlacklist() { final int testSiteId = 3; SiteModel testSite = getTestSiteWithLocalId(testSiteId); - assertTrue(mMediaStore.getSiteImageCount(testSite) == 0); + assertEquals(0, mMediaStore.getSiteImageCount(testSite)); final int testListSize = 10; final List testImages = new ArrayList<>(testListSize); final String testImagePath = "/test/test_image%d.png"; for (int i = 0; i < testListSize; ++i) { MediaModel image = generateMediaFromPath(testSiteId, i, String.format(testImagePath, i)); - assertTrue(insertMediaIntoDatabase(image) == 1); + assertEquals(1, insertMediaIntoDatabase(image)); testImages.add(image); } - assertTrue(mMediaStore.getSiteImageCount(testSite) == testListSize); + assertEquals(testListSize, mMediaStore.getSiteImageCount(testSite)); // create blacklist List blacklist = new ArrayList<>(testListSize / 2); @@ -259,7 +259,7 @@ public void testGetUnattachedSiteMedia() { final List storeMedia = mMediaStore.getUnattachedSiteMedia(getTestSiteWithLocalId(testSiteId)); assertNotNull(storeMedia); - assertTrue(storeMedia.size() == unattachedMedia.size()); + assertEquals(storeMedia.size(), unattachedMedia.size()); for (int i = 0; i < storeMedia.size(); ++i) { assertTrue(storeMedia.contains(unattachedMedia.get(i))); } @@ -279,7 +279,7 @@ public void testGetUnattachedSiteMediaCount() { insertMediaIntoDatabase(attached); insertMediaIntoDatabase(unattached); } - assertTrue(mMediaStore.getUnattachedSiteMediaCount(getTestSiteWithLocalId(testSiteId)) == testPoolSize); + assertEquals(testPoolSize, mMediaStore.getUnattachedSiteMediaCount(getTestSiteWithLocalId(testSiteId))); } @Test @@ -333,7 +333,7 @@ public void testGetUrlForVideoWithVideoPressGuid() { final String testVideoPressGuid = "thisisonlyatest"; testVideo.setUrl(testUrl); testVideo.setVideoPressGuid(testVideoPressGuid); - assertTrue(insertMediaIntoDatabase(testVideo) == 1); + assertEquals(1, insertMediaIntoDatabase(testVideo)); // retrieve video and verify final String storeUrl = mMediaStore @@ -351,7 +351,7 @@ public void testGetThumbnailUrl() { final String testUrl = "http://notarealurl.testfluxc.org/not/a/real/resource/path.mp4"; testMedia.setThumbnailUrl(testUrl); testMedia.setMediaId(testMediaId); - assertTrue(insertMediaIntoDatabase(testMedia) == 1); + assertEquals(1, insertMediaIntoDatabase(testMedia)); // retrieve media and verify final String storeUrl = mMediaStore @@ -372,7 +372,7 @@ public void testSearchSiteMediaTitles() { MediaModel testMedia = generateMedia(baseString, null, null, null); testMedia.setLocalSiteId(testSiteId); testMedia.setMediaId(i); - assertTrue(insertMediaIntoDatabase(testMedia) == 1); + assertEquals(1, insertMediaIntoDatabase(testMedia)); baseString += String.valueOf(i); } @@ -380,7 +380,7 @@ public void testSearchSiteMediaTitles() { List storeMedia = mMediaStore .searchSiteMedia(getTestSiteWithLocalId(testSiteId), testTitles[i]); assertNotNull(storeMedia); - assertTrue(storeMedia.size() == testPoolSize - i); + assertEquals(storeMedia.size(), testPoolSize - i); } } @@ -420,7 +420,7 @@ public void testSearchSiteImages() { .searchSiteImages(getTestSiteWithLocalId(testSiteId), "test"); assertNotNull(storeImages); - assertTrue(storeImages.size() == 1); + assertEquals(1, storeImages.size()); assertEquals(testImageId, storeImages.get(0).getMediaId()); assertTrue(MediaUtils.isImageMimeType(storeImages.get(0).getMimeType())); assertEquals(testSiteId, storeImages.get(0).getLocalSiteId()); @@ -459,7 +459,7 @@ public void testSearchSiteVideos() { final List storeVideos = mMediaStore .searchSiteVideos(getTestSiteWithLocalId(testSiteId), "test"); assertNotNull(storeVideos); - assertTrue(storeVideos.size() == 1); + assertEquals(1, storeVideos.size()); assertEquals(testVideoId2, storeVideos.get(0).getMediaId()); assertTrue(MediaUtils.isVideoMimeType(storeVideos.get(0).getMimeType())); assertEquals(testSiteId, storeVideos.get(0).getLocalSiteId()); @@ -507,7 +507,7 @@ public void testSearchSiteAudio() { final List storeAudio = mMediaStore .searchSiteAudio(getTestSiteWithLocalId(testSiteId), "test"); assertNotNull(storeAudio); - assertTrue(storeAudio.size() == 2); + assertEquals(2, storeAudio.size()); assertEquals(testAudioId1, storeAudio.get(0).getMediaId()); assertEquals(testAudioId2, storeAudio.get(1).getMediaId()); @@ -571,7 +571,7 @@ public void testSearchSiteDocuments() { final List storeDocuments = mMediaStore .searchSiteDocuments(getTestSiteWithLocalId(testSiteId), "test"); assertNotNull(storeDocuments); - assertTrue(storeDocuments.size() == 2); + assertEquals(2, storeDocuments.size()); assertEquals(testDocumentId2, storeDocuments.get(0).getMediaId()); assertEquals(testDocumentId3, storeDocuments.get(1).getMediaId()); @@ -708,16 +708,16 @@ public void testHasSiteMediaToDelete() { public void testRemoveAllMedia() { SiteModel testSite1 = getTestSiteWithLocalId(1); insertRandomMediaIntoDatabase(testSite1.getId(), 5); - assertTrue(mMediaStore.getSiteMediaCount(testSite1) == 5); + assertEquals(5, mMediaStore.getSiteMediaCount(testSite1)); SiteModel testSite2 = getTestSiteWithLocalId(2); insertRandomMediaIntoDatabase(testSite2.getId(), 7); - assertTrue(mMediaStore.getSiteMediaCount(testSite2) == 7); + assertEquals(7, mMediaStore.getSiteMediaCount(testSite2)); MediaSqlUtils.deleteAllMedia(); - assertTrue(mMediaStore.getSiteMediaCount(testSite1) == 0); - assertTrue(mMediaStore.getSiteMediaCount(testSite2) == 0); + assertEquals(0, mMediaStore.getSiteMediaCount(testSite1)); + assertEquals(0, mMediaStore.getSiteMediaCount(testSite2)); } private MediaModel getBasicMedia() { From af02aff38ed7a4874270d29f76caf09222b64efd Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:50:32 +0300 Subject: [PATCH 57/87] Test: Suppress new class naming convention for connected tests Warnings: - "Test class name 'ReleaseStack_TaxonomyTestWPCom' doesn't match regex '[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*) IT(Case)?'" - "detekt - ClassNaming: Class and Object names should match the pattern: [A-Z][a-zA-Z0-9]*" --- .../org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt | 1 + .../android/fluxc/mocked/MockedStack_UploadStoreTest.java | 1 + .../wordpress/android/fluxc/mocked/MockedStack_UploadTest.java | 1 + .../android/fluxc/release/ReleaseStack_MediaTestJetpack.java | 1 + .../android/fluxc/release/ReleaseStack_MediaTestWPCom.java | 1 + .../android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java | 1 + 6 files changed, 6 insertions(+) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt index f8006023bd..0c4f32bd87 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit import javax.inject.Inject import kotlin.properties.Delegates.notNull +@Suppress("ClassNaming") @SuppressLint("UseSparseArrays") class MockedStack_MediaTest : MockedStack_Base() { @Inject lateinit var dispatcher: Dispatcher diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java index 464e94f83f..d1a7bd3961 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java @@ -31,6 +31,7 @@ * Tests the interactions between the MediaStore/PostStore and the UploadStore, without directly injecting the * UploadStore in the test class. */ +@SuppressWarnings("NewClassNamingConvention") public class MockedStack_UploadStoreTest extends MockedStack_Base { @Inject Dispatcher mDispatcher; @Inject MediaStore mMediaStore; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java index 503385340c..223f7f0a6e 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java @@ -50,6 +50,7 @@ /** * Tests using a Mocked Network app component. Test the Store itself and not the underlying network component(s). */ +@SuppressWarnings("NewClassNamingConvention") public class MockedStack_UploadTest extends MockedStack_Base { private static final String POST_DEFAULT_TITLE = "UploadTest base post"; private static final String POST_DEFAULT_DESCRIPTION = "Hi there, I'm a post from FluxC!"; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java index 0e0ed89db9..4172dfe102 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java @@ -33,6 +33,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@SuppressWarnings("NewClassNamingConvention") public class ReleaseStack_MediaTestJetpack extends ReleaseStack_Base { @Inject SiteStore mSiteStore; @Inject AccountStore mAccountStore; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java index e5bf6fa0c6..9f6058a827 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java @@ -40,6 +40,7 @@ import static org.junit.Assert.assertTrue; @SuppressLint("UseSparseArrays") +@SuppressWarnings("NewClassNamingConvention") public class ReleaseStack_MediaTestWPCom extends ReleaseStack_WPComBase { @Inject MediaStore mMediaStore; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java index 9da77d8956..b13d41e8da 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java @@ -39,6 +39,7 @@ import static org.junit.Assert.assertTrue; @SuppressLint("UseSparseArrays") +@SuppressWarnings("NewClassNamingConvention") public class ReleaseStack_MediaTestXMLRPC extends ReleaseStack_XMLRPCBase { @SuppressWarnings("unused") @Inject AccountStore mAccountStore; From 8f235d62f457b4e320a2804cdac7d67438223b8b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:52:21 +0300 Subject: [PATCH 58/87] Test: Suppress throws count for ms media test Warning: "detekt - ThrowsCount: Too many throw statements in the function onMediaUploaded. The maximum number of allowed throw statements is 2." --- .../org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt index 0c4f32bd87..a18481337c 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt @@ -206,7 +206,7 @@ class MockedStack_MediaTest : MockedStack_Base() { Assert.assertEquals(amountToCancel, mediaStore.getSiteMediaWithState(testSite, MediaUploadState.FAILED).size) } - @Suppress("unused") + @Suppress("unused", "ThrowsCount") @Subscribe fun onMediaUploaded(event: OnMediaUploaded) { if (event.isError) { From 7d2084e46cb0a727890f2cd3cc2f7192b590f7bf Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:54:40 +0300 Subject: [PATCH 59/87] Test: Simplify new media model helper func. on ms media test Warning: "Actual value of parameter 'mimeType' is always 'image/jpeg'" --- .../android/fluxc/mocked/MockedStack_MediaTest.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt index a18481337c..bc9a8e3287 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt @@ -67,7 +67,7 @@ class MockedStack_MediaTest : MockedStack_Base() { interceptor.respondWithSticky("media-upload-response-success.json") // First, try canceling an image with the default behavior (canceled image is deleted from the store) - newMediaModel("Test Title", sampleImagePath, "image/jpeg").let { testMedia -> + newMediaModel("Test Title", sampleImagePath).let { testMedia -> countDownLatch = CountDownLatch(1) nextEvent = TestEvents.CANCELED_MEDIA val payload = UploadMediaPayload(testSite, testMedia, true) @@ -83,7 +83,7 @@ class MockedStack_MediaTest : MockedStack_Base() { } // Now, try canceling with delete=false (canceled image should be marked as failed and kept in the store) - newMediaModel("Test Title", sampleImagePath, "image/jpeg").let { testMedia -> + newMediaModel("Test Title", sampleImagePath).let { testMedia -> countDownLatch = CountDownLatch(1) nextEvent = TestEvents.CANCELED_MEDIA val payload = UploadMediaPayload(testSite, testMedia, true) @@ -245,11 +245,11 @@ class MockedStack_MediaTest : MockedStack_Base() { } private fun addMediaModelToUploadArray(title: String) { - val mediaModel = newMediaModel(title, sampleImagePath, "image/jpeg") + val mediaModel = newMediaModel(title, sampleImagePath) uploadedMediaModels[mediaModel.id] = mediaModel } - private fun newMediaModel(testTitle: String, mediaPath: String, mimeType: String): MediaModel { + private fun newMediaModel(testTitle: String, mediaPath: String): MediaModel { val testDescription = "Test Description" val testCaption = "Test Caption" val testAlt = "Test Alt" @@ -257,7 +257,7 @@ class MockedStack_MediaTest : MockedStack_Base() { return mediaStore.instantiateMediaModel().apply { filePath = mediaPath fileExtension = mediaPath.substring(mediaPath.lastIndexOf(".") + 1) - this.mimeType = mimeType + this.mimeType = "image/jpeg" fileName = mediaPath.substring(mediaPath.lastIndexOf("/")) title = testTitle description = testDescription From 6a652a523ab4979dc3e13434fe4cdb97a1c223cd Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:57:16 +0300 Subject: [PATCH 60/87] Test: Guard usages of remote id queue poll on ms media test Warning: "Unsafe use of a nullable receiver of type Int?" --- .../org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt index bc9a8e3287..f061bd2e96 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt @@ -279,7 +279,7 @@ class MockedStack_MediaTest : MockedStack_Base() { // To imitate a real set of media upload requests as much as possible, each one should return a unique // remote media id. This also makes sure the MediaModel table doesn't treat these as duplicate entries and // deletes them, failing the test. - defaultId: String -> defaultId.replace("9999", remoteIdQueue.poll().toString()) + defaultId: String -> defaultId.replace("9999", remoteIdQueue.poll()?.toString() ?: "") } countDownLatch = CountDownLatch(mediaList.size) From e370b8456f63e9d366a84bc389b3205097b46774 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:58:08 +0300 Subject: [PATCH 61/87] Test: Fix typo with we're on ms media test Warning: "Typo: In word 'We'e'" --- .../org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt index f061bd2e96..ff7f618f02 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_MediaTest.kt @@ -293,7 +293,7 @@ class MockedStack_MediaTest : MockedStack_Base() { // Wait a bit and issue the cancel command TestUtils.waitFor(300) - // We'e only cancelling the first n=howManyFirstToCancel uploads + // We're only cancelling the first n=howManyFirstToCancel uploads for (i in 0 until howManyFirstToCancel) { val media = mediaList[i] val payload = CancelMediaPayload(testSite, media, delete) From 448539587552ce725341f2fac62032524256a8d9 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 15:59:52 +0300 Subject: [PATCH 62/87] Test: Simplify new media model helper function on ms upload test Warnings: - "Actual value of parameter 'mimeType' is always 'image/jpeg'" - "Actual value of parameter 'testTitle' is always 'Test Title'" --- .../fluxc/mocked/MockedStack_UploadTest.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java index 223f7f0a6e..2ea8243015 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java @@ -89,7 +89,7 @@ public void setUp() throws Exception { @Test public void testUploadMedia() throws InterruptedException { - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); startSuccessfulMediaUpload(testMedia, getTestSite()); assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); @@ -102,7 +102,7 @@ public void testUploadMedia() throws InterruptedException { @Test public void testUploadMediaError() throws InterruptedException { - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); startFailingMediaUpload(testMedia, getTestSite()); assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); @@ -121,7 +121,7 @@ public void testCancelImageUpload() throws InterruptedException { mInterceptor.respondWithSticky("media-upload-response-success.json", 1000L, null); // First, try canceling an image with the default behavior (canceled image is deleted from the store) - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); mCountDownLatch = new CountDownLatch(1); mNextEvent = TestEvents.CANCELED_MEDIA; UploadMediaPayload payload = new UploadMediaPayload(getTestSite(), testMedia, true); @@ -142,7 +142,7 @@ public void testCancelImageUpload() throws InterruptedException { assertNull(mediaUploadModel); // Now, try canceling with delete=false (canceled image should be marked as failed and kept in the store) - testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + testMedia = newMediaModel(getSampleImagePath()); mCountDownLatch = new CountDownLatch(1); mNextEvent = TestEvents.CANCELED_MEDIA; payload = new UploadMediaPayload(getTestSite(), testMedia, true); @@ -175,7 +175,7 @@ public void testRegisterPostAndUploadMediaWithError() throws InterruptedExceptio setupPostAttributes(); // Start uploading media - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); testMedia.setLocalPostId(mPost.getId()); startFailingMediaUpload(testMedia, site); @@ -272,7 +272,7 @@ public void testRegisterPostAndUploadMediaWithPostCancellation() throws Interrup setupPostAttributes(); // Start uploading media - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); testMedia.setLocalPostId(mPost.getId()); startSuccessfulMediaUpload(testMedia, site); @@ -342,7 +342,7 @@ public void testUploadMediaInCancelledPost() throws InterruptedException { setupPostAttributes(); // Start uploading media - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); testMedia.setLocalPostId(mPost.getId()); startFailingMediaUpload(testMedia, site); @@ -373,7 +373,7 @@ public void testUploadMediaInCancelledPost() throws InterruptedException { clearMedia(mPost, mUploadStore.getFailedMediaForPost(mPost)); // Upload a new media item to the cancelled post - testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + testMedia = newMediaModel(getSampleImagePath()); testMedia.setLocalPostId(mPost.getId()); startFailingMediaUpload(testMedia, site); @@ -399,7 +399,7 @@ public void testUpdateMediaModelState() throws InterruptedException { setupPostAttributes(); // Start uploading media - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); testMedia.setLocalPostId(mPost.getId()); startSuccessfulMediaUpload(testMedia, site); @@ -514,11 +514,7 @@ public void onUploadChanged(OnUploadChanged event) { } } - private MediaModel newMediaModel(String mediaPath, String mimeType) { - return newMediaModel("Test Title", mediaPath, mimeType); - } - - private MediaModel newMediaModel(String testTitle, String mediaPath, String mimeType) { + private MediaModel newMediaModel(String mediaPath) { final String testDescription = "Test Description"; final String testCaption = "Test Caption"; final String testAlt = "Test Alt"; @@ -526,9 +522,9 @@ private MediaModel newMediaModel(String testTitle, String mediaPath, String mime MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); - testMedia.setMimeType(mimeType); + testMedia.setMimeType("image/jpeg"); testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); - testMedia.setTitle(testTitle); + testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); testMedia.setAlt(testAlt); From e4c6d1fe88314060408f153912c2998b3e258e71 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:03:12 +0300 Subject: [PATCH 63/87] Test: Remove unnecessary media path length on ms upload test Warning: "Unnecessary string length argument" --- .../android/fluxc/mocked/MockedStack_UploadTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java index 2ea8243015..db65c8ad21 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java @@ -521,9 +521,9 @@ private MediaModel newMediaModel(String mediaPath) { MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); - testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); + testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1)); testMedia.setMimeType("image/jpeg"); - testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); + testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"))); testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); From 280025233ac999662f24f7cdcd86019cd3905a50 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:04:07 +0300 Subject: [PATCH 64/87] Test: Make create new post method void on ms upload test Warning: "Return value of the method is never used" --- .../wordpress/android/fluxc/mocked/MockedStack_UploadTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java index db65c8ad21..31916cfd69 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java @@ -532,9 +532,8 @@ private MediaModel newMediaModel(String mediaPath) { return testMedia; } - private PostModel createNewPost(SiteModel site) throws InterruptedException { + private void createNewPost(SiteModel site) throws InterruptedException { mPost = mPostStore.instantiatePostModel(site, false); - return mPost; } private void setupPostAttributes() { From 68151b6576dfd9625c48f3a68fade983fd236092 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:04:59 +0300 Subject: [PATCH 65/87] Test: Remove interrupted exception from throws list on ms upload test Warning: "Exception 'java.lang.InterruptedException' is never thrown in the method" --- .../wordpress/android/fluxc/mocked/MockedStack_UploadTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java index 31916cfd69..d918756d57 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadTest.java @@ -532,7 +532,7 @@ private MediaModel newMediaModel(String mediaPath) { return testMedia; } - private void createNewPost(SiteModel site) throws InterruptedException { + private void createNewPost(SiteModel site) { mPost = mPostStore.instantiatePostModel(site, false); } From 66b4d279cff9b1d7c5eec7726c3b9ef412a4405a Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:05:39 +0300 Subject: [PATCH 66/87] Test: Insert

    on ms upload store test Warning: "Blank line will be ignored" --- .../android/fluxc/mocked/MockedStack_UploadStoreTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java index d1a7bd3961..acf56a14f4 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java @@ -27,7 +27,7 @@ /** * Tests using a Mocked Network app component. Test the Store itself and not the underlying network component(s). - * + *

    * Tests the interactions between the MediaStore/PostStore and the UploadStore, without directly injecting the * UploadStore in the test class. */ From c9d440d9f368867ab20e3efbf948ee82d159208d Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:07:11 +0300 Subject: [PATCH 67/87] Test: Simplify new media model helper function on ms upload store test Warnings: - "Actual value of parameter 'mimeType' is always 'image/jpeg'" - "Actual value of parameter 'testTitle' is always 'Test Title'" --- .../fluxc/mocked/MockedStack_UploadStoreTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java index acf56a14f4..199641837d 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java @@ -59,7 +59,7 @@ public void setUp() throws Exception { @Test public void testUploadMedia() throws InterruptedException { - MediaModel testMedia = newMediaModel(getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(getSampleImagePath()); startSuccessfulMediaUpload(testMedia, getTestSite()); assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); @@ -90,11 +90,7 @@ public void onMediaUploaded(OnMediaUploaded event) { } } - private MediaModel newMediaModel(String mediaPath, String mimeType) { - return newMediaModel("Test Title", mediaPath, mimeType); - } - - private MediaModel newMediaModel(String testTitle, String mediaPath, String mimeType) { + private MediaModel newMediaModel(String mediaPath) { final String testDescription = "Test Description"; final String testCaption = "Test Caption"; final String testAlt = "Test Alt"; @@ -102,9 +98,9 @@ private MediaModel newMediaModel(String testTitle, String mediaPath, String mime MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); - testMedia.setMimeType(mimeType); + testMedia.setMimeType("image/jpeg"); testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); - testMedia.setTitle(testTitle); + testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); testMedia.setAlt(testAlt); From 034f80045cf871ea25287b169b531aed3888b389 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:07:35 +0300 Subject: [PATCH 68/87] Test: Remove unnecessary media path length on ms upload store test Warning: "Unnecessary string length argument" --- .../android/fluxc/mocked/MockedStack_UploadStoreTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java index 199641837d..b8092868b7 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_UploadStoreTest.java @@ -97,9 +97,9 @@ private MediaModel newMediaModel(String mediaPath) { MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); - testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); + testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1)); testMedia.setMimeType("image/jpeg"); - testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); + testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"))); testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); From e28b96050732232efaa1af1119d32eed53b3682b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:08:28 +0300 Subject: [PATCH 69/87] Test: Delete unused account store file on rs media test jetpack Warning: "Field 'mAccountStore' is never used" --- .../android/fluxc/release/ReleaseStack_MediaTestJetpack.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java index 4172dfe102..a0924eb15f 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java @@ -10,7 +10,6 @@ import org.wordpress.android.fluxc.generated.SiteActionBuilder; import org.wordpress.android.fluxc.model.MediaModel; import org.wordpress.android.fluxc.model.SiteModel; -import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.fluxc.store.AccountStore.AuthenticatePayload; import org.wordpress.android.fluxc.store.AccountStore.OnAccountChanged; import org.wordpress.android.fluxc.store.AccountStore.OnAuthenticationChanged; @@ -36,7 +35,6 @@ @SuppressWarnings("NewClassNamingConvention") public class ReleaseStack_MediaTestJetpack extends ReleaseStack_Base { @Inject SiteStore mSiteStore; - @Inject AccountStore mAccountStore; @Inject MediaStore mMediaStore; private enum TestEvents { From 61deec7a4f6c50ab574431a5398ecfeb9e26f6f2 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:11:03 +0300 Subject: [PATCH 70/87] Test: Simplify new media model helper function on rs media test jetpack Warning: "Actual value of parameter 'mimeType' is always 'image/jpeg'" --- .../fluxc/release/ReleaseStack_MediaTestJetpack.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java index a0924eb15f..7b6fda9388 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java @@ -71,7 +71,7 @@ public void testUploadMediaLowFilesizeLimit() throws InterruptedException { site = mSiteStore.getSites().get(0); // Attempt to upload an image that exceeds the site's maximum upload_max_filesize or post_max_size - MediaModel testMedia = newMediaModel(site, getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(site, getSampleImagePath()); mNextEvent = TestEvents.ERROR_EXCEEDS_FILESIZE_LIMIT; uploadMedia(site, testMedia); @@ -91,7 +91,7 @@ public void testUploadMediaLowMemoryLimit() throws InterruptedException { site.setMemoryLimit(1985); // Artificially set the site's memory limit, in bytes // Attempt to upload an image that exceeds the site's memory limit - MediaModel testMedia = newMediaModel(site, getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(site, getSampleImagePath()); mNextEvent = TestEvents.ERROR_EXCEEDS_MEMORY_LIMIT; uploadMedia(site, testMedia); @@ -115,7 +115,7 @@ public void testUploadMediaLowQuotaAvailableLimit() throws InterruptedException site.setSpaceUsed(50); // Attempt to upload an image that exceeds the site's memory limit - MediaModel testMedia = newMediaModel(site, getSampleImagePath(), "image/jpeg"); + MediaModel testMedia = newMediaModel(site, getSampleImagePath()); mNextEvent = TestEvents.ERROR_EXCEEDS_SITE_SPACE_QUOTA_LIMIT; uploadMedia(site, testMedia); @@ -147,7 +147,7 @@ public void onMediaUploaded(OnMediaUploaded event) { } } - private MediaModel newMediaModel(SiteModel site, String mediaPath, String mimeType) { + private MediaModel newMediaModel(SiteModel site, String mediaPath) { final String testTitle = "Test Title"; final String testDescription = "Test Description"; final String testCaption = "Test Caption"; @@ -156,7 +156,7 @@ private MediaModel newMediaModel(SiteModel site, String mediaPath, String mimeTy MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); - testMedia.setMimeType(mimeType); + testMedia.setMimeType("image/jpeg"); testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); testMedia.setTitle(testTitle); testMedia.setDescription(testDescription); From 3be1fc6bec78500365d0bdc114c414dd6b1488fb Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:11:30 +0300 Subject: [PATCH 71/87] Test: Remove unnecessary media path length on rs media test jetpack Warning: "Unnecessary string length argument" --- .../android/fluxc/release/ReleaseStack_MediaTestJetpack.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java index 7b6fda9388..9f01b39eda 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestJetpack.java @@ -155,9 +155,9 @@ private MediaModel newMediaModel(SiteModel site, String mediaPath) { MediaModel testMedia = mMediaStore.instantiateMediaModel(); testMedia.setFilePath(mediaPath); - testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1, mediaPath.length())); + testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1)); testMedia.setMimeType("image/jpeg"); - testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"), mediaPath.length())); + testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"))); testMedia.setTitle(testTitle); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); From 6c96bcac32b7f578435dbbf50a6c7cca2c5f0da7 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:12:36 +0300 Subject: [PATCH 72/87] Test: Simplify new media model helper function on rs media test wp com Warning: "Actual value of parameter 'testTitle' is always 'Test Title'" --- .../android/fluxc/release/ReleaseStack_MediaTestWPCom.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java index 9f6058a827..0022247180 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java @@ -381,10 +381,6 @@ private boolean eventHasKnownImages(OnMediaChanged event) { } private MediaModel newMediaModel(String mediaPath, String mimeType) { - return newMediaModel("Test Title", mediaPath, mimeType); - } - - private MediaModel newMediaModel(String testTitle, String mediaPath, String mimeType) { final String testDescription = "Test Description"; final String testCaption = "Test Caption"; final String testAlt = "Test Alt"; @@ -394,7 +390,7 @@ private MediaModel newMediaModel(String testTitle, String mediaPath, String mime testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1)); testMedia.setMimeType(mimeType); testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"))); - testMedia.setTitle(testTitle); + testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); testMedia.setAlt(testAlt); From d3c81462ff5cb97dcca100dc94c0705e160e71b2 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:13:34 +0300 Subject: [PATCH 73/87] Test: Simplify new media model helper function on rs media test xmlrpc Warning: "Actual value of parameter 'mimeType' is always 'image/jpeg'" --- .../android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java index b13d41e8da..dec57cc573 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestXMLRPC.java @@ -404,10 +404,6 @@ public void onMediaListFetched(OnMediaListFetched event) { } private MediaModel newMediaModel(String mediaPath, String mimeType) { - return newMediaModel("Test Title", mediaPath, mimeType); - } - - private MediaModel newMediaModel(String testTitle, String mediaPath, String mimeType) { final String testDescription = "Test Description"; final String testCaption = "Test Caption"; final String testAlt = "Test Alt"; @@ -417,7 +413,7 @@ private MediaModel newMediaModel(String testTitle, String mediaPath, String mime testMedia.setFileExtension(mediaPath.substring(mediaPath.lastIndexOf(".") + 1)); testMedia.setMimeType(mimeType); testMedia.setFileName(mediaPath.substring(mediaPath.lastIndexOf("/"))); - testMedia.setTitle(testTitle); + testMedia.setTitle("Test Title"); testMedia.setDescription(testDescription); testMedia.setCaption(testCaption); testMedia.setAlt(testAlt); From ec6e158c1050ecb73c9459232255ded5d8ea831b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:18:01 +0300 Subject: [PATCH 74/87] Docs: Improve documentation on rest upload request body Warnings: - "Blank line will be ignored" - "Link specified as plain text" --- .../network/rest/wpcom/media/RestUploadRequestBody.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java index 97e6d2f401..e38c57a3ed 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java @@ -20,10 +20,10 @@ /** * Wrapper for {@link MultipartBody} that reports upload progress as body data is written. - * + *

    * A {@link ProgressListener} is required, use {@link MultipartBody} if progress is not needed. - * - * ref http://stackoverflow.com/questions/35528751/okhttp-3-tracking-multipart-upload-progress + *

    + * @see doc */ public class RestUploadRequestBody extends BaseUploadRequestBody { private static final String MEDIA_DATA_KEY = "media[0]"; From 3db2be480483ab0fbcab0ce38147389b17db6bf5 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:20:16 +0300 Subject: [PATCH 75/87] Analysis: Guard usages of params get key on rest upload request body Warnings: "Method invocation 'toString' may produce 'NullPointerException'" --- .../network/rest/wpcom/media/RestUploadRequestBody.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java index e38c57a3ed..f797a93a82 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java @@ -76,7 +76,10 @@ private MultipartBody buildMultipartBody(@NonNull Map params) { // add media attributes for (String key : params.keySet()) { - builder.addFormDataPart(String.format(MEDIA_PARAM_FORMAT, key), params.get(key).toString()); + Object value = params.get(key); + if (value != null) { + builder.addFormDataPart(String.format(MEDIA_PARAM_FORMAT, key), value.toString()); + } } // add media file data From 17118eea95ded117fe8d01f5082c80b8877b1dd8 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:22:07 +0300 Subject: [PATCH 76/87] Analysis: Suppress request body create deprecation on rest upload rb Warnings: "'create(okhttp3.MediaType, java.io.File)' is deprecated" --- .../fluxc/network/rest/wpcom/media/RestUploadRequestBody.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java index f797a93a82..6355b4f1a1 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java @@ -70,6 +70,7 @@ public void writeTo(@NonNull BufferedSink sink) throws IOException { } @NonNull + @SuppressWarnings("deprecation") private MultipartBody buildMultipartBody(@NonNull Map params) { MediaModel media = getMedia(); MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); From 2f2875a976acd35a187632dafc2e163e07e8c2dd Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:25:10 +0300 Subject: [PATCH 77/87] Analysis: Suppress string escape utils deprecation on xmlrpc upload rb Warnings: "'org.apache.commons.lang3.StringEscapeUtils' is deprecated" --- .../fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java index e8b6cd527d..5ffa5aee5c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java @@ -44,6 +44,7 @@ public class XmlrpcUploadRequestBody extends BaseUploadRequestBody { private long mContentSize = -1; private long mMediaBytesWritten = 0; + @SuppressWarnings("deprecation") public XmlrpcUploadRequestBody( @NonNull MediaModel media, @NonNull ProgressListener listener, From 007716e339cc09481aa6eaa8e7cb6fa58824a8fd Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:30:31 +0300 Subject: [PATCH 78/87] Analysis: Replace fi stream with try with resource on xmlrpc upload rb Warnings: "'try' can use automatic resource management" --- .../fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java index 5ffa5aee5c..e36f52b4b7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java @@ -114,8 +114,7 @@ public void writeTo(@NonNull BufferedSink sink) throws IOException { // write file to xml - FileInputStream fis = new FileInputStream(getMedia().getFilePath()); - try { + try (FileInputStream fis = new FileInputStream(getMedia().getFilePath())) { byte[] buffer = new byte[3600]; // you must use a 24bit multiple int length; String chunk; @@ -124,8 +123,6 @@ public void writeTo(@NonNull BufferedSink sink) throws IOException { mMediaBytesWritten += length; bufferedSink.writeUtf8(chunk); } - } finally { - fis.close(); } // write remainder or XML From b54bd63949d2d05275889b47d1ca8a79ffccfabf Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:32:38 +0300 Subject: [PATCH 79/87] Docs: Improve documentation on base upload request body Warnings: - "Blank line will be ignored" - "Link specified as plain text" --- .../android/fluxc/network/BaseUploadRequestBody.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java index 539be09eaf..bc9fdf5717 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java @@ -19,10 +19,10 @@ /** * Wrapper for {@link okhttp3.MultipartBody} that reports upload progress as body data is written. - * + *

    * A {@link ProgressListener} is required, use {@link okhttp3.MultipartBody} if progress is not needed. - * - * ref http://stackoverflow.com/questions/35528751/okhttp-3-tracking-multipart-upload-progress + *

    + * @see doc */ public abstract class BaseUploadRequestBody extends RequestBody { /** From e145b90e20087ea3948582f8edb1ce380c86e7fa Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:33:43 +0300 Subject: [PATCH 80/87] Analysis: Add missing n-a to counting sink on base upload request body FYI: 'n-a' stands for 'nullability annotations' --- .../wordpress/android/fluxc/network/BaseUploadRequestBody.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java index bc9fdf5717..f0e1f49f7e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java @@ -97,7 +97,7 @@ protected final class CountingSink extends ForwardingSink { private long mBytesWritten = 0; private long mLastTimeOnProgressCalled = 0; - public CountingSink(Sink delegate) { + public CountingSink(@NonNull Sink delegate) { super(delegate); } From 1b6399da43bdc09c40343808de789fae81b5c4f4 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:39:09 +0300 Subject: [PATCH 81/87] Docs: Improve documentation on media wp com rest response Warnings: - "Blank line will be ignored" - "Link specified as plain text" --- .../network/rest/wpcom/media/MediaWPComRestResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index d659d023ae..9a08f937e6 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -6,8 +6,8 @@ /** * Response to GET request for media items - * - * https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/media/%24media_ID/ + *

    + * @see doc */ public class MediaWPComRestResponse implements Response { public static final String DELETED_STATUS = "deleted"; From 61b71b45ff038a137ab272465556e77ab074eda2 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 16:41:34 +0300 Subject: [PATCH 82/87] Analysis: Make inner classes static on media wp com rest response Warnings: - "Inner class 'MultipleMediaResponse' may be 'static'" - "Inner class 'Thumbnails' may be 'static'" --- .../network/rest/wpcom/media/MediaWPComRestResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index 9a08f937e6..9650c41f27 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -12,13 +12,13 @@ public class MediaWPComRestResponse implements Response { public static final String DELETED_STATUS = "deleted"; - public class MultipleMediaResponse { + public static class MultipleMediaResponse { public List media; public List errors; public int found; } - public class Thumbnails { + public static class Thumbnails { public String thumbnail; public String medium; public String large; From 8b8c7aeb495c5c98cea53f204c171eda07730058 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 17:17:38 +0300 Subject: [PATCH 83/87] Analysis: Delete unused thumbnails field on media wp com rest response --- .../fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java | 1 - 1 file changed, 1 deletion(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index 9650c41f27..009dee81fc 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -22,7 +22,6 @@ public static class Thumbnails { public String thumbnail; public String medium; public String large; - public String post_thumbnail; public String fmt_std; } From a12ad85713a34b75498b3380c603e39de9757211 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 18:06:02 +0300 Subject: [PATCH 84/87] Analysis: Add missing nl-a to s method parameter on media fragment FYI: 'nl-a' stands for 'nullable annotation'. --- .../org/wordpress/android/fluxc/example/MediaFragment.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java index 10c630dce9..367f7f4b69 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java @@ -18,6 +18,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import org.greenrobot.eventbus.Subscribe; @@ -266,8 +267,10 @@ public void onMediaUploaded(OnMediaUploaded event) { } } - private void prependToLog(final String s) { - ((MainExampleActivity) getActivity()).prependToLog(s); + private void prependToLog(@Nullable final String s) { + if (s != null) { + ((MainExampleActivity) getActivity()).prependToLog(s); + } } private void fetchMediaList(@NonNull SiteModel site) { From 971a8bc299dd46e5d279c260150af36caf627750 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 18:10:54 +0300 Subject: [PATCH 85/87] Analysis: Delete unused multiple fields on media wp com rest response --- .../fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index 009dee81fc..77268af7a7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -14,8 +14,6 @@ public class MediaWPComRestResponse implements Response { public static class MultipleMediaResponse { public List media; - public List errors; - public int found; } public static class Thumbnails { From e57e2277ce52e90a0543b264c5c704fdc3756c8e Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Fri, 20 Oct 2023 18:14:44 +0300 Subject: [PATCH 86/87] Analysis: Add missing nn-a to multi field on media wp com rest response FYI: 'nn-a' stands for 'non-null annotations'. PS: This 'NotNullFieldNotInitialized' warning got suppressed because a 'response' class can never have its fields initialized via a constructor initialization, or otherwise for that matter. ------------------------------------------------------------------------ Also, note that as part of this change, the 'response' that was previously considered '@Nullable' has been updated to '@NonNull' as it doesn't seem that a nullable response to be valid, or part of a specific valid flow. The fact that 'MediaWPRESTResponse.kt' and 'BaseWPV2MediaRestClient.kt' is also working with a '@NonNull' response give this change some extra confidence. --- .../rest/wpcom/media/MediaResponseUtils.kt | 9 +- .../rest/wpcom/media/MediaRestClient.java | 83 ++++++------------- .../wpcom/media/MediaWPComRestResponse.java | 5 +- .../wpcom/stockmedia/StockMediaRestClient.kt | 2 +- 4 files changed, 34 insertions(+), 65 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt index 7ad5bf84c8..d2f85ef0ef 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt @@ -13,15 +13,16 @@ class MediaResponseUtils /** * Creates a [MediaModel] list from a WP.com REST response to a request for all media. */ - fun getMediaListFromRestResponse(from: MultipleMediaResponse?, localSiteId: Int): List? { - return from?.media?.mapNotNull { getMediaFromRestResponse(it)?.apply { this.localSiteId = localSiteId } } + fun getMediaListFromRestResponse(from: MultipleMediaResponse, localSiteId: Int): List { + return from.media.mapNotNull { + getMediaFromRestResponse(it).apply { this.localSiteId = localSiteId } + } } /** * Creates a [MediaModel] from a WP.com REST response to a fetch request. */ - fun getMediaFromRestResponse(from: MediaWPComRestResponse?): MediaModel? { - if (from == null) return null + fun getMediaFromRestResponse(from: MediaWPComRestResponse): MediaModel { val media = MediaModel() media.mediaId = from.ID media.uploadDate = from.date diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 534fe5aa48..a5786fd7e7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -121,15 +121,9 @@ public void pushMedia(@NonNull final SiteModel site, @Nullable final MediaModel add(WPComGsonRequest.buildPostRequest(url, getEditRequestParams(media), MediaWPComRestResponse.class, response -> { MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (responseMedia != null) { - AppLog.v(T.MEDIA, "media changes pushed for " + responseMedia.getTitle()); - responseMedia.setLocalSiteId(site.getId()); - notifyMediaPushed(site, responseMedia, null); - } else { - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = "Parsed media is null"; - notifyMediaPushed(site, media, error); - } + AppLog.v(T.MEDIA, "media changes pushed for " + responseMedia.getTitle()); + responseMedia.setLocalSiteId(site.getId()); + notifyMediaPushed(site, responseMedia, null); }, error -> { String errorMessage = "error editing remote media: " + error; @@ -246,9 +240,10 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO reader.setLenient(true); MultipleMediaResponse mediaResponse = gson.fromJson(reader, MultipleMediaResponse.class); - List responseMedia = - mMediaResponseUtils.getMediaListFromRestResponse(mediaResponse, site.getId()); - if (responseMedia != null && !responseMedia.isEmpty()) { + List responseMedia = mMediaResponseUtils.getMediaListFromRestResponse( + mediaResponse, + site.getId()); + if (!responseMedia.isEmpty()) { MediaModel uploadedMedia = responseMedia.get(0); uploadedMedia.setId(media.getId()); uploadedMedia.setLocalPostId(media.getLocalPostId()); @@ -312,19 +307,12 @@ public void fetchMediaList( String url = WPCOMREST.sites.site(site.getSiteId()).media.getUrlV1_1(); add(WPComGsonRequest.buildGetRequest(url, params, MultipleMediaResponse.class, response -> { - List mediaList = - mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); - if (mediaList != null) { - AppLog.v(T.MEDIA, "Fetched media list for site with size: " + mediaList.size()); - boolean canLoadMore = mediaList.size() == number; - notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); - } else { - String errorMessage = "could not parse Fetch all media response: " + response; - AppLog.w(T.MEDIA, errorMessage); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = errorMessage; - notifyMediaListFetched(site, error, mimeType); - } + List mediaList = mMediaResponseUtils.getMediaListFromRestResponse( + response, + site.getId()); + AppLog.v(T.MEDIA, "Fetched media list for site with size: " + mediaList.size()); + boolean canLoadMore = mediaList.size() == number; + notifyMediaListFetched(site, mediaList, offset > 0, canLoadMore, mimeType); }, error -> { String errorMessage = "VolleyError Fetching media: " + error; @@ -352,17 +340,9 @@ public void fetchMedia(@NonNull final SiteModel site, @Nullable final MediaModel add(WPComGsonRequest.buildGetRequest(url, null, MediaWPComRestResponse.class, response -> { MediaModel responseMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (responseMedia != null) { - responseMedia.setLocalSiteId(site.getId()); - AppLog.v(T.MEDIA, "Fetched media with ID: " + media.getMediaId()); - notifyMediaFetched(site, responseMedia, null); - } else { - String message = "could not parse Fetch media response, ID: " + media.getMediaId(); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = message; - notifyMediaFetched(site, media, error); - } + responseMedia.setLocalSiteId(site.getId()); + AppLog.v(T.MEDIA, "Fetched media with ID: " + media.getMediaId()); + notifyMediaFetched(site, responseMedia, null); }, error -> { AppLog.e(T.MEDIA, "VolleyError Fetching media: " + error); @@ -388,17 +368,9 @@ public void deleteMedia(@NonNull final SiteModel site, @Nullable final MediaMode String url = WPCOMREST.sites.site(site.getSiteId()).media.item(media.getMediaId()).delete.getUrlV1_1(); add(WPComGsonRequest.buildPostRequest(url, null, MediaWPComRestResponse.class, response -> { - MediaModel deletedMedia = mMediaResponseUtils.getMediaFromRestResponse(response); - if (deletedMedia != null) { - AppLog.v(T.MEDIA, "deleted media: " + media.getTitle()); - notifyMediaDeleted(site, media, null); - } else { - String message = "could not parse delete media response, ID: " + media.getMediaId(); - AppLog.w(T.MEDIA, message); - MediaError error = new MediaError(MediaErrorType.PARSE_ERROR); - error.logMessage = message; - notifyMediaDeleted(site, media, error); - } + mMediaResponseUtils.getMediaFromRestResponse(response); + AppLog.v(T.MEDIA, "deleted media: " + media.getTitle()); + notifyMediaDeleted(site, media, null); }, error -> { AppLog.e(T.MEDIA, "VolleyError deleting media (ID=" + media.getMediaId() + "): " + error); @@ -462,18 +434,11 @@ public void uploadStockMedia(@NonNull final SiteModel site, MultipleMediaResponse.class, response -> { // response is a list of media, exactly like that of MediaRestClient.fetchMediaList() - List mediaList = - mMediaResponseUtils.getMediaListFromRestResponse(response, site.getId()); - if (mediaList != null) { - UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); - mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); - } else { - AppLog.e(T.MEDIA, "Media list is null: " + response); - UploadStockMediaError mediaError = new UploadStockMediaError( - UploadStockMediaErrorType.GENERIC_ERROR, "Media list is null"); - UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaError); - mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); - } + List mediaList = mMediaResponseUtils.getMediaListFromRestResponse( + response, + site.getId()); + UploadedStockMediaPayload payload = new UploadedStockMediaPayload(site, mediaList); + mDispatcher.dispatch(MediaActionBuilder.newUploadedStockMediaAction(payload)); }, error -> { AppLog.e(T.MEDIA, "VolleyError uploading stock media: " + error); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index 77268af7a7..71308b1586 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -1,5 +1,7 @@ package org.wordpress.android.fluxc.network.rest.wpcom.media; +import androidx.annotation.NonNull; + import org.wordpress.android.fluxc.network.Response; import java.util.List; @@ -9,11 +11,12 @@ *

    * @see doc */ +@SuppressWarnings("NotNullFieldNotInitialized") public class MediaWPComRestResponse implements Response { public static final String DELETED_STATUS = "deleted"; public static class MultipleMediaResponse { - public List media; + @NonNull public List media; } public static class Thumbnails { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.kt index c3ee88245b..25ae6ba3eb 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.kt @@ -110,7 +110,7 @@ class StockMediaRestClient @Inject constructor( val mediaList: List = mediaResponseUtils.getMediaListFromRestResponse( response.data, site.id - ) ?: listOf() + ) UploadedStockMediaPayload(site, mediaList) } is Error -> { From 3334cf0e27dfb7c2eb9021a7e09700dbc49645bf Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Mon, 23 Oct 2023 14:18:06 +0300 Subject: [PATCH 87/87] Analysis: Add missing n-a to media wp com rest response fields FYI: 'n-a' stands for 'nullability annotations'. --- .../rest/wpcom/media/MediaResponseUtils.kt | 16 ++++----- .../wpcom/media/MediaWPComRestResponse.java | 35 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt index d2f85ef0ef..0890c2a428 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt @@ -37,17 +37,17 @@ class MediaResponseUtils media.caption = StringEscapeUtils.unescapeHtml4(from.caption) media.description = StringEscapeUtils.unescapeHtml4(from.description) media.alt = StringEscapeUtils.unescapeHtml4(from.alt) - if (from.thumbnails != null) { - if (!TextUtils.isEmpty(from.thumbnails.fmt_std)) { - media.thumbnailUrl = from.thumbnails.fmt_std + from.thumbnails?.let { + if (!TextUtils.isEmpty(it.fmt_std)) { + media.thumbnailUrl = it.fmt_std } else { - media.thumbnailUrl = from.thumbnails.thumbnail + media.thumbnailUrl = it.thumbnail } - if (!TextUtils.isEmpty(from.thumbnails.large)) { - media.fileUrlLargeSize = from.thumbnails.large + if (!TextUtils.isEmpty(it.large)) { + media.fileUrlLargeSize = it.large } - if (!TextUtils.isEmpty(from.thumbnails.medium)) { - media.fileUrlMediumSize = from.thumbnails.medium + if (!TextUtils.isEmpty(it.medium)) { + media.fileUrlMediumSize = it.medium } } media.height = from.height diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java index 71308b1586..dcbd0d2da5 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java @@ -1,6 +1,7 @@ package org.wordpress.android.fluxc.network.rest.wpcom.media; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.wordpress.android.fluxc.network.Response; @@ -20,30 +21,30 @@ public static class MultipleMediaResponse { } public static class Thumbnails { - public String thumbnail; - public String medium; - public String large; - public String fmt_std; + @Nullable public String thumbnail; + @Nullable public String medium; + @Nullable public String large; + @Nullable public String fmt_std; } public long ID; - public String date; + @NonNull public String date; public long post_ID; public long author_ID; - public String URL; - public String guid; - public String file; - public String extension; - public String mime_type; - public String title; - public String caption; - public String description; - public String alt; - public Thumbnails thumbnails; + @NonNull public String URL; + @NonNull public String guid; + @NonNull public String file; + @NonNull public String extension; + @NonNull public String mime_type; + @NonNull public String title; + @NonNull public String caption; + @NonNull public String description; + @NonNull public String alt; + @Nullable public Thumbnails thumbnails; public int height; public int width; public int length; - public String videopress_guid; + @Nullable public String videopress_guid; public boolean videopress_processing_done; - public String status; + @Nullable public String status; }