private void notifyAboutBackup(BackupState state) { NotificationCompat.Builder builder = createNotification(R.string.status_backup); notification = builder.setContentTitle(getString(R.string.status_backup)) .setContentText(state.getNotificationLabel(getResources())) .setContentIntent(getPendingIntent(null)) .build(); startForeground(BACKUP_ID, notification); }
@Subscribe public void backupStateChanged(final BackupState newState) { if (App.LOCAL_LOGV) Log.v(TAG, "backupStateChanged:"+newState); if (newState.backupType.isBackground()) return; stateChanged(newState); switch (newState.state) { case FINISHED_BACKUP: finishedBackup(newState); break; case BACKUP: restoreButton.setEnabled(false); backupButton.setText(R.string.ui_sync_button_label_syncing); statusLabel.setText(R.string.status_backup); syncDetailsLabel.setText(newState.getNotificationLabel(getContext().getResources())); progressBar.setIndeterminate(false); progressBar.setProgress(newState.currentSyncedItems); progressBar.setMax(newState.itemsToSync); break; case CANCELED_BACKUP: statusLabel.setText(R.string.status_canceled); syncDetailsLabel.setText(getString(R.string.status_canceled_details, newState.currentSyncedItems, newState.itemsToSync)); break; } }
@Test public void shouldGetNotificationLabelError() throws Exception { assertThat(new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo")).getNotificationLabel(resources)) .isEqualTo("foo"); } }
@Test public void shouldGetNotificationLabelCalculating() throws Exception { assertThat(new BackupState(SmsSyncState.CALC, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_calc_details) ); }
@Test public void shouldGetNotificationLabelLogin() throws Exception { assertThat(new BackupState(SmsSyncState.LOGIN, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_login_details) ); }