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
<?php | |
if (!isset($_GET['user'])) { | |
if (!isset($_GET['hashtag'])) { | |
exit('Not a valid RSS feed. You didn\'nt provide an Instagram user or hashtag. Send one via a GET variable. Example .../instarss.php?user=snoopdogg'); | |
} | |
} | |
if (isset($_GET['user']) && isset($_GET['hashtag'])) { | |
exit('Don\'t request both user and hashtag. Request one or the other.'); |
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"?> | |
<resources> | |
<!-- google's material design colours from | |
http://www.google.com/design/spec/style/color.html#color-ui-color-palette --> | |
<!--reds--> | |
<color name="md_red_50">#FFEBEE</color> | |
<color name="md_red_100">#FFCDD2</color> | |
<color name="md_red_200">#EF9A9A</color> |
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
package com.example.android.cookies; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { |
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
package com.example.android.menu; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { |
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
//couple the activity with the view model | |
viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class); | |
//subscribe to LiveData | |
viewModel.getRecipesListObservable().observe(MainActivity.this, new Observer<Resource<List<Recipe>>>() { | |
@Override | |
public void onChanged(@Nullable Resource<List<Recipe>> recipes) { | |
Timber.d(recipes.status.toString()); | |
} | |
}); | |
//ask the viewmodel for data (maybe an event happened?or onCreate?) |
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 void getData(){ | |
mRepository.fetchData(); | |
} |
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 void fetchData(){ | |
List<Recipe> loadingList = null; | |
if (recipesListObservable.getValue()!=null){ | |
loadingList=recipesListObservable.getValue().data; | |
} | |
recipesListObservable.setValue(Resource.loading(loadingList)); | |
loadAllRecipesFromDB(); | |
getRecipesFromWeb(); | |
} |
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
private void loadAllRecipesFromDB() { | |
Timber.d("loadAllRecipesFromDB"); | |
new AsyncTask<Void, Void, List<Recipe>>() { | |
@Override | |
protected List<Recipe> doInBackground(Void...a) { | |
return recipesDAO.getAllEntries(); | |
} | |
@Override | |
protected void onPostExecute(List<Recipe> results) { |
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
private void getRecipesFromWeb(){ | |
Timber.d("getRecipesFromWeb"); | |
recipeApi.getRecipesFromWeb().enqueue(new Callback<List<Recipe>>() { | |
@Override | |
public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) { | |
if (response.isSuccessful()) { | |
setRecipesListObservableStatus(Status.SUCCESS,null); | |
addRecipesToDB(response.body()); | |
} else { | |
// error case |
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
/* | |
* Copyright (C) 2017 The Android Open Source Project | |
*/ | |
//a generic wrapper class that describes a data with a status | |
public class Resource<T> { | |
@NonNull | |
public final Status status; | |
@Nullable | |
public final T data; | |
@Nullable public final String message; |
OlderNewer