Skip to content

Commit

Permalink
Merge pull request #835 from opensrp/834-fix-sync-progress-bar
Browse files Browse the repository at this point in the history
834 Fix sync progress bar
  • Loading branch information
allan-on committed Sep 15, 2021
2 parents b5615f8 + 98599f9 commit 9cc7955
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=4.3.21-SNAPSHOT
VERSION_NAME=4.3.22-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class SyncIntentService extends BaseSyncIntentService {
protected ValidateAssignmentHelper validateAssignmentHelper;
private long totalRecords;
private int fetchedRecords = 0;
private int totalRecordsCount = 0 ;
//this variable using to track the sync request goes along with add events/clients
private boolean isEmptyToAdd = true;

Expand Down Expand Up @@ -244,6 +245,7 @@ private void processFetchedEvents(Response resp, ECSyncHelper ecSyncUpdater, fin

if (eCount == 0) {
complete(FetchStatus.nothingFetched);
sendSyncProgressBroadcast(eCount); // Complete progress update
} else if (eCount < 0) {
fetchFailed(count);
} else {
Expand All @@ -267,7 +269,7 @@ private void processFetchedEvents(Response resp, ECSyncHelper ecSyncUpdater, fin
ecSyncUpdater.updateLastSyncTimeStamp(lastServerVersion);
}
sendSyncProgressBroadcast(eCount);
fetchRetry(0, false);
fetchRetry(0, true);

}
}
Expand Down Expand Up @@ -454,11 +456,12 @@ protected int fetchNumberOfEvents(JSONObject jsonObject) {
}

protected void sendSyncProgressBroadcast(int eventCount) {
totalRecordsCount += totalRecords;
fetchedRecords = fetchedRecords + eventCount;
SyncProgress syncProgress = new SyncProgress();
syncProgress.setSyncEntity(SyncEntity.EVENTS);
syncProgress.setTotalRecords(totalRecords);
syncProgress.setPercentageSynced(Utils.calculatePercentage(totalRecords, fetchedRecords));
syncProgress.setPercentageSynced(Utils.calculatePercentage(totalRecordsCount, fetchedRecords));
Intent intent = new Intent();
intent.setAction(AllConstants.SyncProgressConstants.ACTION_SYNC_PROGRESS);
intent.putExtra(AllConstants.SyncProgressConstants.SYNC_PROGRESS_DATA, syncProgress);
Expand Down

0 comments on commit 9cc7955

Please sign in to comment.