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
ebbd63d
commit 76e61aa
Showing
14 changed files
with
166 additions
and
54 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
67 changes: 67 additions & 0 deletions
67
odk/collect/collect_app/src/main/java/org/odk/collect/android/events/FormEventBus.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,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<FormStateEvent>() { | ||
//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() | ||
} |
17 changes: 17 additions & 0 deletions
17
odk/collect/collect_app/src/main/java/org/odk/collect/android/events/ODKEventBus.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 ODKEventBus<T : Any> { | ||
|
||
protected val state: PublishSubject<T> = PublishSubject.create() | ||
|
||
fun getState(): 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
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.