From 76e61aaffd6742b2681b0b6ae070b036c078cc0c Mon Sep 17 00:00:00 2001 From: Chinmoy Chakraborty Date: Thu, 16 Mar 2023 17:14:41 +0530 Subject: [PATCH] Added ODKEventExporter and FormEventExporter. Supported events: - OnFormOpened - OnFormOpenFailed - OnFormSaved - OnFormSaveError - OnFormUploaded - OnFormUploadFailed - OnFormDownloaded - OnFormDownloadFailed --- odk/collect/collect_app/build.gradle | 4 +- .../android/activities/FormEntryActivity.java | 13 ++++ .../collect/android/events/FormEventBus.kt | 67 ++++++++++++++++++ .../odk/collect/android/events/ODKEventBus.kt | 17 +++++ .../autosend/InstanceAutoSender.kt | 9 +++ .../android/tasks/DownloadFormListTask.java | 1 + .../android/tasks/DownloadFormsTask.java | 3 + odk/config/dependencies.gradle | 2 + .../extension/handlers/FormsNetworkHandler.kt | 2 + .../collect/extension/handlers/ODKHandler.kt | 20 ++---- .../extension/interactors/ODKInteractor.kt | 4 +- .../listeners/FileDownloadListener.kt | 6 +- sample/build.gradle | 2 + .../oce_sample/ODKFeatureTesterActivity.kt | 70 ++++++++++--------- 14 files changed, 166 insertions(+), 54 deletions(-) create mode 100644 odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventBus.kt create mode 100644 odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventBus.kt diff --git a/odk/collect/collect_app/build.gradle b/odk/collect/collect_app/build.gradle index d1aa32d8fe0..0648d22a758 100644 --- a/odk/collect/collect_app/build.gradle +++ b/odk/collect/collect_app/build.gradle @@ -4,8 +4,6 @@ apply from: '../../config/quality.gradle' apply from: '../../config/jacoco.gradle' apply from: '../../config/dependencies.gradle' -import com.android.ddmlib.DdmPreferences - // Build numbers were manually set until 1067 def LEGACY_BUILD_NUMBER_OFFSET = 1067 @@ -181,6 +179,8 @@ dependencies { implementation packages.bikram_sambat implementation packages.rarepebble_colorpicker implementation packages.commons_io + implementation packages.rx_java + implementation packages.rx_android implementation(packages.opencsv) { exclude group: 'commons-logging' } diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java b/odk/collect/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java index 5df026d4b53..8d69f222f1f 100644 --- a/odk/collect/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java @@ -99,6 +99,7 @@ import org.odk.collect.android.audio.M4AAppender; import org.odk.collect.android.backgroundwork.InstanceSubmitScheduler; import org.odk.collect.android.dao.helpers.InstancesDaoHelper; +import org.odk.collect.android.events.FormEventBus; import org.odk.collect.android.exception.JavaRosaException; import org.odk.collect.android.external.FormsContract; import org.odk.collect.android.external.InstancesContract; @@ -703,10 +704,12 @@ private void loadFromIntent(Intent intent) { } formPath = candidateForms.get(0).getFormFilePath(); + FormEventBus.INSTANCE.formOpened(instance.getFormId()); } else if (uriMimeType != null && uriMimeType.equals(FormsContract.CONTENT_ITEM_TYPE)) { Form form = formsRepositoryProvider.get().get(ContentUriHelper.getIdFromUri(uri)); if (form != null) { formPath = form.getFormFilePath(); + FormEventBus.INSTANCE.formOpened(form.getFormId()); } if (formPath == null) { @@ -1823,6 +1826,11 @@ private void handleSaveResult(FormSaveViewModel.SaveResult result) { DialogFragmentUtils.dismissDialog(SaveFormProgressDialogFragment.class, getSupportFragmentManager()); DialogFragmentUtils.dismissDialog(ChangesReasonPromptDialogFragment.class, getSupportFragmentManager()); + Instance instance = new InstancesRepositoryProvider(this).get().getOneByPath(getAbsoluteInstancePath()); + if (instance != null) { + FormEventBus.INSTANCE.formSaved(instance.getFormId(), instance.getInstanceFilePath()); + } + showShortToast(this, R.string.data_saved_ok); if (result.getRequest().viewExiting()) { @@ -1848,6 +1856,11 @@ private void handleSaveResult(FormSaveViewModel.SaveResult result) { message = getString(R.string.data_saved_error); } + instance = new InstancesRepositoryProvider(this).get().getOneByPath(getAbsoluteInstancePath()); + if (instance != null) { + FormEventBus.INSTANCE.formSaveError(instance.getFormId(), message); + } + showLongToast(this, message); formSaveViewModel.resumeFormEntry(); break; diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventBus.kt b/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventBus.kt new file mode 100644 index 00000000000..cb4dd8f3c95 --- /dev/null +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventBus.kt @@ -0,0 +1,67 @@ +package org.odk.collect.android.events + +/** + * Events exporter class for form events. This class contains all the + * events that occur during the lifecycle of a form. + */ +object FormEventBus: ODKEventBus() { + //TODO: make these functions internal + + fun formOpened(formId: String) { + state.onNext(FormStateEvent.OnFormOpened(formId)) + } + + fun formOpenFailed(formId: String, errorMessage: String) { + state.onNext(FormStateEvent.OnFormOpenFailed(formId, errorMessage)) + } + + fun formSaved(formId: String, instancePath: String) { + state.onNext(FormStateEvent.OnFormSaved(formId, instancePath)) + } + + fun formSaveError(formId: String, errorMessage: String) { + state.onNext(FormStateEvent.OnFormSaveError(formId, errorMessage)) + } + + fun formUploaded(formId: String, instancePath: String) { + state.onNext(FormStateEvent.OnFormUploaded(formId, instancePath)) + } + + fun formUploadError(formId: String, errorMessage: String) { + state.onNext(FormStateEvent.OnFormUploadFailed(formId, errorMessage)) + } + + fun formDownloaded(formId: String) { + state.onNext(FormStateEvent.OnFormDownloaded(formId)) + } + + fun formDownloadFailed(formId: String, errorMessage: String) { + state.onNext(FormStateEvent.OnFormDownloadFailed(formId, errorMessage)) + } +} + +sealed class FormStateEvent { + /** Called when a form is opened. */ + data class OnFormOpened(val formId: String): FormStateEvent() + + /** Called when an error occurs while opening a form. */ + data class OnFormOpenFailed(val formId: String, val errorMessage: String): FormStateEvent() + + /** Called when a form is saved. */ + data class OnFormSaved(val formId: String, val instancePath: String): FormStateEvent() + + /** Called when a form save process errors out. */ + data class OnFormSaveError(val formId: String, val errorMessage: String): FormStateEvent() + + /** Called when a form upload is successful. */ + data class OnFormUploaded(val formId: String, val instancePath: String): FormStateEvent() + + /** Called when a form upload fails. */ + data class OnFormUploadFailed(val formId: String, val errorMessage: String): FormStateEvent() + + /** Called when a form is successfully downloaded. */ + data class OnFormDownloaded(val formId: String): FormStateEvent() + + /** Called when a form download fails. */ + data class OnFormDownloadFailed(val formId: String, val errorMessage: String): FormStateEvent() +} \ No newline at end of file diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventBus.kt b/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventBus.kt new file mode 100644 index 00000000000..69a20a1dc41 --- /dev/null +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventBus.kt @@ -0,0 +1,17 @@ +package org.odk.collect.android.events + +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.subjects.PublishSubject + +/** + * This is the base class for all the event exporters. Extend this class + * to create more concrete event exporters, for example form events. + */ +open class ODKEventBus { + + protected val state: PublishSubject = PublishSubject.create() + + fun getState(): Observable { + return state.hide() + } +} \ No newline at end of file diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/instancemanagement/autosend/InstanceAutoSender.kt b/odk/collect/collect_app/src/main/java/org/odk/collect/android/instancemanagement/autosend/InstanceAutoSender.kt index 157fd6d4127..0529ef9e769 100644 --- a/odk/collect/collect_app/src/main/java/org/odk/collect/android/instancemanagement/autosend/InstanceAutoSender.kt +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/instancemanagement/autosend/InstanceAutoSender.kt @@ -3,6 +3,7 @@ package org.odk.collect.android.instancemanagement.autosend import android.content.Context import org.odk.collect.analytics.Analytics import org.odk.collect.android.R +import org.odk.collect.android.events.FormEventBus import org.odk.collect.android.formmanagement.InstancesAppState import org.odk.collect.android.gdrive.GoogleAccountsManager import org.odk.collect.android.gdrive.GoogleApiProvider @@ -43,6 +44,14 @@ class InstanceAutoSender( try { val result: Map = instanceSubmitter.submitInstances(toUpload) + result.entries.stream().forEach { entry -> + if (entry.value == null) { + FormEventBus.formUploaded(entry.key.formId, entry.key.instanceFilePath) + } + else { + FormEventBus.formUploadError(entry.key.formId, entry.value!!.message) + } + } notifier.onSubmission(result, projectDependencyProvider.projectId) } catch (e: SubmitException) { when (e.type) { diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormListTask.java b/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormListTask.java index 8569da6e229..97839a32eaf 100644 --- a/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormListTask.java +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormListTask.java @@ -19,6 +19,7 @@ import androidx.core.util.Pair; +import org.odk.collect.android.events.FormEventBus; import org.odk.collect.android.formmanagement.ServerFormDetails; import org.odk.collect.android.formmanagement.ServerFormsDetailsFetcher; import org.odk.collect.android.listeners.FormListDownloaderListener; diff --git a/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormsTask.java b/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormsTask.java index 7420cfdf00d..f5c25ed43a9 100644 --- a/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormsTask.java +++ b/odk/collect/collect_app/src/main/java/org/odk/collect/android/tasks/DownloadFormsTask.java @@ -21,6 +21,7 @@ import org.odk.collect.android.R; import org.odk.collect.android.application.Collect; +import org.odk.collect.android.events.FormEventBus; import org.odk.collect.android.formmanagement.FormDownloadException; import org.odk.collect.android.formmanagement.FormDownloader; import org.odk.collect.android.formmanagement.ServerFormDetails; @@ -70,10 +71,12 @@ protected Map doInBackground(ArrayList }, this::isCancelled); results.put(serverFormDetails, null); + FormEventBus.INSTANCE.formDownloaded(serverFormDetails.getFormId()); } catch (FormDownloadException.DownloadingInterrupted e) { return emptyMap(); } catch (FormDownloadException e) { results.put(serverFormDetails, e); + FormEventBus.INSTANCE.formDownloadFailed(serverFormDetails.getFormId(), e.getMessage()); } index++; diff --git a/odk/config/dependencies.gradle b/odk/config/dependencies.gradle index 9a58a105b83..f1ed1a3a53b 100644 --- a/odk/config/dependencies.gradle +++ b/odk/config/dependencies.gradle @@ -112,5 +112,7 @@ ext { robolectric : "org.robolectric:robolectric:${versions.robolectric}", robolectric_shadows_multidex : "org.robolectric:shadows-multidex:${versions.robolectric}", uiautomator : "androidx.test.uiautomator:uiautomator:2.2.0", + rx_java : "io.reactivex.rxjava3:rxjava:3.1.5", + rx_android :"io.reactivex.rxjava3:rxandroid:3.0.0" ] } \ No newline at end of file diff --git a/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/FormsNetworkHandler.kt b/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/FormsNetworkHandler.kt index 1bb1cca4157..c29ab1d88e3 100644 --- a/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/FormsNetworkHandler.kt +++ b/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/FormsNetworkHandler.kt @@ -9,6 +9,7 @@ import io.samagra.odk.collect.extension.utilities.FormsDownloadUtil import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import org.odk.collect.android.events.FormEventBus import org.odk.collect.android.formmanagement.FormDownloadException import org.odk.collect.android.formmanagement.ServerFormDetails import org.odk.collect.android.listeners.DownloadFormsTaskListener @@ -128,6 +129,7 @@ class FormsNetworkHandler @Inject constructor( formsDownloadUtil.downloadFormsList { formList, exception -> if (exception != null || formList == null) { listener.onCancelled(exception) + FormEventBus.formDownloadFailed(formId, exception.message ?: "Form list download failed!") return@downloadFormsList } val requiredForms = ArrayList(formList.filter { form -> form.value.formId == formId }.values) diff --git a/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/ODKHandler.kt b/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/ODKHandler.kt index e30a80ed4a8..0d2c7e6554b 100644 --- a/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/ODKHandler.kt +++ b/odk/extension/src/main/java/io/samagra/odk/collect/extension/handlers/ODKHandler.kt @@ -11,7 +11,6 @@ import io.samagra.odk.collect.extension.interactors.FormsInteractor import io.samagra.odk.collect.extension.interactors.FormsNetworkInteractor import io.samagra.odk.collect.extension.interactors.ODKInteractor import io.samagra.odk.collect.extension.listeners.FileDownloadListener -import io.samagra.odk.collect.extension.listeners.FormsProcessListener import io.samagra.odk.collect.extension.listeners.ODKProcessListener import io.samagra.odk.collect.extension.utilities.ConfigHandler import kotlinx.coroutines.CoroutineScope @@ -65,7 +64,7 @@ class ODKHandler @Inject constructor( CoroutineScope(Job()).launch{ ConfigHandler(application).reset(listener) } } - override fun openForm(formId: String, context: Context, listener: FormsProcessListener) { + override fun openForm(formId: String, context: Context) { CoroutineScope(Job()).launch { // Delete any saved instances of this form val savedInstances = instancesRepository.getAllByFormId(formId) @@ -76,25 +75,24 @@ class ODKHandler @Inject constructor( } val requiredForm = formsDatabaseInteractor.getLatestFormById(formId) if (requiredForm == null) { - downloadAndOpenForm(formId, context, listener) + downloadAndOpenForm(formId, context) } else { val xmlFile = File(requiredForm.formFilePath) if (xmlFile.exists() && (requiredForm.formMediaPath == null || mediaExists(requiredForm))) { - listener.onProcessed() formsInteractor.openFormWithFormId(formId, context) } else { requiredForm.formMediaPath?.let { File(it).deleteRecursively() } xmlFile.delete() formsDatabaseInteractor.deleteByFormId(formId) - downloadAndOpenForm(formId, context, listener) + downloadAndOpenForm(formId, context) } } } } - override fun openSavedForm(formId: String, context: Context, listener: FormsProcessListener) { + override fun openSavedForm(formId: String, context: Context) { CoroutineScope(Job()).launch { val formInstances = instancesRepository.getAllByFormId(formId) var savedInstance: Instance? = null @@ -104,7 +102,7 @@ class ODKHandler @Inject constructor( } } if (savedInstance == null) { - openForm(formId, context, listener) + openForm(formId, context) } else { val currentProjectProvider = DaggerAppDependencyComponent.builder().application(application).build().currentProjectProvider() @@ -115,21 +113,15 @@ class ODKHandler @Inject constructor( intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED) intent.putExtra(FormHierarchyActivity.EXTRA_JUMP_TO_BEGINNING, true) context.startActivity(intent) - listener.onProcessed() } } } - private fun downloadAndOpenForm(formId: String, context: Context, listener: FormsProcessListener) { + private fun downloadAndOpenForm(formId: String, context: Context) { formsNetworkInteractor.downloadFormById(formId, object : FileDownloadListener { - override fun onProgress(progress: Int) {} override fun onComplete(downloadedFile: File) { - listener.onProcessed() formsInteractor.openFormWithFormId(formId, context) } - override fun onCancelled(exception: Exception) { - listener.onProcessingError(exception) - } }) } diff --git a/odk/extension/src/main/java/io/samagra/odk/collect/extension/interactors/ODKInteractor.kt b/odk/extension/src/main/java/io/samagra/odk/collect/extension/interactors/ODKInteractor.kt index 8c604eb7c88..34f84753433 100644 --- a/odk/extension/src/main/java/io/samagra/odk/collect/extension/interactors/ODKInteractor.kt +++ b/odk/extension/src/main/java/io/samagra/odk/collect/extension/interactors/ODKInteractor.kt @@ -27,8 +27,8 @@ interface ODKInteractor { /** Opens the latest version related to the formId. Deletes any * saved instance of a form with this particular formId. */ - fun openForm(formId: String, context: Context, listener: FormsProcessListener) + fun openForm(formId: String, context: Context) /** Opens a saved form. If no saved instance is found, opens a new form. */ - fun openSavedForm(formId: String, context: Context, listener: FormsProcessListener) + fun openSavedForm(formId: String, context: Context) } diff --git a/odk/extension/src/main/java/io/samagra/odk/collect/extension/listeners/FileDownloadListener.kt b/odk/extension/src/main/java/io/samagra/odk/collect/extension/listeners/FileDownloadListener.kt index 2b40babc30e..47e45988579 100644 --- a/odk/extension/src/main/java/io/samagra/odk/collect/extension/listeners/FileDownloadListener.kt +++ b/odk/extension/src/main/java/io/samagra/odk/collect/extension/listeners/FileDownloadListener.kt @@ -6,13 +6,13 @@ import java.io.File interface FileDownloadListener { /** Called when there is update in download progress. */ - fun onProgress(progress: Int) + fun onProgress(progress: Int) {} /** Called when the download is complete. * Takes the downloaded file as an argument. */ - fun onComplete(downloadedFile: File) + fun onComplete(downloadedFile: File) {} /** Called if the download is cancelled due to any error. * Takes the exception occurred as an argument. */ - fun onCancelled(exception: Exception) + fun onCancelled(exception: Exception) {} } \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index f388e75975a..82c28320e07 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -280,6 +280,8 @@ dependencies { androidTestImplementation Dependencies.androidx_work_testing androidTestImplementation Dependencies.uiautomator implementation project(':odk:extension') + implementation "io.reactivex.rxjava3:rxjava:3.1.5" + implementation "io.reactivex.rxjava3:rxandroid:3.0.0" // Real LeakCanary for debug builds only: notifications, analysis, etc // debugImplementation Dependencies.leakcanary diff --git a/sample/src/main/java/io/samagra/oce_sample/ODKFeatureTesterActivity.kt b/sample/src/main/java/io/samagra/oce_sample/ODKFeatureTesterActivity.kt index 8e00d909d45..0ae2bc385c7 100644 --- a/sample/src/main/java/io/samagra/oce_sample/ODKFeatureTesterActivity.kt +++ b/sample/src/main/java/io/samagra/oce_sample/ODKFeatureTesterActivity.kt @@ -9,19 +9,18 @@ import android.widget.Button import android.widget.EditText import android.widget.ProgressBar import android.widget.Toast +import io.reactivex.rxjava3.disposables.CompositeDisposable -import io.samagra.odk.collect.extension.components.DaggerFormsDatabaseInteractorComponent -import io.samagra.odk.collect.extension.components.DaggerFormsNetworkInteractorComponent -import io.samagra.odk.collect.extension.components.DaggerODKInteractorComponent import io.samagra.odk.collect.extension.interactors.FormsDatabaseInteractor import io.samagra.odk.collect.extension.interactors.FormsNetworkInteractor import io.samagra.odk.collect.extension.interactors.ODKInteractor import io.samagra.odk.collect.extension.listeners.FileDownloadListener -import io.samagra.odk.collect.extension.listeners.FormsProcessListener import io.samagra.odk.collect.extension.listeners.ODKProcessListener +import io.samagra.odk.collect.extension.utilities.ODKProvider import org.apache.commons.io.IOUtils +import org.odk.collect.android.events.FormEventBus +import org.odk.collect.android.events.FormStateEvent import org.odk.collect.android.injection.config.DaggerAppDependencyComponent -import org.odk.collect.forms.instances.InstancesRepository import timber.log.Timber import java.io.File @@ -43,10 +42,11 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { private lateinit var odkInteractor: ODKInteractor private lateinit var networkInteractor: FormsNetworkInteractor private lateinit var formsDatabaseInteractor: FormsDatabaseInteractor - private lateinit var instancesRepository: InstancesRepository private lateinit var context: Context + private val compositeDisposable = CompositeDisposable() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_odkfeature_tester) @@ -65,15 +65,16 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { openSavedInput = findViewById(R.id.open_saved_form_input) openSavedButton = findViewById(R.id.open_saved_form_button) - odkInteractor = DaggerODKInteractorComponent.factory().create(application).getODKInteractor() + ODKProvider.init(application) + odkInteractor = ODKProvider.getOdkInteractor() progressBar.visibility = View.VISIBLE odkInteractor.setupODK(IOUtils.toString(resources.openRawResource(R.raw.settings)), false, object : ODKProcessListener { override fun onProcessComplete() { val currentProjectProvider = DaggerAppDependencyComponent.builder().application(application).build().currentProjectProvider() currentProjectProvider.getCurrentProject().name - formsDatabaseInteractor = DaggerFormsDatabaseInteractorComponent.factory().create(application).getFormsDatabaseInteractor() - networkInteractor = DaggerFormsNetworkInteractorComponent.factory().create(application).getFormsNetworkInteractor() + formsDatabaseInteractor = ODKProvider.getFormsDatabaseInteractor() + networkInteractor = ODKProvider.getFormsNetworkInteractor() progressBar.visibility = View.INVISIBLE } override fun onProcessingError(exception: Exception) { @@ -89,6 +90,26 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { clearAllFormsButton.setOnClickListener(this) showAllForms.setOnClickListener(this) openSavedButton.setOnClickListener(this) + + setListeners() + } + + private fun setListeners() { + compositeDisposable.add( + FormEventBus.getState().subscribe { event -> + when (event) { + is FormStateEvent.OnFormDownloadFailed -> Timber.tag("FORM EVENT").d("Download for form %s failed. Reason: %s", event.formId, event.errorMessage) + is FormStateEvent.OnFormDownloaded -> Timber.tag("FORM EVENT").d("Form downloaded with id: %s", event.formId) + is FormStateEvent.OnFormOpenFailed -> Timber.tag("FORM EVENT").d("Form open failed for form %s. Reason: %s", event.formId, event.errorMessage) + is FormStateEvent.OnFormOpened -> Timber.tag("FORM EVENT").d("Form with id: %s was opened", event.formId) + is FormStateEvent.OnFormSaveError -> Timber.tag("FORM EVENT").d("Form with id: %s could not be saved. Reason: %s", event.formId, event.errorMessage) + is FormStateEvent.OnFormSaved -> Timber.tag("FORM EVENT").d("Form with id: %s was saved. Saved instance path: %s", event.formId, event.instancePath) + is FormStateEvent.OnFormUploadFailed -> Timber.tag("FORM EVENT").d("Form upload failed for form id: %s. Reason: %s", event.formId, event.errorMessage) + is FormStateEvent.OnFormUploaded -> Timber.tag("FORM EVENT").d("Form with id: %s was uploaded", event.formId) + } + progressBar.visibility = View.INVISIBLE + } + ) } override fun onClick(v: View?) { @@ -97,18 +118,7 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { val formId: String = openFormsInput.text.toString().trim() if (formId.isNotBlank()) { progressBar.visibility = View.VISIBLE - odkInteractor.openForm(formId, context, object : FormsProcessListener { - override fun onProcessed() { - progressBar.visibility = View.INVISIBLE - } - - override fun onProcessingError(e: Exception) { - progressBar.visibility = View.INVISIBLE - Timber.e(e) - showToast(e.message) - } - - }) + odkInteractor.openForm(formId, context) } } R.id.download_form_button -> { @@ -174,18 +184,7 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { val formId: String = openSavedInput.text.toString().trim() if (formId.isNotBlank()) { progressBar.visibility = View.VISIBLE - odkInteractor.openSavedForm(formId, context, object : FormsProcessListener { - override fun onProcessed() { - progressBar.visibility = View.INVISIBLE - } - - override fun onProcessingError(e: Exception) { - progressBar.visibility = View.INVISIBLE - Timber.e(e) - showToast(e.message) - } - - }) + odkInteractor.openSavedForm(formId, context) } } } @@ -195,4 +194,9 @@ class ODKFeatureTesterActivity : AppCompatActivity(), View.OnClickListener { if (text != null) Toast.makeText(context, text, Toast.LENGTH_LONG).show() } + + override fun onDestroy() { + super.onDestroy() + compositeDisposable.clear() + } } \ No newline at end of file