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

Vedant #28

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS"> </uses-permission>



<permission android:name="com.BugBazaar.permission.contacts" android:protectionLevel="signature"/>


Expand Down Expand Up @@ -40,8 +38,8 @@
tools:targetApi="31"
tools:ignore="CustomPermissionTypo">
<activity
android:name=".ui.payment.OrderHistory"
android:exported="false" />
android:name=".ui.myorders.OrderHistoryActivity"
android:exported="true" />
<activity
android:name=".ui.payment.OrderSummary"
android:exported="true" />
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.BugBazaar.ui.cart.CartActivity;
import com.BugBazaar.ui.cart.CartItem;
import com.BugBazaar.ui.cart.NotificationHelper;
import com.BugBazaar.ui.myorders.OrderHistoryActivity;

import com.BugBazaar.utils.AppInitializationManager;
import com.BugBazaar.utils.CustomDialog;
import com.google.android.material.navigation.NavigationView;
Expand Down Expand Up @@ -108,7 +110,7 @@ protected void onCreate(Bundle savedInstanceState) {
productGridView.setAdapter(adapter);

//Handle Deeplink intent
// Intent get_item = getIntent();
Intent get_item = getIntent();
if (get_item.hasExtra("fetched_item")) {
// Check for the "fetched_item" string extra
String deeplink_item = get_item.getStringExtra("fetched_item");
Expand Down Expand Up @@ -212,7 +214,19 @@ else if (itemId == R.id.itemCart) {
startActivity(intent);
drawerLayout.closeDrawer(GravityCompat.START);
return true;
} else if (itemId == R.id.itemLoginLogout) {
}
else if (itemId == R.id.itemWallet) {
Intent intent = new Intent(NavigationDrawer_Dashboard.this, TermsAndConditionsActivity.class);
startActivity(intent);
drawerLayout.closeDrawer(GravityCompat.START);
return true;
} else if (itemId == R.id.itemMyOrders) {
Intent intent = new Intent(NavigationDrawer_Dashboard.this, OrderHistoryActivity.class);
startActivity(intent);
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
else if (itemId == R.id.itemLoginLogout) {
Intent intent = new Intent(NavigationDrawer_Dashboard.this, Signin.class);
startActivity(intent);
drawerLayout.closeDrawer(GravityCompat.START);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void showNotification(Context context, StringBuilder message) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notification = new Notification.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.sucessful_order)
.setContentTitle("your Order Summary")
.setContentTitle("Your order for below items has been placed!\n")
.setContentText(message)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.BugBazaar.ui.myorders;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.BugBazaar.R;

import org.w3c.dom.Text;

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

public class OrderHistoryActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_history);

// Toolbar title set
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("My Orders");

//NoOrder Components
LinearLayout emptyLinearOH=findViewById(R.id.emptyLinearOH);
ImageView orderEmptyImage=findViewById(R.id.orderEmptyImage);
TextView orderEmptyTextView=findViewById(R.id.orderEmptyTextView);


// Receive the Intent that started this activity
Intent intent = getIntent();
String orderId = intent.getStringExtra("order_id");
Log.d("OrderHistoryActivity", "Order ID: " + orderId);

if (orderId == null) {
// OrderID is null, fetch and display all old orders from OrderHistory db

// Use the OrderHistoryDatabaseHelper to fetch all order items from the database
OrderHistoryDatabaseHelper dbHelper = new OrderHistoryDatabaseHelper(this);
List<OrderHistoryItem> orderItems = dbHelper.getAllOrderItemsz();
if(orderItems.isEmpty()){
RecyclerView recyclerView = findViewById(R.id.orderHistoryRecyclerView);
recyclerView.setVisibility(View.GONE);

//Order Empty UI components show
emptyLinearOH.setVisibility(View.VISIBLE);
orderEmptyImage.setVisibility(View.VISIBLE);
orderEmptyTextView.setVisibility(View.VISIBLE);
}else{

// Find the RecyclerView in the layout
RecyclerView recyclerView = findViewById(R.id.orderHistoryRecyclerView);
// Create an adapter for the RecyclerView
OrderHistoryAdapter adapter = new OrderHistoryAdapter(orderItems, this);

// Set the adapter for the RecyclerView
recyclerView.setAdapter(adapter);
// Set the layout manager for the RecyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(this));

// Add dividers between items
adapter.addDividers(recyclerView);
}
} else {
OrderHistoryDatabaseHelper dbHelper = new OrderHistoryDatabaseHelper(this);
List<OrderHistoryItem> orderItems = dbHelper.getAllOrderItemsz();

// Find the RecyclerView in the layout
RecyclerView recyclerView = findViewById(R.id.orderHistoryRecyclerView);
// Create an adapter for the RecyclerView
OrderHistoryAdapter adapter = new OrderHistoryAdapter(orderItems, this);

// Set the adapter for the RecyclerView
recyclerView.setAdapter(adapter);
// Set the layout manager for the RecyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(this));

// Add dividers between items
adapter.addDividers(recyclerView);
}
}

private void loadAndLogAllItemsFromDatabase() {
// Load all items from the database and log them
OrderHistoryDatabaseHelper dbHelper = new OrderHistoryDatabaseHelper(this);
List<OrderHistoryItem> allItems = dbHelper.getAllOrderItemsz();

for (OrderHistoryItem item : allItems) {
Log.d("OrderHistoryActivity", "Order ID: " + item.getOrderID());
Log.d("OrderHistoryActivity", "Product Names:");
for (String productName : item.getProductNames()) {
Log.d("OrderHistoryActivity", " - " + productName);
}
Log.d("OrderHistoryActivity", "Order Total: " + item.getFinalCost());
}
}

// Code to handle the back button
public void onBackButtonClick(View view) {
onBackPressed(); // Navigate back to the previous activity
}
}
102 changes: 102 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.BugBazaar.ui.myorders;

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

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

