use of com.se491.chef_ly.model.ExtendedIngredient in project chefly_android by chef-ly.
the class RecipeDetailActivity method setRecipeInfo.
private void setRecipeInfo() {
final Context c = getApplicationContext();
TextView author = (TextView) findViewById(R.id.recipeAuthor);
// TextView description = (TextView) findViewById(R.id.recipeDescription);
TextView serves = (TextView) findViewById(R.id.recipeServings);
TextView time = (TextView) findViewById(R.id.recipeTime);
String recipeName;
Step[] directions;
if (recipeDetail == null) {
recipeTitle.setText(R.string.recipeNotFound);
} else {
recipeName = recipeDetail.getTitle();
recipeTitle.setText(recipeName);
author.setText(recipeDetail.getCreditText());
int servings = recipeDetail.getServings();
Log.d(TAG, "Serves -> " + servings);
if (servings <= 0) {
serves.setText(R.string.unknown);
} else {
serves.setText(String.valueOf(servings));
}
int cookTime = recipeDetail.getReadyInMinutes();
int hour = 0;
while (cookTime >= 60) {
hour++;
cookTime = cookTime - 60;
}
String newTime;
if (hour < 2) {
newTime = (hour != 0) ? hour + " hr " : "";
} else {
newTime = (hour != 0) ? hour + " hrs " : "";
}
newTime += ((cookTime > 0) ? cookTime + " min" : "");
if (newTime.isEmpty()) {
time.setText(R.string.unknown);
} else {
time.setText(newTime);
}
new AsyncTask<RequestMethod, Integer, Long>() {
Bitmap image = null;
@Override
protected Long doInBackground(RequestMethod... params) {
try {
URL url = new URL(recipeDetail.getImage());
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
Log.d(TAG, "IOException on load image");
Log.d(TAG, e.getMessage());
}
return 1L;
}
@Override
protected void onPostExecute(Long aLong) {
if (image != null) {
imageView.setImageBitmap(image);
}
}
}.execute();
ingredients = recipeDetail.getExtendedIngredients();
if (recipeDetail.getAnalyzedInstructions().length > 0) {
directions = recipeDetail.getAnalyzedInstructions()[0].getSteps();
} else {
directions = new Step[] { new Step(recipeDetail.getInstructions()) };
}
// checkBoxes = new CheckBox[ingredients.length];
// int states[][] = {{android.R.attr.state_checked}, {}};
TableLayout table = (TableLayout) findViewById(R.id.ingredientGroup);
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin = 30;
int topMargin = 1;
int rightMargin = 30;
int bottomMargin = 1;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
int color1 = getColor(c, R.color.table_color1);
int color2 = getColor(c, R.color.table_color2);
int count = 0;
for (ExtendedIngredient s : ingredients) {
final TableRow row = new TableRow(c);
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
row.setPadding(10, 5, 10, 5);
TextView text = new TextView(c);
text.setText(s.getOriginalString());
text.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_small) / getResources().getDisplayMetrics().density));
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
text.setPadding(10, 5, 10, 5);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageView image = (ImageView) row.getChildAt(1);
String text = String.valueOf(((TextView) row.getChildAt(0)).getText());
if (row.getChildAt(1).getVisibility() == View.GONE) {
image.setVisibility(View.VISIBLE);
shoppingList.add(new ShoppingListItem(text, false));
Toast.makeText(c, text + " added to shopping list", Toast.LENGTH_SHORT).show();
} else {
image.setVisibility(View.GONE);
shoppingList.remove(new ShoppingListItem(text, false));
Toast.makeText(c, text + " removed from shopping list", Toast.LENGTH_SHORT).show();
}
}
});
row.addView(text);
ImageView check = new ImageView(c);
check.setImageResource(R.drawable.shoppinglist);
check.setLayoutParams(new TableRow.LayoutParams(60, 60, 0.1f));
if (shoppingList.contains(new ShoppingListItem(s.getOriginalString(), false))) {
check.setVisibility(View.VISIBLE);
} else {
check.setVisibility(View.GONE);
}
row.addView(check);
table.addView(row);
count++;
}
//
final TableLayout tableDirec = (TableLayout) findViewById(R.id.directionGroup);
tableDirec.setColumnShrinkable(0, true);
tableDirec.setVisibility(View.GONE);
directionsForCooking = new String[directions.length];
count = 1;
for (Step s : directions) {
String step = count + ") " + s.getStep();
TableRow row = new TableRow(c);
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
TextView text = new TextView(c);
text.setText(step);
text.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_small) / getResources().getDisplayMetrics().density));
text.setPadding(15, 1, 15, 1);
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
row.addView(text);
tableDirec.addView(row);
directionsForCooking[count - 1] = s.getStep();
count++;
}
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
final ImageButton dropdown = (ImageButton) findViewById(R.id.directionsDropdown);
final RotateAnimation rotatedown = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotatedown.setDuration(250);
rotatedown.setFillAfter(true);
final RotateAnimation rotateup = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateup.setDuration(250);
rotateup.setFillAfter(true);
dropdown.setOnClickListener(new View.OnClickListener() {
private boolean isClicked = false;
@Override
public void onClick(View v) {
if (!isClicked) {
tableDirec.setVisibility(View.VISIBLE);
dropdown.startAnimation(rotatedown);
isClicked = true;
sv.post(new Runnable() {
@Override
public void run() {
//sv.fullScroll(ScrollView.FOCUS_DOWN);
sv.smoothScrollBy(0, 500);
}
});
} else {
dropdown.startAnimation(rotateup);
tableDirec.setVisibility(View.GONE);
isClicked = false;
//sv.fullScroll(ScrollView.FOCUS_DOWN);
}
}
});
}
}
use of com.se491.chef_ly.model.ExtendedIngredient in project chefly_android by chef-ly.
the class RecipeDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_detail);
Button getCookingBtn;
//EditText editTextDesciption;
recipeTitle = (TextView) findViewById(R.id.recipeName);
imageView = (ImageView) findViewById(R.id.image);
//editTextDesciption = (EditText) findViewById(R.id.hidden_edit_view);
getCookingBtn = (Button) findViewById(R.id.getCookingBtn);
getCookingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cookingIntent = new Intent(RecipeDetailActivity.this, GetCookingActivity.class);
if (directionsForCooking != null) {
cookingIntent.putExtra("directions", directionsForCooking);
ArrayList<String> ingredList = new ArrayList<String>();
for (ExtendedIngredient ingre : ingredients) {
ingredList.add(ingre.getOriginalString());
}
cookingIntent.putExtra("ingredients", ingredList);
startActivity(cookingIntent);
finish();
} else {
Toast.makeText(RecipeDetailActivity.this, "Could not find recipe directions", Toast.LENGTH_SHORT).show();
}
}
});
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
shoppingList = db.getShoppingList();
}
Aggregations