Skip to content

Commit

Permalink
create recyclerview for viewing recipe, updating code w comments
Browse files Browse the repository at this point in the history
  • Loading branch information
savannah-nelson committed Dec 12, 2021
1 parent 2123f90 commit ee6bb97
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

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

22 changes: 18 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_view = 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 @@ -86,6 +91,15 @@ public void onClick(View view) {
}
});

//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
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/res/layout/recipe_rv_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:elevation="8dp"
app:cardCornerRadius="4dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:orientation="vertical">

<!--text view for our recipe name-->
<TextView
android:id="@+id/idTVRecipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="Recipe Name"
android:textColor="@color/black" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">

<!--text view for 1st ing-->
<TextView
android:id="@+id/idTVIng1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dp"
android:text="Ing1"
android:textColor="@color/black" />

<!--text view for 1st ing-->
<TextView
android:id="@+id/idTVIng2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dp"
android:text="Ing2"
android:textColor="@color/black" />

<!--text view for 1st ing-->
<TextView
android:id="@+id/idTVIng3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dp"
android:text="Ing3"
android:textColor="@color/black" />

</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

0 comments on commit ee6bb97

Please sign in to comment.