import com.BugBazaar.R;
import android.text.Html;
import android.text.Spanned;


import java.util.List;

public class OrderHistoryAdapter extends RecyclerView.Adapter<OrderHistoryAdapter.OrderViewHolder> {
private List<OrderHistoryItem> orderItems;
private Context context;

public OrderHistoryAdapter(List<OrderHistoryItem> orderItems, Context context) {
this.orderItems = orderItems;
this.context = context;
}
// Method to set dividers
public void addDividers(RecyclerView recyclerView) {
Drawable divider = context.getResources().getDrawable(R.drawable.divider); // The custom divider XML
DividerItemDecoration itemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
itemDecoration.setDrawable(divider);
recyclerView.addItemDecoration(itemDecoration);
}

@NonNull
@Override
public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_item, parent, false);
return new OrderViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull OrderViewHolder holder, int position) {
OrderHistoryItem orderItem = orderItems.get(position);

// Use HTML formatting to make "Order ID" text bold
String orderIdText = "<b>" + orderItem.getOrderID()+"</b>";
holder.orderIdTextView.setText(Html.fromHtml(orderIdText, Html.FROM_HTML_MODE_COMPACT));

// Format the list of products with bullet points including quantity
StringBuilder productsText = new StringBuilder();
List<String> productNames = orderItem.getProductNames();
List<Integer> productQuantities = orderItem.getProductQuantities();
for (int i = 0; i < productNames.size(); i++) {
String productName = productNames.get(i);
int productQuantity = productQuantities.get(i);
productsText.append("• ").append(productName).append(" (Qty: ").append(productQuantity).append(")\n");
}
holder.itemsTextView.setText(productsText.toString());

String formattedTotalCost = formatPrice(orderItem.getFinalCost());
String orderTotal = "<b>Order Total:</b> <i>" + formattedTotalCost+"</i>";
holder.orderTotalTextView.setText(Html.fromHtml(orderTotal, Html.FROM_HTML_MODE_COMPACT));
}





// Format the list of products with bullet points
private String formatProductList(String products) {
String[] productList = products.split(", "); // Assuming products are comma-separated
StringBuilder formattedList = new StringBuilder();
for (String product : productList) {
formattedList.append("• ").append(product).append("\n");
}
return formattedList.toString();
}

@Override
public int getItemCount() {
return orderItems.size();
}

public class OrderViewHolder extends RecyclerView.ViewHolder {
TextView orderIdTextView;
TextView itemsTextView;
TextView orderTotalTextView;

public OrderViewHolder(View itemView) {
super(itemView);
orderIdTextView = itemView.findViewById(R.id.orderIdTextView);
itemsTextView = itemView.findViewById(R.id.itemsTextView);
orderTotalTextView = itemView.findViewById(R.id.orderTotalTextView);
}
}
private String formatPrice(int price) {
return String.format("₹%,d", price);
}
}
Loading
Loading