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
@Dao | |
public interface QuoteDAO { | |
@Insert(onConflict = REPLACE) | |
void save(Quote quote); | |
@Update | |
void update(Quote quote); | |
@Query("SELECT * FROM quote") | |
LiveData<Quote> getQuote(); |
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
@Entity | |
public class Quote{ | |
@PrimaryKey | |
private int id=0; | |
private String quote; | |
private String author; | |
private String category; |
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 QuoteRepository { | |
private QuoteAPI quoteAPI; | |
QuoteRepository(){} | |
// … | |
LiveData<Quote> getQuote(String category, int count) { | |
//live data with setValue method exposed | |
final MutableLiveData<Quote> data = new MutableLiveData<>(); |
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 Quote{ | |
private String quote; | |
private String author; | |
private String category; | |
public String getQuote() { | |
return quote; | |
} |
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
{ | |
"quote": "Oh, no, it wasn’t the airplanes. It was Beauty killed the Beast.", | |
"author": "King Kong", | |
"category": "Movies" | |
} |
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 interface QuoteAPI { | |
@Headers({ | |
"X-Mashape-Key:your_api_key", | |
"Content-Type: application/x-www-form-urlencoded", | |
"Accept: application/json" | |
}) | |
@GET("/") | |
Call<Quote> getQuote(@Query("cat") String category, @Query("count") int count); |
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
compile ‘com.google.code.gson:gson:2.8.0’ | |
compile ‘com.squareup.retrofit2:retrofit:2.1.0’ | |
compile ‘com.squareup.retrofit2:converter-gson:2.1.0’ | |
compile ‘com.squareup.okhttp3:logging-interceptor:3.3.1’ |
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
Connection connection = Jsoup.connect(queryURL.toExternalForm()) | |
.header(headers_if_any) | |
.timeout(0) | |
.ignoreContentType(true); | |
Document document = connection.userAgent(Net.USER_AGENT).get(); | |
response = new JsonParser().parse(document.text()).getAsJsonObject(); |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
android:layout_gravity="center" | |
android:gravity="center" | |
android:orientation="vertical" android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/quote" |
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 FragmentQuote extends LifecycleFragment{ | |
private QuoteViewModel quoteViewModel; | |
private TextView quotetv; | |
private TextView authortv; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_quote,container,false); | |
quotetv = (TextView) view.findViewById(R.id.quote); |