Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

if (id == R.id.action_redownload) {
Intent i = new Intent(this, SyncActivity.class);
i.putExtra(IntentConsts.INTENT_KEY_APP_NAME, getAppName());
i.putExtra(IntentConsts.INTENT_KEY_REDOWNLOAD_ATTACHMENT, "true");
startActivityForResult(i, SYNC_ACTIVITY_RESULT_CODE);
return true;
}

if (id == R.id.action_about) {

FragmentManager mgr = getSupportFragmentManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* @author [email protected]
*/
public enum SyncActions {
IDLE, MONITOR_SYNCING, SYNC, RESET_SERVER
IDLE, MONITOR_SYNCING, SYNC, RESET_SERVER, RE_DOWNLOAD
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public SyncFragment() {
}
}

String re_download = getActivity().getIntent().getStringExtra(IntentConsts.INTENT_KEY_REDOWNLOAD_ATTACHMENT);
WebLogger.getLogger(getAppName())
.w(TAG, "re_download is :" + re_download);

if (re_download != null) {
reDownload();
}

ArrayAdapter<CharSequence> instanceAttachmentsAdapter = ArrayAdapter
.createFromResource(getActivity(), R.array.sync_attachment_option_names, android.R.layout.select_dialog_item);
syncInstanceAttachmentsSpinner.setAdapter(instanceAttachmentsAdapter);
Expand Down Expand Up @@ -309,6 +317,17 @@ void postTaskToAccessSyncService() {
}
});
break;
case RE_DOWNLOAD:
syncServiceInterface.synchronizeWithServer(getAppName(), SyncAttachmentState.RE_DOWNLOAD);
syncAction = SyncActions.MONITOR_SYNCING;

handler.post(new Runnable() {
@Override public void run() {
showProgressDialog(SyncStatus.NONE, null, getString(R.string.sync_starting), -1,
0);
}
});
break;
case RESET_SERVER:
syncServiceInterface.resetServer(getAppName(), syncAttachmentState);
syncAction = SyncActions.MONITOR_SYNCING;
Expand Down Expand Up @@ -479,6 +498,29 @@ public void onClickChangeUser(View v) {
return;
}

private void reDownload() {
WebLogger.getLogger(getAppName()).d(TAG, "[" + getId() + "] [onClickReDownload] timestamp: " + System.currentTimeMillis());
if (areCredentialsConfigured(false)) {
// show warning message
//TODO: make some error message here
AlertDialog.Builder msg = buildOkMessage("confirm re-download attachments",
"re-download will result in high data usage");

msg.setPositiveButton(getString(R.string.sync_reset), new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
WebLogger.getLogger(getAppName()).d(TAG,
"[" + getId() + "] [onClickReDownload] timestamp: " + System.currentTimeMillis());
disableButtons();
syncAction = SyncActions.RE_DOWNLOAD;
prepareForSyncAction();
}
});

msg.setNegativeButton(getString(R.string.cancel), null);
msg.show();
}
}

