Skip to content

Commit

Permalink
Merge pull request #10388 from wordpress-mobile/issue/10001-fix-npe-i…
Browse files Browse the repository at this point in the history
…n-upload-service

Fix NPE in UploadService
  • Loading branch information
malinajirka authored Aug 20, 2019
2 parents a1b5e47 + 7c840f0 commit 047cd21
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ public static void uploadMediaFromEditor(Context context, @NonNull ArrayList<Med
* waiting for media to finish uploading counts as 'waiting to be uploaded' until the media uploads complete.
*/
public static boolean isPostUploadingOrQueued(PostModel post) {
if (sInstance == null || post == null) {
UploadService instance = sInstance;
if (instance == null || post == null) {
return false;
}

Expand All @@ -395,7 +396,7 @@ public static boolean isPostUploadingOrQueued(PostModel post) {
}

// Then check the list of posts waiting for media to complete
return sInstance.mUploadStore.isPendingPost(post);
return instance.mUploadStore.isPendingPost(post);
}

public static boolean isPostQueued(PostModel post) {
Expand Down Expand Up @@ -495,12 +496,13 @@ public static boolean hasPendingOrInProgressPostUploads() {
}

public static float getMediaUploadProgressForPost(PostModel postModel) {
if (postModel == null || sInstance == null) {
UploadService instance = sInstance;
if (postModel == null || instance == null) {
// If the UploadService isn't running, there's no progress for this post
return 0;
}

Set<MediaModel> pendingMediaList = sInstance.mUploadStore.getUploadingMediaForPost(postModel);
Set<MediaModel> pendingMediaList = instance.mUploadStore.getUploadingMediaForPost(postModel);

if (pendingMediaList.size() == 0) {
return 1;
Expand All @@ -516,12 +518,13 @@ public static float getMediaUploadProgressForPost(PostModel postModel) {
}

public static float getUploadProgressForMedia(MediaModel mediaModel) {
if (mediaModel == null || sInstance == null) {
UploadService instance = sInstance;
if (mediaModel == null || instance == null) {
// If the UploadService isn't running, there's no progress for this media
return 0;
}

float uploadProgress = sInstance.mUploadStore.getUploadProgressForMedia(mediaModel);
float uploadProgress = instance.mUploadStore.getUploadProgressForMedia(mediaModel);

// If this is a video and video optimization is enabled, include the optimization progress in the outcome
if (mediaModel.isVideo() && WPMediaUtils.isVideoOptimizationEnabled()) {
Expand All @@ -533,10 +536,11 @@ public static float getUploadProgressForMedia(MediaModel mediaModel) {

public static @NonNull
Set<MediaModel> getPendingMediaForPost(PostModel postModel) {
if (postModel == null || sInstance == null) {
UploadService instance = sInstance;
if (postModel == null || instance == null) {
return Collections.emptySet();
}
return sInstance.mUploadStore.getUploadingMediaForPost(postModel);
return instance.mUploadStore.getUploadingMediaForPost(postModel);
}

public static boolean isPendingOrInProgressMediaUpload(@NonNull MediaModel media) {
Expand Down

0 comments on commit 047cd21

Please sign in to comment.