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); } } }
protected void setProgressAndNotify(String statusText, int progress) { if (!isCancelled()) { RapidFtrApplication.getApplicationInstance() .showProgressNotification( recordSyncService.getNotificationId(), context.getString(R.string.sync_title), statusText, maxProgress, progress, false); } }
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; } }
@Override protected Boolean doInBackground(Object... notRelevant) { try { sync(); return true; } catch (HttpException e) { Log.e("SyncAllDataTask", "HTTPError in sync", e); String message = RapidFtrApplication.getApplicationInstance().getString(R.string.session_timeout); if (e.getMessage() != null && e.getMessage().trim().length() > 0) { message = e.getMessage(); } publishProgress(message); return false; } catch (Exception e) { Log.e("SyncAllDataTask", "Error in sync", e); publishProgress(context.getString(R.string.sync_error)); return false; } }
@Override public void setContext(RapidFtrActivity context) { this.context = context; this.applicationContext = context.getContext(); }
private void configureNotification() { Intent intent = new Intent(context, RapidFtrActivity.class); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.contentView = new RemoteViews(context.getPackageName(), R.layout.progress_bar); }
private void initNotifiers() { notification = new Notification(R.drawable.icon, "Syncing in progress...", currentTimeMillis()); notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); }
private void toggleMenu(String showMenu) { context.getMenu().getItem(0).setVisible(showMenu == SYNC_ALL); context.getMenu().getItem(1).setVisible(showMenu == CANCEL_SYNC_ALL); }