Added popups for coupons
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.a1.nextlocation.fragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -42,14 +44,34 @@ public class CouponFragment extends Fragment {
|
||||
CouponListManager.INSTANCE.load();
|
||||
this.couponList = CouponListManager.INSTANCE.getCouponList();
|
||||
|
||||
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList, onClickedItem -> showPopup());
|
||||
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList, clickedPosition -> showPopup(this.couponList.get(clickedPosition)));
|
||||
|
||||
this.couponRecyclerView.setLayoutManager(this.layoutManager);
|
||||
this.couponRecyclerView.setAdapter(this.couponAdapter);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void showPopup() {
|
||||
private void showPopup(Coupon coupon) {
|
||||
AlertDialog.Builder activateBuilder = new AlertDialog.Builder(getContext());
|
||||
AlertDialog.Builder couponCodeBuilder = new AlertDialog.Builder(getContext());
|
||||
// TODO: use string resources instead of hardcoded strings
|
||||
activateBuilder.setMessage("Weet je zeker dat je deze coupon wilt activeren?");
|
||||
activateBuilder.setCancelable(true);
|
||||
// TODO: use string resources instead of hardcoded strings
|
||||
activateBuilder.setPositiveButton("activeren", (dialog, which) -> {
|
||||
// TODO: use string resources instead of hardcoded strings
|
||||
dialog.cancel();
|
||||
couponCodeBuilder.setMessage("Code: " + coupon.getCode());
|
||||
couponCodeBuilder.setPositiveButton("Klaar", (dialog1, which1) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
AlertDialog couponCodePopup = couponCodeBuilder.create();
|
||||
couponCodePopup.show();
|
||||
});
|
||||
// TODO: use string resources instead of hardcoded strings
|
||||
activateBuilder.setNegativeButton("annuleren", (dialog, which) -> dialog.cancel());
|
||||
AlertDialog couponPopup = activateBuilder.create();
|
||||
couponPopup.show();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.a1.nextlocation.recyclerview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -29,10 +28,10 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
||||
|
||||
private TextView couponCode;
|
||||
private TextView couponReward;
|
||||
private Coupon coupon;
|
||||
|
||||
public CouponViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setTextViewCode(String text){
|
||||
@@ -45,13 +44,9 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
||||
this.couponReward.setText(text);
|
||||
}
|
||||
|
||||
public void setCoupon(Coupon coupon){
|
||||
this.coupon = coupon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.d("yeet", "Coupon code: " + coupon.getCode());
|
||||
clickListener.onItemClick(getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +67,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
|
||||
Coupon coupon = couponList.get(position);
|
||||
holder.setCoupon(coupon);
|
||||
holder.setTextViewCode(coupon.getCode());
|
||||
holder.setTextViewReward(coupon.getReward());
|
||||
}
|
||||
@@ -82,7 +76,4 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
||||
return couponList.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user