Skip to content

Commit c16a249

Browse files
committed
Add Payment Method and 97% Completed
1 parent ad4c1c3 commit c16a249

File tree

5 files changed

+177
-9
lines changed

5 files changed

+177
-9
lines changed

app/src/main/java/codercamp/com/e_commerce/activity/DetailedActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void onClick(View v) {
144144
String currentDate, currentTime;
145145

146146
Calendar calendar = Calendar.getInstance();
147-
147+
calendar.add(Calendar.HOUR,-1);
148148
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd,yyyy");
149149
currentDate = dateFormat.format(calendar.getTime());
150150

app/src/main/java/codercamp/com/e_commerce/activity/PaymentActivity.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.annotation.SuppressLint;
44
import android.content.Intent;
55
import android.os.Bundle;
6+
import android.util.Log;
67
import android.view.View;
78
import android.widget.Button;
89
import android.widget.RadioButton;
@@ -16,17 +17,25 @@
1617
import com.google.android.gms.tasks.Task;
1718
import com.google.firebase.auth.FirebaseAuth;
1819
import com.google.firebase.auth.FirebaseUser;
20+
import com.google.firebase.database.DataSnapshot;
21+
import com.google.firebase.database.DatabaseError;
22+
import com.google.firebase.database.DatabaseReference;
23+
import com.google.firebase.database.FirebaseDatabase;
24+
import com.google.firebase.database.ValueEventListener;
1925
import com.google.firebase.firestore.DocumentReference;
2026
import com.google.firebase.firestore.FirebaseFirestore;
2127

2228
import java.text.SimpleDateFormat;
2329
import java.util.Calendar;
2430
import java.util.HashMap;
2531
import java.util.List;
32+
import java.util.Objects;
2633

2734
import codercamp.com.e_commerce.BkashPaymentIntegration.BkashActivity;
2835
import codercamp.com.e_commerce.R;
2936
import codercamp.com.e_commerce.models.MyCartModel;
37+
import codercamp.com.e_commerce.models.Payment_time;
38+
import codercamp.com.e_commerce.models.ProfileModel;
3039

3140
public class PaymentActivity extends AppCompatActivity {
3241
private RadioGroup radioGroup;//
@@ -36,7 +45,10 @@ public class PaymentActivity extends AppCompatActivity {
3645
private FirebaseAuth auth;
3746
private FirebaseUser user;
3847
private FirebaseFirestore database;
48+
private DatabaseReference reference;
3949
private List<MyCartModel> myCartModels;
50+
String name;
51+
String number;
4052

4153

4254
@Override
@@ -53,17 +65,48 @@ protected void onCreate(Bundle savedInstanceState) {
5365
user = auth.getCurrentUser();
5466
database = FirebaseFirestore.getInstance();
5567

68+
auth = FirebaseAuth.getInstance();
69+
user = auth.getCurrentUser();
70+
71+
reference = FirebaseDatabase.getInstance().getReference("Users");
72+
73+
reference.child(Objects.requireNonNull(auth.getCurrentUser()).getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
74+
@Override
75+
public void onDataChange(@NonNull DataSnapshot snapshot) {
76+
77+
ProfileModel model = snapshot.getValue(ProfileModel.class);
78+
if (model != null) {
79+
try {
80+
name = model.getName();
81+
number = model.getNumber();
82+
} catch (Exception exception) {
83+
exception.printStackTrace();
84+
}
85+
}
86+
}
87+
88+
@Override
89+
public void onCancelled(@NonNull DatabaseError error) {
90+
Log.w("TAG", "Failed to read value.", error.toException());
91+
}
92+
});
93+
5694

5795
String currentDate, currentTime;
5896

5997
Calendar calendar = Calendar.getInstance();
98+
calendar.add(Calendar.HOUR,-1);
6099

61-
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd,yyyy");
100+
@SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
62101
currentDate = dateFormat.format(calendar.getTime());
63102

64-
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
103+
@SuppressLint("SimpleDateFormat") SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
65104
currentTime = timeFormat.format(calendar.getTime());
66105

106+
107+
108+
Payment_time payment_time = new Payment_time(currentDate,currentTime);
109+
67110
myCartModels = (List<MyCartModel>) getIntent().getSerializableExtra("itemList");
68111

69112
FinalOrder.setOnClickListener(new View.OnClickListener() {
@@ -72,17 +115,21 @@ public void onClick(View v) {
72115
//If Selected Cash On Delivery
73116
if (CashOn.isChecked()) {
74117

118+
75119
if (myCartModels != null && myCartModels.size() > 0) {
76120

77121
for (MyCartModel cartModel : myCartModels) {
78122
final HashMap<String, Object> map = new HashMap<>();
79123

124+
125+
map.put("UserName", name);
126+
map.put("Number", number);
80127
map.put("ProductName", cartModel.getProductName());
81128
map.put("ProductPrice", cartModel.getProductPrice());
82129
map.put("TotalQuantity", cartModel.getTotalQuantity());
83130
map.put("TotalPrice", cartModel.getTotalPrice());
84-
map.put("CurrentDate", currentDate);//cartModel.getCurrentDate()
85-
map.put("CurrentTime", currentTime);//cartModel.getCurrentTime()
131+
map.put("CurrentDate", payment_time.getCurrentDate());//cartModel.getCurrentDate()
132+
map.put("CurrentTime", payment_time.getCurrentTime());//cartModel.getCurrentTime()
86133

87134
//Store Data in Database
88135
database.collection("CurrentUser").document(user.getUid())
@@ -97,7 +144,7 @@ public void onComplete(@NonNull Task<DocumentReference> task) {
97144
removeItemToCart(cartModel);
98145
finish();
99146
} else {
100-
Toast.makeText(PaymentActivity.this, "Yor Order Placed Failed", Toast.LENGTH_SHORT).show();
147+
Toast.makeText(PaymentActivity.this, "Your Order Placed Failed", Toast.LENGTH_SHORT).show();
101148

102149
}
103150
}

app/src/main/java/codercamp/com/e_commerce/adapters/MyOrderAdapter.java

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package codercamp.com.e_commerce.adapters;
22

33
import android.content.Context;
4+
import android.util.Log;
45
import android.view.LayoutInflater;
56
import android.view.View;
67
import android.view.ViewGroup;
@@ -9,18 +10,65 @@
910
import androidx.annotation.NonNull;
1011
import androidx.recyclerview.widget.RecyclerView;
1112

13+
import com.google.firebase.auth.FirebaseAuth;
14+
import com.google.firebase.auth.FirebaseUser;
15+
import com.google.firebase.database.DataSnapshot;
16+
import com.google.firebase.database.DatabaseError;
17+
import com.google.firebase.database.DatabaseReference;
18+
import com.google.firebase.database.FirebaseDatabase;
19+
import com.google.firebase.database.ValueEventListener;
20+
1221
import java.util.List;
22+
import java.util.Objects;
1323

1424
import codercamp.com.e_commerce.R;
1525
import codercamp.com.e_commerce.models.MyCartModel;
26+
import codercamp.com.e_commerce.models.Payment_time;
27+
import codercamp.com.e_commerce.models.ProfileModel;
1628

1729
public class MyOrderAdapter extends RecyclerView.Adapter<MyOrderAdapter.MyViewHolderOrder> {
1830
private List<MyCartModel> myOrder;
1931
private Context mContext;
20-
32+
private FirebaseAuth auth;
33+
private FirebaseUser user;
34+
private DatabaseReference reference;
35+
private List<MyCartModel> myCartModels;
36+
String name;
37+
String number;
38+
String date, time;
2139
public MyOrderAdapter(List<MyCartModel> myOrder, Context mContext) {
2240
this.myOrder = myOrder;
2341
this.mContext = mContext;
42+
Payment_time payment_time = new Payment_time();
43+
44+
time = payment_time.getCurrentTime();
45+
date = payment_time.getCurrentDate();
46+
47+
auth = FirebaseAuth.getInstance();
48+
user = auth.getCurrentUser();
49+
50+
reference = FirebaseDatabase.getInstance().getReference("Users");
51+
52+
reference.child(Objects.requireNonNull(auth.getCurrentUser()).getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
53+
@Override
54+
public void onDataChange(@NonNull DataSnapshot snapshot) {
55+
56+
ProfileModel model = snapshot.getValue(ProfileModel.class);
57+
if (model!= null){
58+
try {
59+
name = model.getName();
60+
number = model.getNumber();
61+
}
62+
catch (Exception exception){
63+
exception.printStackTrace();
64+
}
65+
}
66+
}
67+
@Override
68+
public void onCancelled(@NonNull DatabaseError error) {
69+
Log.w("TAG", "Failed to read value.", error.toException());
70+
}
71+
});
2472
}
2573

2674
@NonNull
@@ -34,14 +82,19 @@ public MyViewHolderOrder onCreateViewHolder(@NonNull ViewGroup parent, int viewT
3482
@Override
3583
public void onBindViewHolder(@NonNull MyViewHolderOrder holder, int position) {
3684

85+
3786
MyCartModel model = myOrder.get(position);
3887

88+
89+
holder.UserName.setText("User Name : "+name);
90+
holder.Number.setText("Number : "+number);
91+
3992
holder.ProductID.setText("Product ID : "+model.getDocumentId());
4093
holder.ProductName.setText("Product Name : "+model.getProductName());
4194
holder.ProductPrice.setText("Product Price : "+String.valueOf(model.getProductPrice()) + " Tk");
4295
holder.ProductQuantity.setText("Total Quantity : "+model.getTotalQuantity());
4396
holder.TotalPrice.setText("Total Price : "+String.valueOf(model.getTotalPrice()) + " Tk");
44-
holder.DateTime.setText("Date Time :"+model.getCurrentTime() + model.getCurrentDate());
97+
holder.DateTime.setText("Date Time :"+time +" "+ date);
4598

4699
}
47100

@@ -51,10 +104,13 @@ public int getItemCount() {
51104
}
52105

53106
public class MyViewHolderOrder extends RecyclerView.ViewHolder {
54-
private TextView ProductID,ProductName, ProductPrice, TotalPrice, ProductQuantity, DateTime;
107+
private TextView ProductID,ProductName, ProductPrice, TotalPrice, ProductQuantity, DateTime, UserName, Number;
55108

56109
public MyViewHolderOrder(@NonNull View view) {
57110
super(view);//Product_ID
111+
UserName = view.findViewById(R.id.UserName);
112+
Number = view.findViewById(R.id.Number);
113+
58114
ProductID = view.findViewById(R.id.Product_ID);
59115
ProductName = view.findViewById(R.id.Product_Name);
60116
ProductPrice = view.findViewById(R.id.Product_Price);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package codercamp.com.e_commerce.models;
2+
3+
public class Payment_time {
4+
private String CurrentDate, CurrentTime;
5+
6+
public Payment_time() {
7+
}
8+
9+
public Payment_time(String currentDate, String currentTime) {
10+
CurrentDate = currentDate;
11+
CurrentTime = currentTime;
12+
}
13+
14+
public String getCurrentDate() {
15+
return CurrentDate;
16+
}
17+
18+
public void setCurrentDate(String currentDate) {
19+
CurrentDate = currentDate;
20+
}
21+
22+
public String getCurrentTime() {
23+
return CurrentTime;
24+
}
25+
26+
public void setCurrentTime(String currentTime) {
27+
CurrentTime = currentTime;
28+
}
29+
}

app/src/main/res/layout/my_order_data.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@
1515
android:orientation="horizontal"
1616
android:layout_margin="@dimen/_10sdp">
1717

18+
<TextView
19+
android:id="@+id/UserName"
20+
android:layout_width="0dp"
21+
android:layout_height="wrap_content"
22+
android:layout_weight="1"
23+
android:text="Name"
24+
android:textStyle="bold"
25+
android:maxLines="1"
26+
android:ellipsize="end"
27+
android:textColor="@color/black"
28+
android:textSize="@dimen/_13sdp"/>
29+
</LinearLayout>
30+
<LinearLayout
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:orientation="horizontal"
34+
android:layout_margin="@dimen/_10sdp">
35+
36+
<TextView
37+
android:id="@+id/Number"
38+
android:layout_width="0dp"
39+
android:layout_height="wrap_content"
40+
android:layout_weight="1"
41+
android:text="Number"
42+
android:textStyle="bold"
43+
android:maxLines="1"
44+
android:ellipsize="end"
45+
android:textColor="@color/black"
46+
android:textSize="@dimen/_13sdp"/>
47+
</LinearLayout>
48+
<LinearLayout
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content"
51+
android:orientation="horizontal"
52+
android:layout_margin="@dimen/_10sdp">
53+
1854
<TextView
1955
android:id="@+id/Product_ID"
2056
android:layout_width="0dp"

0 commit comments

Comments
 (0)