Merge develop into master #1

Merged
SemvdH merged 297 commits from develop into main 2021-01-06 22:20:51 +00:00
2 changed files with 26 additions and 13 deletions
Showing only changes of commit edcfd2ff0a - Show all commits

View File

@@ -1,5 +1,7 @@
package com.a1.nextlocation.fragments; package com.a1.nextlocation.fragments;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@@ -42,14 +44,34 @@ public class CouponFragment extends Fragment {
CouponListManager.INSTANCE.load(); CouponListManager.INSTANCE.load();
this.couponList = CouponListManager.INSTANCE.getCouponList(); 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.setLayoutManager(this.layoutManager);
this.couponRecyclerView.setAdapter(this.couponAdapter); this.couponRecyclerView.setAdapter(this.couponAdapter);
return view; 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();
} }
} }

View File

@@ -1,7 +1,6 @@
package com.a1.nextlocation.recyclerview; package com.a1.nextlocation.recyclerview;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -29,10 +28,10 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
private TextView couponCode; private TextView couponCode;
private TextView couponReward; private TextView couponReward;
private Coupon coupon;
public CouponViewHolder(@NonNull View itemView) { public CouponViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
itemView.setOnClickListener(this);
} }
public void setTextViewCode(String text){ public void setTextViewCode(String text){
@@ -45,13 +44,9 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
this.couponReward.setText(text); this.couponReward.setText(text);
} }
public void setCoupon(Coupon coupon){
this.coupon = coupon;
}
@Override @Override
public void onClick(View v) { 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 @Override
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) { public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
Coupon coupon = couponList.get(position); Coupon coupon = couponList.get(position);
holder.setCoupon(coupon);
holder.setTextViewCode(coupon.getCode()); holder.setTextViewCode(coupon.getCode());
holder.setTextViewReward(coupon.getReward()); holder.setTextViewReward(coupon.getReward());
} }
@@ -82,7 +76,4 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
return couponList.size(); return couponList.size();
} }
} }