Class QuizViewModel
- java.lang.Object
-
- androidx.lifecycle.ViewModel
-
- androidx.lifecycle.AndroidViewModel
-
- edu.cnm.deepdive.interviewprep.viewmodel.QuizViewModel
-
- All Implemented Interfaces:
DefaultLifecycleObserver
,LifecycleObserver
public class QuizViewModel extends AndroidViewModel implements DefaultLifecycleObserver
Implements the business logic behind the application. Interacts with the QuizRepository to perform CRUD operations on the server.
-
-
Constructor Summary
Constructors Constructor Description QuizViewModel(Application application)
Class constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LiveData<Question>
getQuestion()
Returns the local question variable.LiveData<List<Question>>
getQuestions()
Returns the local questions variable.void
onStop(LifecycleOwner owner)
void
refreshQuestion()
gets a list of all questions from the question repository.-
Methods inherited from class androidx.lifecycle.AndroidViewModel
getApplication
-
-
-
-
Constructor Detail
-
QuizViewModel
public QuizViewModel(@NonNull Application application)
Class constructor. Instantiates local class variables. Additionally, gets a question from the server.- Parameters:
application
- an application.
-
-
Method Detail
-
refreshQuestion
public void refreshQuestion()
gets a list of all questions from the question repository. Additionally, subscribes to the result and puts the result in the local variable questions.
-
onStop
public void onStop(@NonNull LifecycleOwner owner)
- Specified by:
onStop
in interfaceDefaultLifecycleObserver
-
-