Skip to content

Instantly share code, notes, and snippets.

View amit-bhandari's full-sized avatar
💻
Writing code, duhhh

Amit Bhandari amit-bhandari

💻
Writing code, duhhh
View GitHub Profile
@Dao
public interface QuoteDAO {
@Insert(onConflict = REPLACE)
void save(Quote quote);
@Update
void update(Quote quote);
@Query("SELECT * FROM quote")
LiveData<Quote> getQuote();
@Entity
public class Quote{
@PrimaryKey
private int id=0;
private String quote;
private String author;
private String category;
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<>();
public class Quote{
private String quote;
private String author;
private String category;
public String getQuote() {
return quote;
}
{
"quote": "Oh, no, it wasn’t the airplanes. It was Beauty killed the Beast.",
"author": "King Kong",
"category": "Movies"
}
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);
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’
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();
<?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"
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);