Skip to content

Commit 8384ad0

Browse files
fixes - #1984 -Upload count does not get updated right away post successful upload
->implements the Callback method to update total number of media uploaded
1 parent 3ad16d1 commit 8384ad0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import fr.free.nrw.commons.notification.Notification;
3939
import fr.free.nrw.commons.notification.NotificationController;
4040
import fr.free.nrw.commons.theme.BaseActivity;
41+
import fr.free.nrw.commons.upload.UploadService.ServiceCallback;
4142
import io.reactivex.disposables.Disposable;
4243
import java.util.List;
4344

@@ -84,7 +85,7 @@ public class ContributionsFragment
8485
OnBackStackChangedListener,
8586
LocationUpdateListener,
8687
MediaDetailProvider,
87-
ICampaignsView, ContributionsContract.View, Callback {
88+
ICampaignsView, ContributionsContract.View, Callback , ServiceCallback {
8889
@Inject @Named("default_preferences") JsonKvStore store;
8990
@Inject NearbyController nearbyController;
9091
@Inject OkHttpJsonApiClient okHttpJsonApiClient;
@@ -135,6 +136,7 @@ public static ContributionsFragment newInstance() {
135136
public void onServiceConnected(ComponentName componentName, IBinder binder) {
136137
uploadService = (UploadService) ((UploadService.UploadServiceLocalBinder) binder)
137138
.getService();
139+
uploadService.setServiceCallback(ContributionsFragment.this);
138140
isUploadServiceConnected = true;
139141
}
140142

@@ -520,6 +522,7 @@ public void onDestroy() {
520522

521523
if (isUploadServiceConnected) {
522524
if (getActivity() != null) {
525+
uploadService.setServiceCallback(null);
523526
getActivity().unbindService(uploadServiceConnection);
524527
isUploadServiceConnected = false;
525528
}
@@ -666,5 +669,10 @@ public void backButtonClicked() {
666669
public MediaDetailPagerFragment getMediaDetailPagerFragment() {
667670
return mediaDetailPagerFragment;
668671
}
672+
673+
@Override
674+
public void updateUploadCount() {
675+
setUploadCount();
676+
}
669677
}
670678

app/src/main/java/fr/free/nrw/commons/upload/UploadService.java

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class UploadService extends CommonsDaggerService {
8080
private NotificationCompat.Builder curNotification;
8181
private int toUpload;
8282
private CompositeDisposable compositeDisposable;
83+
private ServiceCallback serviceCallback;
8384

8485
/**
8586
* The filePath names of unfinished uploads, used to prevent overwriting
@@ -395,6 +396,10 @@ private void onSuccessfulUpload(Contribution contribution, UploadResult uploadRe
395396
}
396397
}
397398
saveCompletedContribution(contribution, uploadResult);
399+
if(serviceCallback!=null) {
400+
//this function update the tatol number media Uploaded or contributions
401+
serviceCallback.updateUploadCount();
402+
}
398403
}
399404

400405
private void saveCompletedContribution(Contribution contribution, UploadResult uploadResult) {
@@ -471,4 +476,13 @@ private String findUniqueFilename(String fileName) throws IOException {
471476
}
472477
return sequenceFileName;
473478
}
479+
480+
public interface ServiceCallback{
481+
void updateUploadCount() ;
482+
}
483+
484+
public void setServiceCallback(ServiceCallback serviceCallback) {
485+
this.serviceCallback = serviceCallback;
486+
}
487+
474488
}

0 commit comments

Comments
 (0)