diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a5794..b69d72d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +## [1.7.13] - build 226 2024-04-18 +### Added +- Option to submit only current record to Collect; + ## [1.7.12] - build 225 2024-04-10 ### Fixed - Fixed cannot delete records from records list; diff --git a/android/src/main/java/org/openforis/collect/android/gui/SubmitDataToCollectActivity.java b/android/src/main/java/org/openforis/collect/android/gui/SubmitDataToCollectActivity.java index 4699f81..e8eb3f5 100644 --- a/android/src/main/java/org/openforis/collect/android/gui/SubmitDataToCollectActivity.java +++ b/android/src/main/java/org/openforis/collect/android/gui/SubmitDataToCollectActivity.java @@ -1,5 +1,10 @@ package org.openforis.collect.android.gui; +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; +import static org.openforis.collect.android.gui.CollectMobileApplication.LOG_TAG; + +import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; @@ -22,6 +27,7 @@ import org.openforis.collect.android.collectadapter.SurveyExporter; import org.openforis.collect.android.gui.settings.SettingsActivity; import org.openforis.collect.android.gui.util.AppDirs; +import org.openforis.collect.android.util.Collections; import org.openforis.collect.android.util.HttpConnectionHelper; import org.openforis.collect.android.util.MultipartUtility; import org.openforis.collect.android.util.ProgressHandler; @@ -31,12 +37,9 @@ import java.util.Timer; import java.util.TimerTask; -import static android.view.View.INVISIBLE; -import static android.view.View.VISIBLE; -import static org.openforis.collect.android.gui.CollectMobileApplication.LOG_TAG; - public class SubmitDataToCollectActivity extends BaseActivity { + public static final String EXTRA_ONLY_RECORD_IDS = "only_current_record"; private static final String DATA_RESTORE_ENDPOINT = "/api/surveys/restore/data"; private static final String DATA_RESTORE_JOB_ENDPOINT = "/api/surveys/data/restorejobs/%s/status.json"; private static final long RESTORE_DATA_JOB_MONITOR_PERIOD = 3000L; @@ -209,8 +212,14 @@ private class ExportDataTask extends AsyncTask { @Override protected File doInBackground(Void... voids) { SubmitDataToCollectActivity context = SubmitDataToCollectActivity.this; + Intent intent = context.getIntent(); + int[] recordIds = intent.hasExtra(EXTRA_ONLY_RECORD_IDS) ? intent.getIntArrayExtra(SubmitDataToCollectActivity.EXTRA_ONLY_RECORD_IDS) : new int[0]; try { - return ServiceLocator.surveyService().exportSurvey(AppDirs.surveysDir(context), new SurveyDataExportParameters()); + SurveyDataExportParameters parameters = new SurveyDataExportParameters(); + if (recordIds.length > 0) { + parameters.filterRecordIds = Collections.intArrayToList(recordIds); + } + return ServiceLocator.surveyService().exportSurvey(AppDirs.surveysDir(context), parameters); } catch (SurveyExporter.AllRecordKeysNotSpecified e) { handleError(AllRecordKeysNotSpecifiedDialog.generateMessage(context)); } catch (Exception e) { diff --git a/android/src/main/java/org/openforis/collect/android/gui/SurveyNodeActivity.java b/android/src/main/java/org/openforis/collect/android/gui/SurveyNodeActivity.java index 887cf26..28b1d6d 100644 --- a/android/src/main/java/org/openforis/collect/android/gui/SurveyNodeActivity.java +++ b/android/src/main/java/org/openforis/collect/android/gui/SurveyNodeActivity.java @@ -24,6 +24,7 @@ import org.openforis.collect.android.SurveyService; import org.openforis.collect.android.gui.barcode.BarcodeCaptureActivity; import org.openforis.collect.android.gui.detail.ExportDialogFragment; +import org.openforis.collect.android.gui.detail.SendDataToCollectDialogFragment; import org.openforis.collect.android.gui.entitytable.EntityTableDialogFragment; import org.openforis.collect.android.gui.input.AudioFileAttributeComponent; import org.openforis.collect.android.gui.input.BarcodeTextAttributeComponent; @@ -273,9 +274,8 @@ public void navigateDown(View view) { navigateDown(); } - public void exportDialog(MenuItem item) { + public void openExportDialog(MenuItem item) { if (Permissions.checkStoragePermissionOrRequestIt(this)) { - new ExportDialogFragment().show(getSupportFragmentManager(), "export-dialog"); } } @@ -478,21 +478,16 @@ public void openSurveyGuide(MenuItem menuItem) { } } - public void navigateToSendDataToCollect(MenuItem menuItem) { - navigateToSendDataToCollect(); + public void openSendDataToCollectDialog(MenuItem menuItem) { + openSendDataToCollectDialog(); } - private void navigateToSendDataToCollect() { + private void openSendDataToCollectDialog() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean remoteSyncEnabled = preferences.getBoolean(SettingsActivity.REMOTE_SYNC_ENABLED, false); if (remoteSyncEnabled) { if (Permissions.checkInternetPermissionOrRequestIt(this)) { - Dialogs.confirm(this, R.string.submit_to_collect_confirm_title, R.string.submit_to_collect_confirm_message, new Runnable() { - public void run() { - Keyboard.hide(SurveyNodeActivity.this); - SurveyNodeActivity.this.startActivity(new Intent(SurveyNodeActivity.this, SubmitDataToCollectActivity.class)); - } - }); + new SendDataToCollectDialogFragment().show(getSupportFragmentManager(), "send-data-to-collect-dialog"); } } else { Toast.makeText(this, R.string.submit_to_collect_remote_sync_not_configured, Toast.LENGTH_SHORT).show(); diff --git a/android/src/main/java/org/openforis/collect/android/gui/detail/SendDataToCollectDialogFragment.java b/android/src/main/java/org/openforis/collect/android/gui/detail/SendDataToCollectDialogFragment.java new file mode 100644 index 0000000..a407a94 --- /dev/null +++ b/android/src/main/java/org/openforis/collect/android/gui/detail/SendDataToCollectDialogFragment.java @@ -0,0 +1,70 @@ +package org.openforis.collect.android.gui.detail; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; + +import org.openforis.collect.R; +import org.openforis.collect.android.SurveyService; +import org.openforis.collect.android.gui.ServiceLocator; +import org.openforis.collect.android.gui.SubmitDataToCollectActivity; +import org.openforis.collect.android.viewmodel.UiNode; +import org.openforis.collect.android.viewmodel.UiRecordCollection; + +import java.util.Arrays; +import java.util.List; + +public class SendDataToCollectDialogFragment extends DialogFragment { + private static final int ALL_RECORDS = 0; + private static final int ONLY_CURRENT_RECORD = 1; + + private Dialog dialog = null; + + @NonNull + public Dialog onCreateDialog(Bundle savedInstanceState) { + final SurveyService surveyService = ServiceLocator.surveyService(); + + final int[] checkedItem = {ALL_RECORDS}; + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.submit_to_collect_confirm_title) + .setPositiveButton(R.string.action_submit_data_to_collect, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + if (SendDataToCollectDialogFragment.this.dialog != null) { + SendDataToCollectDialogFragment.this.dialog.dismiss(); + } + Intent intent = new Intent(getContext(), SubmitDataToCollectActivity.class); + boolean onlyCurrentRecord = checkedItem[0] == ONLY_CURRENT_RECORD; + if (onlyCurrentRecord) { + int recordId = surveyService.selectedNode().getUiRecord().getId(); + intent.putExtra(SubmitDataToCollectActivity.EXTRA_ONLY_RECORD_IDS, new int[]{recordId}); + } + getContext().startActivity(intent); + } + }) + .setNegativeButton(android.R.string.cancel, null); + + UiNode selectedNode = surveyService.selectedNode(); + if (selectedNode instanceof UiRecordCollection) { + builder.setMessage(R.string.submit_to_collect_confirm_message); + } else { + List options = Arrays.asList( + getString(R.string.export_dialog_option_all_records), + getString(R.string.export_dialog_option_only_current_record) + ); + builder.setSingleChoiceItems(options.toArray(new String[0]), checkedItem[0], new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + checkedItem[0] = which; + } + }); + } + dialog = builder.create(); + return dialog; + } + +} \ No newline at end of file diff --git a/android/src/main/res/menu/node_activity_actions.xml b/android/src/main/res/menu/node_activity_actions.xml index 6f671ba..b1cb958 100644 --- a/android/src/main/res/menu/node_activity_actions.xml +++ b/android/src/main/res/menu/node_activity_actions.xml @@ -17,13 +17,13 @@ android:title="@string/action_export" android:icon="?attr/exportIcon" app:showAsAction="never" - android:onClick="exportDialog"/> + android:onClick="openExportDialog"/> + android:onClick="openSendDataToCollectDialog"/> dd MMMM yyyy hh:mm - Send records to Collect - Send all collected records to Collect server? + Confirm submit data to Collect + Submit all collected records to Collect server? Collect server not configured in Settings 1/3 Exporting data @@ -213,6 +213,7 @@ Please select a valid Collect Mobile survey file (.%s) Export survey data + All records Only current record Only selected records Exclude image files diff --git a/gradle.properties b/gradle.properties index 80a4187..f960c46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ #Wed Apr 10 23:12:41 CEST 2024 currentVersionCode=225 -currentVersionName=1.7.12 +currentVersionName=1.7.13 org.gradle.jvmargs=-Xmx1536M android.enableJetifier=true android.useAndroidX=true diff --git a/model/src/main/java/org/openforis/collect/android/util/Collections.java b/model/src/main/java/org/openforis/collect/android/util/Collections.java index 9b85049..c3be6df 100644 --- a/model/src/main/java/org/openforis/collect/android/util/Collections.java +++ b/model/src/main/java/org/openforis/collect/android/util/Collections.java @@ -5,6 +5,14 @@ public abstract class Collections { + public static List intArrayToList(int[] arr) { + List list = new ArrayList(); + for (int recordId : arr) { + list.add(recordId); + } + return list; + } + public static List transform(List list, Transformer transformer) { List result = new ArrayList(list.size()); for (T item : list) {