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
class QuestionsViewModel : ViewModel() { | |
private val repository: QuestionsRepository = QuestionsRepositoryImp() | |
private var questions = MutableLiveData<List<Question>>() | |
private var answeredState: MutableLiveData<AnsweredState> = | |
MutableLiveData(AnsweredState.Answering) | |
var currentQuestionIndex = 0 |
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
var questionList: List<Question>? = null | |
private fun observeQuestions() { | |
questionsViewModel.getQuestions().observe(viewLifecycleOwner, Observer { | |
//this code runs every time the data changes. | |
questionList = it | |
getNextQuestion() | |
}) | |
} | |
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
class QuestionsFragment : Fragment() { | |
val questionsViewModel: QuestionsViewModel by viewModels() | |
lateinit var currentQuestion : Question | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { |
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
private fun observeAnsweredState() { | |
questionsViewModel.getAnsweredState().observe(viewLifecycleOwner, Observer { | |
Log.d("Elijah", "Answered State: " + it.name) | |
when(it){ | |
AnsweredState.Answered -> showAnswered() | |
AnsweredState.Answering -> showAnswering() | |
} | |
}) | |
} |
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
class QuestionsFragment : Fragment() { | |
val questionsViewModel: QuestionsViewModel by viewModels() | |
lateinit var currentQuestion : Question | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { |
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
class QuestionsViewModel : ViewModel() { | |
private val repository: QuestionsRepository = QuestionsRepositoryImp() | |
private var questions = MutableLiveData<List<Question>>() | |
private var answeredState: MutableLiveData<AnsweredState> = | |
MutableLiveData(AnsweredState.Answering) | |
fun getAnsweredState(): MutableLiveData<AnsweredState> { | |
return answeredState |
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
enum class AnsweredState { | |
Answered, Answering | |
} |
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
class QuestionsFragment : Fragment() { | |
val questionsViewModel: QuestionsViewModel by viewModels() | |
lateinit var currentQuestion : Question | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { |
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
private fun getCurrentAnswer(id: Int): String? { | |
return when (id) { | |
option_1.id -> option_1.text.toString() | |
option_2.id -> option_2.text.toString() | |
option_3.id -> option_3.text.toString() | |
option_4.id -> option_4.text.toString() | |
else -> null | |
} | |
} |
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
class QuestionsFragment : Fragment() { | |
val questionsViewModel: QuestionsViewModel by viewModels() | |
lateinit var currentQuestion : Question | |
var currentAnswer : String? = null | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? |
NewerOlder