Skip to content

Commit

Permalink
fixed reading keys from xml
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejgaciarz committed Jul 18, 2018
1 parent bbb58f3 commit b326aee
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@
* Created by mgaciarz on 2018-04-26.
*/

public class JSONDownloader extends AsyncTask<String, Void, String> {
public class JSONDownloader extends AsyncTask<String, Void, String> {


Context context;
public JSONDownloader(Context context){
this.context= context;
}
private Context context;
private String api_key;
private String app_id;

private final String api_key = context.getResources().getString(R.string.api_key);
private final String app_id = context.getResources().getString(R.string.app_id);
private final String searchRequestURL = "https://api.edamam.com/search?q=";


protected String doInBackground(String... params) {
JSONDownloader(Context context) {
this.context = context;
this.api_key = context.getResources().getString(R.string.api_key);
this.app_id = context.getResources().getString(R.string.app_id);
}



protected String doInBackground(String... params) {


String liveUpdateUrl = searchRequestURL + params[0] + "&app_id=" + app_id + "&app_key=" + api_key;
HttpsURLConnection con;
InputStream in = null;
String result="";
String result = "";
try {
JSONObject jObj = null;

Expand Down Expand Up @@ -75,18 +79,16 @@ protected String doInBackground(String... params) {
e.printStackTrace();
return new String("error");
}
return result;
return result;

}

protected void onPostExecute(String result) {

Intent i = new Intent(context,ResultActivity.class);
Intent i = new Intent(context, ResultActivity.class);
i.putExtra("searchValues", result);
context.startActivity(i);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
public class JSONObjectWrapper {

//function that strips " sign from beginning and end of string
private String stripQuotes(String toStrip){
private String stripQuotes(String toStrip) {
return toStrip.replaceAll("^\"|\"$", "");
}

public List<Recipe> getRecipes(String JSON){
public List<Recipe> getRecipes(String JSON) {

ArrayList<Recipe> recipes = new ArrayList<>();

Expand Down Expand Up @@ -50,7 +50,7 @@ public List<Recipe> getRecipes(String JSON){
}


} catch (JsonParseException e){
} catch (JsonParseException e) {
e.printStackTrace();
}

Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/com/example/mgaciarz/myrecipes/ListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class ListAdapter extends BaseAdapter {

private Activity activity;
private static LayoutInflater inflater=null;
private static LayoutInflater inflater = null;
private List<Recipe> recipes;

@Override
Expand All @@ -36,25 +36,26 @@ public Object getItem(int position) {
@Override
public long getItemId(int position) {

return recipes.get(position).getId();
}
return recipes.get(position).getId();
}

public ListAdapter(Activity activity, List<Recipe> recipes) {
this.activity = activity;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.recipes = recipes;
}

@Override
public View getView(int position, View convertView, ViewGroup parent){
public View getView(int position, View convertView, ViewGroup parent) {

View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, parent,false);
//vi = inflater.inflate(R.layout.list_row, null);
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.list_row, parent, false);
//vi = inflater.inflate(R.layout.list_row, null);

TextView dishName = (TextView)vi.findViewById(R.id.dishName);
TextView dishDesc = (TextView)vi.findViewById(R.id.dishDescription);
ImageView dishImage =(ImageView) vi.findViewById(R.id.dishImage);
TextView dishName = (TextView) vi.findViewById(R.id.dishName);
TextView dishDesc = (TextView) vi.findViewById(R.id.dishDescription);
ImageView dishImage = (ImageView) vi.findViewById(R.id.dishImage);

Recipe recipe = recipes.get(position);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ protected void onCreate(Bundle savedInstanceState) {
foodText = findViewById(R.id.FoodText);


foodText.setFilters(new InputFilter[] {
foodText.setFilters(new InputFilter[]{
new InputFilter() {
public CharSequence filter(CharSequence src, int start,
int end, Spanned dst, int dstart, int dend) {
if(src.equals("")){ // for backspace
if (src.equals("")) { // for backspace
return src;
}
if(src.toString().matches("[a-zA-Z ]+")){
if (src.toString().matches("[a-zA-Z ]+")) {
return src;
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ protected void onCreate(Bundle savedInstanceState) {
Picasso.get().load(recipe.getImageURL()).into(dishImage);
dishDesc.setText(recipe.getInstructionURL());

}
else{
} else {
//todo: throw some error that extras are empty
}


}



}

0 comments on commit b326aee

Please sign in to comment.