use of com.se491.chef_ly.Databases.DatabaseHandler in project chefly_android by chef-ly.
the class RecipeDetailActivity method onDestroy.
@Override
protected void onDestroy() {
super.onDestroy();
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
// Remove an item from shopping list if removed by clicking on ingredient
ArrayList<ShoppingListItem> existing = db.getShoppingList();
ArrayList<ShoppingListItem> toDelete = new ArrayList<>();
for (ShoppingListItem item : existing) {
if (!shoppingList.contains(item)) {
toDelete.add(item);
}
}
db.deleteItemFromShoppingList(toDelete);
// Add new items to shopping list
for (ShoppingListItem item : shoppingList) {
if (item.getId() == -9999) {
db.addItemToShoppingList(item.getName(), item.isPurchased());
}
}
if (BuildConfig.DEBUG) {
RefWatcher refWatcher = CheflyApplication.getRefWatcher(this);
refWatcher.watch(this);
}
}
use of com.se491.chef_ly.Databases.DatabaseHandler in project chefly_android by chef-ly.
the class RecipeDetailActivity method onPostResume.
@Override
protected void onPostResume() {
super.onPostResume();
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
shoppingList = db.getShoppingList();
}
use of com.se491.chef_ly.Databases.DatabaseHandler 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();
}
use of com.se491.chef_ly.Databases.DatabaseHandler in project chefly_android by chef-ly.
the class ShoppingListActivity method addText.
private void addText(String text) {
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
db.addItemToShoppingList(text, false);
shoppingList = db.getShoppingList();
((BaseAdapter) getListAdapter()).notifyDataSetChanged();
}
use of com.se491.chef_ly.Databases.DatabaseHandler in project chefly_android by chef-ly.
the class ShoppingListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopping_list);
setListAdapter(new myAdapter(this.getApplicationContext()));
final DatabaseHandler handler = new DatabaseHandler(this.getApplicationContext());
Button deletePurchasedBtn;
deletePurchasedBtn = (Button) findViewById(R.id.clearPurchasedBtn);
deletePurchasedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<ShoppingListItem> toDelete = new ArrayList<>();
for (ShoppingListItem item : shoppingList) {
if (item.isPurchased()) {
toDelete.add(item);
}
}
if (toDelete.size() > 0) {
for (ShoppingListItem item : toDelete) {
shoppingList.remove(item);
}
DatabaseHandler h = new DatabaseHandler(getApplicationContext());
h.deleteItemFromShoppingList(toDelete);
((BaseAdapter) getListAdapter()).notifyDataSetChanged();
}
}
});
final Button add = (Button) findViewById(R.id.addBtn);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText newItem = new EditText(getApplicationContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 150);
params.addRule(RelativeLayout.BELOW, add.getId());
params.setMargins(20, 2, 20, 2);
newItem.setLayoutParams(params);
newItem.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
newItem.setHint("new grocery list item");
newItem.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.color.white));
newItem.setInputType(InputType.TYPE_CLASS_TEXT);
newItem.setImeOptions(EditorInfo.IME_ACTION_DONE);
newItem.setMaxLines(1);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.activity_shopping_list);
layout.addView(newItem);
newItem.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
String text = newItem.getText().toString();
if (!hasFocus && text.length() > 0) {
addText(text);
newItem.setText("");
newItem.setVisibility(View.GONE);
}
}
});
newItem.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
String text = newItem.getText().toString();
if (!text.isEmpty()) {
addText(text);
newItem.setText("");
}
newItem.setVisibility(View.GONE);
return true;
}
return false;
}
});
}
});
shoppingList = handler.getShoppingList();
}
Aggregations