protected void saveIncomingRecords(List<String> idsToDownload, int startProgress) throws IOException, JSONException, HttpException { String subStatusFormat = "Downloading Record %s of" + idsToDownload.size(); int counter = 0; setProgressAndNotify(context.getString(R.string.synchronize_step_3), startProgress); for (String idToDownload : idsToDownload) { T incomingRecord = recordSyncService.getRecord(idToDownload); if (isCancelled()) { break; } try { if (repository.exists(incomingRecord.getUniqueId())) { repository.update(incomingRecord); } else { repository.createOrUpdate(incomingRecord); } recordSyncService.setMedia(incomingRecord); setProgressAndNotify(String.format(subStatusFormat, ++counter), startProgress); startProgress += 1; } catch (Exception e) { Log.e("SyncAllDataTask", "Error syncing record", e); throw new RuntimeException(e); } } }
@Override protected void onProgressUpdate(String... values) { RapidFtrApplication.getApplicationInstance() .showNotification( recordSyncService.getNotificationId(), recordSyncService.getNotificationTitle(), values[0]); }
@Override protected void onCancelled() { toggleMenu(SYNC_ALL); RapidFtrApplication.getApplicationInstance() .cancelNotification(recordSyncService.getNotificationId()); RapidFtrApplication.getApplicationInstance().setSyncTask(null); }
protected void setProgressAndNotify(String statusText, int progress) { if (!isCancelled()) { RapidFtrApplication.getApplicationInstance() .showProgressNotification( recordSyncService.getNotificationId(), context.getString(R.string.sync_title), statusText, maxProgress, progress, false); } }
@Override protected void onPostExecute(Boolean result) { toggleMenu(SYNC_ALL); RapidFtrApplication.getApplicationInstance().setSyncTask(null); if (result) { RapidFtrApplication.getApplicationInstance() .showNotification( recordSyncService.getNotificationId(), recordSyncService.getNotificationTitle(), successMessage); Toast.makeText( RapidFtrApplication_.getApplicationInstance(), successMessage, Toast.LENGTH_LONG) .show(); } else { Toast.makeText( RapidFtrApplication_.getApplicationInstance(), RapidFtrApplication_.getApplicationInstance().getString(R.string.sync_error), Toast.LENGTH_LONG) .show(); } }
void sendRecordsToServer(List<T> recordsToSyncWithServer) throws IOException, JSONException, HttpException { setProgressAndNotify(context.getString(R.string.synchronize_step_2), formSectionProgress); String subStatusFormat = "Uploading Record %s of " + recordsToSyncWithServer.size(); int counter = 0; int startProgress = formSectionProgress; for (T baseModel : recordsToSyncWithServer) { if (isCancelled()) { break; } recordSyncService.sync(baseModel, currentUser); setProgressAndNotify(String.format(subStatusFormat, ++counter), startProgress); startProgress += 1; } }