Skip to content

Commit

Permalink
Fix NPE in UploadService
Browse files Browse the repository at this point in the history
  • Loading branch information
malinajirka committed Aug 13, 2019
1 parent b5ce248 commit 7c840f0
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 7c840f0

Please sign in to comment.