-
Notifications
You must be signed in to change notification settings - Fork 5
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 #75 from uOttawaSEGA2022/pendingOrders
Pending orders
- Loading branch information
Showing
13 changed files
with
440 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/example/mealer_project/ui/screens/PendingOrdersAdapter.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,76 @@ | ||
package com.example.mealer_project.ui.screens; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.example.mealer_project.R; | ||
import com.example.mealer_project.data.models.Order; | ||
import com.example.mealer_project.data.models.orders.MealInfo; | ||
|
||
import java.util.List; | ||
|
||
public class PendingOrdersAdapter extends ArrayAdapter<Order> { | ||
|
||
/** | ||
* Constructor | ||
* @param context The current context. | ||
* @param resource The resource ID for a layout file containing a TextView to use when instantiating views. | ||
* @param objects The objects to represent in the ListView. | ||
*/ | ||
public PendingOrdersAdapter(@NonNull Context context, int resource, @NonNull List<Order> objects) { | ||
super(context, resource, objects); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
|
||
// Variable Declaration: getting order data item for given position | ||
Order order = getItem(position); | ||
String mealNames = ""; | ||
String quantities = ""; | ||
|
||
// Process: checking if existing view is being reused | ||
if (convertView == null) { //must inflate view | ||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_pending_orders_list_item, parent, false); | ||
} | ||
|
||
// Process: traversing entire meals map | ||
for (MealInfo mI : order.getMeals().values()) { | ||
|
||
mealNames += mI.getName() + "\n"; | ||
quantities += mI.getQuantity() + "\n"; | ||
|
||
} | ||
|
||
// Process: setting the order info to appear on the screen | ||
((TextView) convertView.findViewById(R.id.clientNameText)).setText(order.getClientInfo().getClientName()); | ||
((TextView) convertView.findViewById(R.id.mealNameText)).setText(mealNames); | ||
((TextView) convertView.findViewById(R.id.quantityText)).setText(quantities); | ||
((TextView) convertView.findViewById(R.id.dateText)).setText(order.getOrderDate().toString()); | ||
((Button) convertView.findViewById(R.id.rejectButton)).setOnClickListener(new View.OnClickListener(){ | ||
@Override | ||
public void onClick(View v) { | ||
//do something | ||
|
||
} | ||
}); | ||
((Button) convertView.findViewById(R.id.acceptButton)).setOnClickListener(new View.OnClickListener(){ | ||
@Override | ||
public void onClick(View v) { | ||
//do something | ||
|
||
} | ||
}); | ||
|
||
return convertView; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
app/src/main/java/com/example/mealer_project/ui/screens/PendingOrdersScreen.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,104 @@ | ||
package com.example.mealer_project.ui.screens; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.widget.ImageButton; | ||
import android.widget.ListView; | ||
|
||
import com.example.mealer_project.R; | ||
import com.example.mealer_project.app.App; | ||
import com.example.mealer_project.data.models.Chef; | ||
import com.example.mealer_project.data.models.Order; | ||
import com.example.mealer_project.ui.core.UIScreen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PendingOrdersScreen extends UIScreen { | ||
|
||
// Variable Declaration | ||
/** | ||
* the map that contains the current CHEF's Orders | ||
*/ | ||
private List<Order> ordersData; | ||
|
||
/** | ||
* the list that will hold the orders | ||
*/ | ||
private List<Order> orders; | ||
|
||
/** | ||
* the array adapter for the list view of the pending orders | ||
*/ | ||
private PendingOrdersAdapter pendingOrdersAdapter; | ||
|
||
/** | ||
* the back button icon | ||
*/ | ||
ImageButton backButton; | ||
|
||
//---------------------------------------------------------------------------------------------------------- | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_pending_orders_screen); | ||
|
||
// Initialization | ||
ordersData = new ArrayList<Order>(); | ||
backButton = findViewById(R.id.backButton); | ||
|
||
// Process: loading the Orders data | ||
loadPendingOrdersData(); | ||
|
||
// Process: populating the Orders ListView | ||
populatePendingOrdersList(); | ||
|
||
// Process: setting onClick method for back button | ||
backButton.setOnClickListener(v -> finish()); | ||
|
||
} | ||
|
||
/** | ||
* this helper method retrieves the current CHEF's Orders | ||
*/ | ||
private void loadPendingOrdersData() { | ||
|
||
// Process: checking if current user is a CHEF | ||
if (App.getUser() instanceof Chef) { //is CHEF | ||
// Initialization: setting ordersData to the map of orderIDs & Orders | ||
this.ordersData = ((Chef) App.getUser()).ORDERS.getPendingOrders(); | ||
} | ||
else { //not a chef -> error-handling | ||
Log.e("PendingOrdersScreen", "Can't show pending offered; Current logged-in user is not a CHEF"); | ||
|
||
// Output | ||
displayErrorToast("No pending orders available to be displayed!"); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* this helper method populates the Orders list | ||
*/ | ||
private void populatePendingOrdersList() { | ||
|
||
// Variable Declaration | ||
this.orders = new ArrayList<Order>(); | ||
ListView pendingOrdersList = findViewById(R.id.pendingListView); | ||
|
||
// Initialization: setting the adapter | ||
pendingOrdersAdapter = new PendingOrdersAdapter(this, R.layout.activity_pending_orders_list_item, this.orders); | ||
|
||
// Process: attaching the adapter to the ListView | ||
pendingOrdersList.setAdapter(pendingOrdersAdapter); | ||
|
||
// Process: looping through the map of data | ||
for (Order order: this.ordersData) { | ||
pendingOrdersAdapter.add(order); //adding the orderData to the list | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.