This file contains hidden or 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
| class TextInput @JvmOverloads constructor(context: Context, attrSet: AttributeSet? = null, defStyleAttr: Int = 0) | |
| : FrameLayout(context, attrSet, defStyleAttr), FieldInput { | |
| override var key: String = "" | |
| private val textInput: TextInputEditText | |
| init { | |
| val view = inflate(context, R.layout.text_input, this) | |
| textInput = view.findViewById(R.id.editText) | |
This file contains hidden or 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
| interface FormSection { | |
| fun onUserSubmitSection() | |
| } |
This file contains hidden or 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
| class FormFragment : Fragment(), FormSection { | |
| private val section by lazy { arguments!!.getParcelable<Section>(SECTION) } | |
| private val fieldInputs = mutableListOf<FieldInput>() | |
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
| val view = inflater.inflate(R.layout.form_section_fragment, container, false) | |
| return view | |
| } |
This file contains hidden or 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
| interface SectionSubmittedListener { | |
| fun onSectionSubmittedWithValidAnswers(answers: List<Answer>) | |
| } |
This file contains hidden or 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
| class MainActivity : AppCompatActivity(), SectionSubmittedListener { | |
| private val viewPager by lazy { findViewById<ViewPager>(R.id.viewPager) } | |
| //Added code | |
| private val nextButton by lazy { findViewById<Button>(R.id.nextButton) } | |
| private val allAnswers = mutableListOf<Answer>() | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) |
This file contains hidden or 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
| interface WorkflowService { | |
| @POST("/my_endpoint_to_receive_data") | |
| fun submit(@Body data: FormBody): Single<MyResponse> | |
| } |
This file contains hidden or 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
| class WorkflowRepository(private val service: WorkflowService) { | |
| override fun submit(answers: List<Answer>): Single<MyResponse> { | |
| val formBody = FormBody.Builder() | |
| answers.forEach { | |
| formBody.add(it.key, it.value) | |
| } | |
| return service.submit(formBody.build()) | |
| } | |
| } |
This file contains hidden or 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
| { | |
| "sections": [ | |
| { | |
| "title": "What's your name", | |
| "type": "form", | |
| "fields": [ | |
| { | |
| "type": "text", | |
| "key": "first_name", | |
| "hint": "Type your first name" |
This file contains hidden or 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
| sealed class ResultWrapper<out T> { | |
| data class Success<out T>(val value: T): ResultWrapper<T>() | |
| data class GenericError(val code: Int? = null, val error: ErrorResponse? = null): ResultWrapper<Nothing>() | |
| object NetworkError: ResultWrapper<Nothing>() | |
| } |
This file contains hidden or 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
| suspend fun <T> safeApiCall(dispatcher: CoroutineDispatcher, apiCall: suspend () -> T): ResultWrapper<T> { | |
| return withContext(dispatcher) { | |
| try { | |
| ResultWrapper.Success(apiCall.invoke()) | |
| } catch (throwable: Throwable) { | |
| when (throwable) { | |
| is IOException -> ResultWrapper.NetworkError | |
| is HttpException -> { | |
| val code = throwable.code() | |
| val errorResponse = convertErrorBody(throwable) |