Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savbranch #19

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CMSC355CookBookApp">
<activity
android:name=".ViewRecipes"
android:exported="true" />
<activity
android:name=".recipes"
android:exported="true"/>
android:exported="true" />
<activity
android:name=".ShoppingPage"
android:exported="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class MainActivity extends AppCompatActivity {
Button ing_btn;
Button shopping_btn;
Button recipe_btn;
Button viewrecipe_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -21,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {

shopping_btn = (Button)findViewById(R.id.shopping_btn);
ing_btn = (Button)findViewById(R.id.ing_btn);
recipe_btn = (Button)findViewById(R.id.recipe_btn);
viewrecipe_btn = (Button)findViewById(R.id.recipe_btn);

shopping_btn.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -30,9 +30,10 @@ public void onClick(View v) {
}
});

recipe_btn.setOnClickListener(new View.OnClickListener() {
viewrecipe_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

openRecipes();
}
});
Expand All @@ -44,12 +45,6 @@ public void onClick(View v) {
}
});

recipe_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openRecipes();
}
});
}

public void openPantry() {
Expand All @@ -70,4 +65,6 @@ public void openShoppingPage() {
startActivity(intent);
}



}
40 changes: 37 additions & 3 deletions app/src/main/java/com/example/cmsc355cookbookapp/Pantry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.cmsc355cookbookapp;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
Expand All @@ -17,12 +18,47 @@

import androidx.appcompat.app.AppCompatActivity;

import com.example.cmsc355cookbookapp.CustomArrayAdapter.PantryListAdapter;
import java.util.ArrayList;

public final class PantryDB {
// To prevent someone from accidentally instantiating the contract class,
// make the constructor private.
private PantryDB() {}

/* Inner class that defines the table contents */
public static class Ingredient implements BaseColumns {
public static final String TABLE_NAME = "ingr";
public static final String COLUMN_NAME = "name";
}


private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + Ingredient.TABLE_NAME + " (" +
Ingredient._ID + " INTEGER PRIMARY KEY," +
Ingredient.COLUMN_NAME + " TEXT," +
Ingredient._COUNT + " TEXT";

private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + Ingredient.TABLE_NAME;
}

public class Pantry extends AppCompatActivity {
public static final String DATABASE_NAME = "MyPantry.db";

ListView listView;
ArrayList<String> items;
ArrayAdapter<String> adapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//@Override
protected void onCreate(Bundle savedInstanceState, SQLiteDatabase db){
super.onCreate(savedInstanceState);
setContentView(R.layout.pantry_layout);
db.execSQL(SQL_CREATE_ENTRIES);

public class Pantry extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
Button add_btn_ing;
EditText Item_Amount, input_name;
Expand All @@ -40,8 +76,6 @@ protected void onCreate(Bundle savedInstanceState) {
ingrediate_list = findViewById(R.id.ingrediate_list);


amount_type = findViewById(R.id.amount_type);

String[] Amount_types = getResources().getStringArray(R.array.amount_types);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.amount_types, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.example.cmsc355cookbookapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class RecipeRVAdapter extends RecyclerView.Adapter<RecipeRVAdapter.ViewHolder> {

// variable for our array list and context
private ArrayList<recipes_class> recipes_classArrayList;
private Context context;

// constructor
public RecipeRVAdapter(ArrayList<recipes_class> recipes_classArrayList, Context context) {
this.recipes_classArrayList = recipes_classArrayList;
this.context = context;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// on below line we are inflating our layout
// file for our recycler view items.
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recipe_rv_item, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// on below line we are setting data
// to our views of recycler view item.
recipes_class modal = recipes_classArrayList.get(position);
holder.recipeTV.setText(modal.getRecipe());
holder.ing1TV.setText(modal.getR_ing1());
holder.ing2TV.setText(modal.getR_ing2());
holder.ing3TV.setText(modal.getR_ing2());
}

@Override
public int getItemCount() {
// returning the size of our array list
return recipes_classArrayList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {

// creating variables for our text views.
private TextView recipeTV, ing1TV, ing2TV, ing3TV;

public ViewHolder(@NonNull View itemView) {
super(itemView);
// initializing our text views
recipeTV = itemView.findViewById(R.id.et_recipe);
ing1TV = itemView.findViewById(R.id.et_ing1);
ing2TV = itemView.findViewById(R.id.et_ing2);
ing3TV = itemView.findViewById(R.id.et_ing3);
}
}
}
46 changes: 46 additions & 0 deletions app/src/main/java/com/example/cmsc355cookbookapp/ViewRecipes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.cmsc355cookbookapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;

public class ViewRecipes extends AppCompatActivity {

private ArrayList<recipes_class> recipesArrayList;
private recipesDBHelper dbHelper;
private RecipeRVAdapter RecipeRVAdapter;
private RecyclerView recipesRV;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_recipes);

//initializing variables
recipesArrayList = new ArrayList<>();
dbHelper = new recipesDBHelper(ViewRecipes.this);

//getting recipe array list from dbhelper
recipesArrayList = dbHelper.showRecipes();

//passing our array lost to our adapter class.
RecipeRVAdapter = new RecipeRVAdapter(recipesArrayList, ViewRecipes.this);
recipesRV = findViewById(R.id.idRVCourses);

// setting layout manager for our recycler view.
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ViewRecipes.this, RecyclerView.VERTICAL, false);
recipesRV.setLayoutManager(linearLayoutManager);

// setting our adapter to recycler view.
recipesRV.setAdapter(RecipeRVAdapter);





}
}
23 changes: 19 additions & 4 deletions app/src/main/java/com/example/cmsc355cookbookapp/recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -16,7 +17,7 @@
public class recipes extends AppCompatActivity {

//references to buttons
Button btn_add, btn_viewall;
Button btn_add, btn_view, btn_viewRecipes;
EditText et_recipe, et_ing1, et_ing2, et_ing3, et_ing1_amt, et_ing2_amt, et_ing3_amt, et_ing1_amtType, et_ing2_amtType, et_ing3_amtType;
ListView lv_recipelist;
ArrayAdapter recipeArrayAdapter;
Expand All @@ -28,7 +29,9 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.recipes_layout);

btn_add = findViewById(R.id.btn_add);
btn_viewall = findViewById(R.id.btn_viewall);
btn_viewRecipes = findViewById(R.id.btn_view);

//initialize variables
et_recipe = findViewById(R.id.et_recipe);
et_ing1 = findViewById(R.id.et_ing1);
et_ing2 = findViewById(R.id.et_ing2);
Expand All @@ -41,11 +44,12 @@ protected void onCreate(Bundle savedInstanceState) {
et_ing3_amtType = findViewById(R.id.et_ing3_amtType);
lv_recipelist = findViewById(R.id.lv_recipelist);

//create dbhelper and pass context
viewDBhelper = new recipesDBHelper(recipes.this);

ShowRecipesOnListView(viewDBhelper);

// button listeners for the add and view all buttons
// button listeners for the add button
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -75,7 +79,8 @@ public void onClick(View view) {
}
});

btn_viewall.setOnClickListener(new View.OnClickListener() {
/*button listener for the view button
btn_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recipesDBHelper viewDBhelper = new recipesDBHelper(recipes.this);
Expand All @@ -85,6 +90,16 @@ public void onClick(View view) {
Toast.makeText(recipes.this, "Your Recipes are Amazing", Toast.LENGTH_SHORT).show();
}
});
*/

//new button listener for view button
btn_viewRecipes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(recipes.this, ViewRecipes.class);
startActivity(i);
}
});

lv_recipelist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Expand Down
Loading