private void showProgressDialog(SyncStatus status, SyncProgressState progress, String message,
int progressStep, int maxStep) {
if (getActivity() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,14 +1053,20 @@ public void uploadInstanceFileBatch(List<CommonFileAttachmentTerms> batch,
@Override
public void downloadInstanceFileBatch(List<CommonFileAttachmentTerms> filesToDownload,
String serverInstanceFileUri, String instanceId, String tableId) throws HttpClientWebException, IOException {
// boolean downloadedAllFiles = true;
downloadInstanceFileBatch(filesToDownload, serverInstanceFileUri, instanceId, tableId, false);
}

@Override
public void downloadInstanceFileBatch(List<CommonFileAttachmentTerms> filesToDownload,
String serverInstanceFileUri, String instanceId, String tableId, boolean reduce) throws HttpClientWebException, IOException {
// boolean downloadedAllFiles = true;
URI instanceFilesDownloadUri = wrapper.constructInstanceFileBulkDownloadUri(serverInstanceFileUri, instanceId);

ArrayList<OdkTablesFileManifestEntry> entries = new ArrayList<OdkTablesFileManifestEntry>();
for (CommonFileAttachmentTerms cat : filesToDownload) {
OdkTablesFileManifestEntry entry = new OdkTablesFileManifestEntry();
entry.filename = cat.rowPathUri;
entry.reduceFileSize = reduce ? "t" : "f";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly recommend to use "true" and "false" instead of "t" and "f" as you can then simply use the Boolean class to convert the parameters. Consistency is important and if it's meant as true and false then use true and false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, OdkTablesFileManifestEntry is one of the classes found in the odk-rest-interface jar. In order for this change to work, the odk-rest-interface jar will need to be packaged with the change to OdkTablesManifestEntry in the sync-endpoint and put into androidlibrary under the androidlibrary/androidlibrary_lib/libs directory.

entries.add(entry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ void downloadInstanceFileBatch(List<CommonFileAttachmentTerms> filesToDownload,
String serverInstanceFileUri, String instanceId, String tableId)
throws HttpClientWebException, IOException;


/**
* @param filesToDownload
* @param serverInstanceFileUri
* @param instanceId
* @param tableId
* @param reduce
* @throws HttpClientWebException
* @throws IOException
*/
void downloadInstanceFileBatch(List<CommonFileAttachmentTerms> filesToDownload,
String serverInstanceFileUri, String instanceId, String tableId, boolean reduce)
throws HttpClientWebException, IOException;

/**
* Report the sync status for this device to the server
* @param tableResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,9 @@ public boolean syncRowLevelFileAttachments(String serverInstanceFileUri, String
log.i(LOGTAG, "syncRowLevelFileAttachments no files to send to server -- they are all synced");
fullySyncedUploads = true;
} else if (attachmentState.equals(SyncAttachmentState.SYNC) ||
attachmentState.equals(SyncAttachmentState.UPLOAD)) {
attachmentState.equals(SyncAttachmentState.UPLOAD) ||
attachmentState.equals(SyncAttachmentState.REDUCED_SYNC) ||
attachmentState.equals(SyncAttachmentState.RE_DOWNLOAD)) {
long batchSize = 0;
List<CommonFileAttachmentTerms> batch = new LinkedList<CommonFileAttachmentTerms>();
for (CommonFileAttachmentTerms fileAttachment : filesToUpload) {
Expand Down Expand Up @@ -903,10 +905,14 @@ public boolean syncRowLevelFileAttachments(String serverInstanceFileUri, String
log.i(LOGTAG, "syncRowLevelFileAttachments no files to fetch from server -- they are all synced");
fullySyncedDownloads = !impossibleToFullySyncDownloadsServerMissingFileToDownload;
} else if (attachmentState.equals(SyncAttachmentState.SYNC) ||
attachmentState.equals(SyncAttachmentState.DOWNLOAD)) {
attachmentState.equals(SyncAttachmentState.UPLOAD) ||
attachmentState.equals(SyncAttachmentState.REDUCED_SYNC) ||
attachmentState.equals(SyncAttachmentState.RE_DOWNLOAD)) {
long batchSize = 0;
List<CommonFileAttachmentTerms> batch = new LinkedList<CommonFileAttachmentTerms>();

boolean reduce = attachmentState.equals(SyncAttachmentState.REDUCED_SYNC);

for (CommonFileAttachmentTerms fileAttachment : filesToDownloadSizes.keySet()) {

// Check if adding the file exceeds the batch limit. If so, download the current batch
Expand All @@ -916,8 +922,8 @@ public boolean syncRowLevelFileAttachments(String serverInstanceFileUri, String
if (batchSize + filesToDownloadSizes.get(fileAttachment) > MAX_BATCH_SIZE &&
!batch.isEmpty()) {
log.i(LOGTAG, "syncRowLevelFileAttachments downloading batch for " + instanceId);
sc.getSynchronizer().downloadInstanceFileBatch(batch,
serverInstanceFileUri, instanceId, tableId);
HttpSynchronizer httpSynchronizer = (HttpSynchronizer) sc.getSynchronizer();
httpSynchronizer.downloadInstanceFileBatch(batch, serverInstanceFileUri, instanceId, tableId, reduce);
batch.clear();
batchSize = 0;
}
Expand All @@ -929,8 +935,8 @@ public boolean syncRowLevelFileAttachments(String serverInstanceFileUri, String
if ( !batch.isEmpty() ) {
// download the final batch
log.i(LOGTAG, "syncRowLevelFileAttachments downloading batch for " + instanceId);
sc.getSynchronizer().downloadInstanceFileBatch(batch, serverInstanceFileUri,
instanceId, tableId);
HttpSynchronizer httpSynchronizer = (HttpSynchronizer) sc.getSynchronizer();
httpSynchronizer.downloadInstanceFileBatch(batch, serverInstanceFileUri, instanceId, tableId, reduce);
}

fullySyncedDownloads = !impossibleToFullySyncDownloadsServerMissingFileToDownload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ public void syncAttachments(TableResource tableResource,


String sqlCommand;
BindArgs bindArgs = new BindArgs(new Object[]{ SyncState.in_conflict.name(),
SyncState.synced_pending_files.name() });
BindArgs bindArgs;
if (attachmentState.equals(SyncAttachmentState.RE_DOWNLOAD)) {
bindArgs = new BindArgs(new Object[]{SyncState.synced.name(),
SyncState.synced_pending_files.name()});
} else {
bindArgs = new BindArgs(new Object[]{ SyncState.in_conflict.name(),
SyncState.synced_pending_files.name() });
}

{
StringBuilder sqlCommandBuilder = new StringBuilder();
Expand Down Expand Up @@ -239,7 +245,8 @@ public void syncAttachments(TableResource tableResource,
boolean syncAttachments = false;
// the local row wasn't impacted by a server change
// see if this local row should be pushed to the server.
if (state == SyncState.in_conflict) {
if (state == SyncState.in_conflict ||
(state == SyncState.synced && attachmentState.equals(SyncAttachmentState.RE_DOWNLOAD))) {
if (!fileAttachmentColumns.isEmpty()) {
// fetch the file attachments for an in_conflict row but don't delete
// anything and never update the state to synced (it must stay in in_conflict)
Expand Down Expand Up @@ -299,6 +306,7 @@ public void syncAttachments(TableResource tableResource,
idString = R.string.sync_skipping_attachments_server_row;
break;
case SYNC:
case REDUCED_SYNC:
idString = R.string.sync_syncing_attachments_server_row;
break;
case UPLOAD:
Expand Down
7 changes: 7 additions & 0 deletions services_app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
android:title="@string/action_change_user"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_redownload"
android:orderInCategory="50"
android:icon="@drawable/ic_cached_black_24dp"
android:title="@string/action_redownload"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_about"
android:orderInCategory="100"
Expand Down
2 changes: 2 additions & 0 deletions services_app/src/main/res/values-es/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<item>UPLOAD</item>
<item>DOWNLOAD</item>
<item>NONE</item>
<item>REDUCED_SYNC</item>
</string-array>
<string-array name="sync_attachment_option_names">
<item>Sincronizar Todos</item>
<item>Solo enviar archivos (imágenes, audio, video) al servidor</item>
<item>Solo recibir archivos (imágenes, audio, video) del servidor</item>
<item>No sincronizar archivos</item>
<item> </item>
</string-array>
</resources>
4 changes: 3 additions & 1 deletion services_app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<string name="action_sync">Sincronización</string>
<!--<string name="action_logout">Logout</string>-->
<string name="action_change_user">Cambiar usuario/Cerrar sesión</string>
<string name="action_redownload"></string>
<string name="action_resolve_conflict">Resolver Conflictos</string>
<string name="action_verify_server_settings">Actualizar permisos de usuario</string>
<!-- Checkpoint and Conflict Resolution Stuff -->
Expand Down Expand Up @@ -165,6 +166,7 @@
<string name="sync_defer_instance_files">Sincronizar archivos adjuntos de la instancia más tarde</string>
<string name="sync_start">Sincronizar Ahora</string>
<string name="sync_reset_server">Reinicializar servidor</string>
<string name="sync_redownload"> </string>
<string name="sync_confirm_change_settings">Confirmar cambios de configuración</string>
<string name="sync_change_settings_warning">Si cambia su configuración, tablas que han sincronizado ahora pueden ya no ser capaces de sincronizar en el futuro.</string>
<string name="sync_save">Guardar</string>
Expand Down Expand Up @@ -199,7 +201,7 @@
<string name="sync_notification_success_pending_attachments_text">\"Sincronización completado, pero %1$d tabulas tienen filas con archivos que no se han sincronizaido completamente.</string>
<string name="sync_status_network_transport_error">Error de red.\nPor favor confirme que el dispotivo tiene acceso al servidor.</string>
<string name="sync_status_device_internal_error">Error interno. \n Por favor, enviar un informe de error</string>
<string name="sync_status_authentication_error">Error de autenticación. \nPlease verificar su
<string name="sync_status_authentication_error">Error de autenticación. \nPlease verificar su
nombre de usuario/contraseña o su cuenta de acceso.</string>
<string name="sync_status_internal_server_error">Error interno del servidor (500). \nPor favor notificar al administrador del servidor.</string>
<string name="sync_status_bad_gateway_or_client_config">WiFi Gateway o Error de configuración. \nPor favor verificar la URL del servidor y que el navegador del dispositivo puede acceder a su servidor.</string>
Expand Down
2 changes: 2 additions & 0 deletions services_app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<item>UPLOAD</item>
<item>DOWNLOAD</item>
<item>NONE</item>
<item>REDUCED_SYNC</item>
</string-array>
<string-array name="sync_attachment_option_names">
<item>Fully Sync Attachments</item>
<item>Upload Attachments Only</item>
<item>Download Attachments Only</item>
<item>Do Not Sync Attachments</item>
<item>Sync Reduced-size Attachments</item>
</string-array>
</resources>
2 changes: 2 additions & 0 deletions services_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<string name="action_sync">Sync</string>
<!--<string name="action_logout">Logout</string>-->
<string name="action_change_user">Change User/Logout</string>
<string name="action_redownload">re-Download attachments</string>
<string name="action_resolve_conflict">Resolve Conflicts</string>
<string name="action_verify_server_settings">Update User Permissions</string>

Expand Down Expand Up @@ -195,6 +196,7 @@
<string name="sync_defer_instance_files">Defer Instance Attachments</string>
<string name="sync_start">Sync now</string>
<string name="sync_reset_server">Reset App Server</string>
<string name="sync_redownload">Re-download Attachments</string>

<string name="sync_confirm_change_settings">Confirm Change Settings</string>
<string name="sync_change_settings_warning">If you change your settings, tables you have sync\'d now may no longer be able to be sync\'d.</string>
Expand Down