-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #156 & #157: Continue/End Exploration player buttons- low-fi #222
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a2cf14
Basic implementation of buttons
abea751
Nit Changes
27cb582
Fully functional
3422b19
Added TODO 163
b7eee27
Nit Changes
5543997
Added test cases
afed9a0
Test cases nit changes
fc64aa4
Configuration change test case aded
55f9b1f
Nit changes
d5f78ce
Combining all buttons to one.
30857e0
Button functionality updated
55c6f8e
Updated test cases
d40b134
Nit changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
100 changes: 99 additions & 1 deletion
100
app/src/main/java/org/oppia/app/player/state/StateViewModel.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 |
---|---|---|
@@ -1,16 +1,114 @@ | ||
package org.oppia.app.player.state | ||
|
||
import android.content.Context | ||
import android.widget.Button | ||
import androidx.databinding.BindingAdapter | ||
import androidx.databinding.ObservableField | ||
import androidx.lifecycle.ViewModel | ||
import org.oppia.app.fragment.FragmentScope | ||
import javax.inject.Inject | ||
import org.oppia.app.R | ||
import org.oppia.app.viewmodel.ObservableViewModel | ||
|
||
private const val CONTINUE = "Continue" | ||
private const val END_EXPLORATION = "EndExploration" | ||
private const val LEARN_AGAIN = "LearnAgain" | ||
private const val MULTIPLE_CHOICE_INPUT = "MultipleChoiceInput" | ||
private const val ITEM_SELECT_INPUT = "ItemSelectionInput" | ||
private const val TEXT_INPUT = "TextInput" | ||
private const val FRACTION_INPUT = "FractionInput" | ||
private const val NUMERIC_INPUT = "NumericInput" | ||
private const val NUMERIC_WITH_UNITS = "NumberWithUnits" | ||
|
||
/** [ViewModel] for state-fragment. */ | ||
@FragmentScope | ||
class StateViewModel @Inject constructor() : ViewModel() { | ||
class StateViewModel @Inject constructor(val context: Context) : ObservableViewModel() { | ||
companion object { | ||
@JvmStatic | ||
@BindingAdapter("buttonDrawable") | ||
fun setBackgroundResource(button: Button, resource: Int) { | ||
button.setBackgroundResource(resource) | ||
} | ||
} | ||
|
||
var isAudioFragmentVisible = ObservableField<Boolean>(false) | ||
|
||
var isNextButtonVisible = ObservableField<Boolean>(false) | ||
var isPreviousButtonVisible = ObservableField<Boolean>(false) | ||
|
||
var observableInteractionId = ObservableField<String>() | ||
var isInteractionButtonActive = ObservableField<Boolean>(false) | ||
var isInteractionButtonVisible = ObservableField<Boolean>(false) | ||
var drawableResourceValue = ObservableField<Int>(R.drawable.state_button_primary_background) | ||
|
||
var name = ObservableField<String>() | ||
|
||
fun setObservableInteractionId(interactionId: String) { | ||
setNextButtonVisible(false) | ||
observableInteractionId.set(interactionId) | ||
when (interactionId) { | ||
CONTINUE -> { | ||
isInteractionButtonActive.set(true) | ||
isInteractionButtonVisible.set(true) | ||
name.set(context.getString(R.string.state_continue_button)) | ||
drawableResourceValue.set(R.drawable.state_button_primary_background) | ||
} | ||
END_EXPLORATION -> { | ||
isInteractionButtonActive.set(true) | ||
isInteractionButtonVisible.set(true) | ||
name.set(context.getString(R.string.state_end_exploration_button)) | ||
drawableResourceValue.set(R.drawable.state_button_primary_background) | ||
} | ||
LEARN_AGAIN -> { | ||
isInteractionButtonActive.set(true) | ||
isInteractionButtonVisible.set(true) | ||
name.set(context.getString(R.string.state_learn_again_button)) | ||
drawableResourceValue.set(R.drawable.state_button_blue_background) | ||
} | ||
ITEM_SELECT_INPUT, MULTIPLE_CHOICE_INPUT -> { | ||
isInteractionButtonActive.set(true) | ||
isInteractionButtonVisible.set(false) | ||
name.set(context.getString(R.string.state_submit_button)) | ||
drawableResourceValue.set(R.drawable.state_button_primary_background) | ||
} | ||
FRACTION_INPUT, NUMERIC_INPUT, NUMERIC_WITH_UNITS, TEXT_INPUT -> { | ||
isInteractionButtonActive.set(false) | ||
isInteractionButtonVisible.set(true) | ||
name.set(context.getString(R.string.state_submit_button)) | ||
drawableResourceValue.set(R.drawable.state_button_transparent_background) | ||
} | ||
} | ||
} | ||
|
||
fun clearObservableInteractionId() { | ||
observableInteractionId.set("") | ||
isInteractionButtonVisible.set(false) | ||
isInteractionButtonActive.set(false) | ||
} | ||
|
||
fun setAudioFragmentVisible(isVisible: Boolean) { | ||
isAudioFragmentVisible.set(isVisible) | ||
} | ||
|
||
fun setNextButtonVisible(isVisible: Boolean) { | ||
isNextButtonVisible.set(isVisible) | ||
} | ||
|
||
fun setPreviousButtonVisible(isVisible: Boolean) { | ||
isPreviousButtonVisible.set(isVisible) | ||
} | ||
|
||
fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { | ||
if (s.isNotEmpty()) { | ||
isInteractionButtonActive.set(true) | ||
drawableResourceValue.set(R.drawable.state_button_primary_background) | ||
} else { | ||
isInteractionButtonActive.set(false) | ||
drawableResourceValue.set(R.drawable.state_button_transparent_background) | ||
} | ||
} | ||
|
||
fun optionSelected(isOptionSelected: Boolean) { | ||
isInteractionButtonVisible.set(isOptionSelected) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? From the mocks it seems like some interactions submit upon selecting an answer (e.g. multiple choice), and others the 'submit' button changes to 'continue' once the answer is submitted. Either way, submitting the answer and progressing to the next card always seem to be distinct user actions (except for continue since there is no explicit answer submission).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check revised implementation TODO comment.
I have created one method
onOptionSelected(isOptionSelected: Boolean)
, which will control the visibility of the submit-button.But for now I have kept this
true
because, currently we don't have functionality ofMultipleChoiceInput
andItemSelectionInput
.