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 User { | |
@PrimaryKey | |
private int uId; | |
private String uName; | |
private ArrayList<String> uPets = new ArrayList<>(); | |
public User() {} | |
public User(int id, String name, List<String> pets){ |
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 cacheOnDB(List<Quote> quote); | |
@Query("SELECT * FROM quote") | |
LiveData<List<Quote>>getCachedQuotes(); | |
//for saved quotes (starred quotes) |
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
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<android.support.v4.widget.SwipeRefreshLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/swipe_to_refresh" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> |
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; //data model | |
private SwipeRefreshLayout swipeRefreshLayout; //swipe to refresh data | |
private RecyclerView recyclerView; | |
private AdapterQuotes adapterQuotes; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
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 xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="10dp"> | |
<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 AdapterQuotes extends RecyclerView.Adapter<AdapterQuotes.MyViewHolder>{ | |
private LayoutInflater inflater; | |
private List<Quote> quoteItems; | |
private Context context; | |
//private Typeface type; | |
public AdapterQuotes(Context context){ | |
this.quoteItems=new ArrayList<>(); | |
inflater= LayoutInflater.from(context); | |
this.context = context; |
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(autoGenerate = true) | |
private int id=0; | |
private String quote; | |
private String author; | |
private String category; | |
public String 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
public interface QuoteAPI { | |
//I insist you put your own key here fellas | |
@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
class QuoteRepository { | |
private QuoteAPI quoteAPI; | |
private QuoteDAO quoteDAO; | |
private Executor executor; | |
QuoteRepository(){ | |
this.executor = Executors.newSingleThreadExecutor(); | |
MyQuoteDB db = Room.databaseBuilder(context, | |
MyQuoteDB.class, "database-name").build(); | |
quoteDAO=db.quoteDAO(); |
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
@Database(entities = {Quote.class}, version = 1) | |
public abstract class MyQuoteDB extends RoomDatabase { | |
public abstract QuoteDAO quoteDAO(); | |
} |
NewerOlder