As a developer, I want to reduce the quantity of code duplicated in the application
Requirements
Implement an TextBasedViewModel extending QuestionViewModel, that:
requires:
everything that QuestionViewModel constructor requires
only Question with options property should be allowed
provide:
boolean useKeyboard indicating if the view should display an input text field or the option cards
String inputValue indicate the current input value (use only if useKeyboard is true)
bool isSubmitEnabled indicating if the submit button is enabled or not.
void onInputValueChange(String value) callback when input value change
List<int> selectedOptionsIndexes containing the indexes in order of the selected text options
void onTextOptionPressed(int index): handle when a text option is pressed
Future<void> readSubject(): read the subject if available
implement
onSubmitPressed: validate the submitted answer and display the appropriate result flow
What needs to be done
Implement under practice/questions, a view model TextBasedViewModel:
constructor:
require:
everything QuestionViewModel needs
instead of a Question, requires a TextQuestion
useKeyboard should:
be true if:
instruction type is spell_romaji or translate_to_app_language
the Japanese keyboard is available (needs investigation, we will probably need to develop our own plugin for that) AND the instruction type is spell_kana, spell or translate_to_japanese
bool isSubmitEnabled: true if inputValue or selectedOptionsIndexes are not empty
List<int> selectedOptionsIndexes should be initialized with an empty array
implement:
void onTextOptionPressed(int index) method that:
update the selectedOptionsIndexes content (add or remove the index) (use only if useKeyboard is false)
read the content of the options using the TTS service
onInputValueChange(String value) method that update inputValue when called
Future<void> readSubject() should use the TTS service to read question.subject_tts if available
onSubmitPressed should:
determine the answer to use: either inputValue or selectedOptionsIndexes based on useKeyboard
validate if the answer is present in accepted_answers
As a developer, I want to reduce the quantity of code duplicated in the application
Requirements
Implement an
TextBasedViewModel
extendingQuestionViewModel
, that:QuestionViewModel
constructor requiresQuestion
withoptions
property should be allowedboolean useKeyboard
indicating if the view should display an input text field or the option cardsString inputValue
indicate the current input value (use only ifuseKeyboard
is true)bool isSubmitEnabled
indicating if the submit button is enabled or not.void onInputValueChange(String value)
callback when input value changeList<int> selectedOptionsIndexes
containing the indexes in order of the selected text optionsvoid onTextOptionPressed(int index)
: handle when a text option is pressedFuture<void> readSubject()
: read the subject if availableonSubmitPressed
: validate the submitted answer and display the appropriate result flowWhat needs to be done
Implement under
practice/questions
, a view modelTextBasedViewModel
:QuestionViewModel
needsQuestion
, requires aTextQuestion
useKeyboard
should:spell_romaji
ortranslate_to_app_language
spell_kana
,spell
ortranslate_to_japanese
bool isSubmitEnabled
: true ifinputValue
orselectedOptionsIndexes
are not emptyList<int> selectedOptionsIndexes
should be initialized with an empty arrayvoid onTextOptionPressed(int index)
method that:selectedOptionsIndexes
content (add or remove the index) (use only ifuseKeyboard
is false)onInputValueChange(String value)
method that updateinputValue
when calledFuture<void> readSubject()
should use the TTS service to readquestion.subject_tts
if availableonSubmitPressed
should:inputValue
orselectedOptionsIndexes
based onuseKeyboard
accepted_answers
_onSuccess
_onError
Dependencies
Child of #160
Depends on:
171