-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from SCCapstone/coydb
added "add/remove" functionality for on-hand ingredients. fixes #13
- Loading branch information
Showing
13 changed files
with
511 additions
and
122 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
app/src/main/java/edu/sc/purplelimited/ui/on_hand_ingredients/OnHandListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package edu.sc.purplelimited.ui.on_hand_ingredients; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.ArrayList; | ||
|
||
import edu.sc.purplelimited.R; | ||
import edu.sc.purplelimited.classes.Ingredient; | ||
|
||
public class OnHandListAdapter extends ArrayAdapter { | ||
ArrayList<Ingredient> onHandList; | ||
Context context; | ||
|
||
public OnHandListAdapter(@NonNull Context context, ArrayList<Ingredient> onHandList) { | ||
super(context, R.layout.on_hand_list_view, onHandList); | ||
this.context = context; | ||
this.onHandList = onHandList; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
if(convertView == null) { | ||
LayoutInflater inflater; | ||
inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); | ||
convertView = inflater.inflate(R.layout.on_hand_list_view, null ); | ||
|
||
// Text | ||
TextView ingredientString = convertView.findViewById(R.id.ingredient_name_in_listview); | ||
ingredientString.setText(onHandList.get(position).toString()); | ||
|
||
// Clickable | ||
ImageView increaseQuantity = convertView.findViewById(R.id.increase_quantity_list_view); | ||
ImageView decreaseQuantity = convertView.findViewById(R.id.decrease_quantity_list_view); | ||
ImageView removeItem = convertView.findViewById(R.id.remove); | ||
|
||
increaseQuantity.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String id = onHandList.get(position).getId(); | ||
int quantity = onHandList.get(position).getQuantity(); | ||
quantity++; | ||
OnHandIngredientsFragment.changeQuantity(quantity, id); | ||
} | ||
}); | ||
decreaseQuantity.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String id = onHandList.get(position).getId(); | ||
int quantity = onHandList.get(position).getQuantity(); | ||
if (quantity > 0) { | ||
quantity--; | ||
OnHandIngredientsFragment.changeQuantity(quantity, id); | ||
} else { | ||
// remove item from list if quantity goes below 0 | ||
OnHandIngredientsFragment.removeIngredient(id); | ||
} | ||
} | ||
}); | ||
removeItem.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String id = onHandList.get(position).getId(); | ||
OnHandIngredientsFragment.removeIngredient(id); | ||
} | ||
}); | ||
} | ||
return convertView; | ||
} | ||
} |
Oops, something went wrong.