forked from getodk/collect
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ODKEventExporter and FormEventExporter.
Supported events: - OnFormOpened - OnFormOpenFailed - OnFormSaved - OnFormSaveError - OnFormUploaded - OnFormUploadFailed - OnFormDownloaded - OnFormDownloadFailed
- Loading branch information
1 parent
476e06e
commit 268c6e7
Showing
13 changed files
with
163 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventExporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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 FormEventExporter: ODKEventExporter<FormStateEvent>() { | ||
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() | ||
|
||
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() | ||
} |
17 changes: 17 additions & 0 deletions
17
odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventExporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ODKEventExporter<T : Any> { | ||
|
||
protected val state: PublishSubject<T> = PublishSubject.create() | ||
|
||
fun getObservable(): Observable<T> { | ||
return state.hide() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.