Created
April 14, 2019 13:48
-
-
Save amit-bhandari/2f36d9fa173d7fcaf8c6390e8ab686c1 to your computer and use it in GitHub Desktop.
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
public class QuoteViewModel extends ViewModel { | |
private LiveData<Quote> quote; //pojo object | |
private String category; //quote category | |
private int count; //number of quotes | |
private QuoteRepository quoteRepository; //data fetching object | |
public void init(String category, int count){ | |
//make sure quote object should be created only once | |
if(this.quote!=null){ | |
return ; | |
} | |
this.category = category; | |
this.count=count; | |
quoteRepository=new QuoteRepository(); | |
quote = quoteRepository.getQuote(category, count); | |
} | |
public LiveData<Quote> getQuote(){ | |
return quote; | |
} | |
//will be used when user manually wants to load new quote | |
public void refreshData(){ | |
quote = quoteRepository.getQuote(category, count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment