Search in sources :

Example 1 with DatabaseHandler

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);
    }
}
Also used : DatabaseHandler(com.se491.chef_ly.Databases.DatabaseHandler) ArrayList(java.util.ArrayList) RefWatcher(com.squareup.leakcanary.RefWatcher) ShoppingListItem(com.se491.chef_ly.model.ShoppingListItem)

Example 2 with DatabaseHandler

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();
}
Also used : DatabaseHandler(com.se491.chef_ly.Databases.DatabaseHandler)

Example 3 with DatabaseHandler

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();
}
Also used : ImageButton(android.widget.ImageButton) Button(android.widget.Button) DatabaseHandler(com.se491.chef_ly.Databases.DatabaseHandler) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ExtendedIngredient(com.se491.chef_ly.model.ExtendedIngredient)

Example 4 with DatabaseHandler

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();
}
Also used : DatabaseHandler(com.se491.chef_ly.Databases.DatabaseHandler) BaseAdapter(android.widget.BaseAdapter)

Example 5 with DatabaseHandler

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();
}
Also used : EditText(android.widget.EditText) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) ShoppingListItem(com.se491.chef_ly.model.ShoppingListItem) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) DatabaseHandler(com.se491.chef_ly.Databases.DatabaseHandler) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView)

Aggregations

DatabaseHandler (com.se491.chef_ly.Databases.DatabaseHandler)5 ArrayList (java.util.ArrayList)3 View (android.view.View)2 Button (android.widget.Button)2 TextView (android.widget.TextView)2 ShoppingListItem (com.se491.chef_ly.model.ShoppingListItem)2 Intent (android.content.Intent)1 KeyEvent (android.view.KeyEvent)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 BaseAdapter (android.widget.BaseAdapter)1 EditText (android.widget.EditText)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RelativeLayout (android.widget.RelativeLayout)1 ScrollView (android.widget.ScrollView)1 ExtendedIngredient (com.se491.chef_ly.model.ExtendedIngredient)1 RefWatcher (com.squareup.leakcanary.RefWatcher)1