Added comments
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.a1.nextlocation.fragments;
|
package com.a1.nextlocation.fragments;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
@@ -22,16 +23,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class StatisticFragment extends Fragment {
|
public class StatisticFragment extends Fragment {
|
||||||
|
|
||||||
private List<Coupon> couponList;
|
|
||||||
private ImageView imageButton;
|
|
||||||
private ImageView couponButton;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint({"DefaultLocale", "SetTextI18n"})
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_statistic, container, false);
|
View view = inflater.inflate(R.layout.fragment_statistic, container, false);
|
||||||
@@ -51,24 +48,27 @@ public class StatisticFragment extends Fragment {
|
|||||||
timeText.setText(p2 + ":" + p3 + ":" + p1);
|
timeText.setText(p2 + ":" + p3 + ":" + p1);
|
||||||
|
|
||||||
|
|
||||||
this.couponList = CouponListManager.INSTANCE.getCouponList();
|
//loads the couponList
|
||||||
CouponAdapter adapter = new CouponAdapter(this.getContext(), this.couponList);
|
List<Coupon> couponList = CouponListManager.INSTANCE.getCouponList();
|
||||||
|
CouponAdapter adapter = new CouponAdapter(this.getContext(), couponList);
|
||||||
TextView couponNumber = view.findViewById(R.id.couponAmount);
|
TextView couponNumber = view.findViewById(R.id.couponAmount);
|
||||||
couponNumber.setText(String.valueOf(adapter.getItemCount()));
|
couponNumber.setText(String.valueOf(adapter.getItemCount()));
|
||||||
|
|
||||||
|
//Initialises the back button
|
||||||
this.imageButton = view.findViewById(R.id.statistics_back_button);
|
ImageView backButton = view.findViewById(R.id.statistics_back_button);
|
||||||
this.imageButton.setOnClickListener(v -> {
|
backButton.setOnClickListener(v -> {
|
||||||
HomeFragment homeFragment = new HomeFragment();
|
HomeFragment homeFragment = new HomeFragment();
|
||||||
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
|
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.couponButton = view.findViewById(R.id.coupon_button);
|
//Initialises the coupon button
|
||||||
this.couponButton.setOnClickListener(v -> {
|
ImageView couponButton = view.findViewById(R.id.coupon_button);
|
||||||
|
couponButton.setOnClickListener(v -> {
|
||||||
CouponFragment couponFragment = new CouponFragment();
|
CouponFragment couponFragment = new CouponFragment();
|
||||||
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, couponFragment).addToBackStack(null).commit();
|
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, couponFragment).addToBackStack(null).commit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Makes the constraintlayout clickable and opens the same layout as the coupon button
|
||||||
ConstraintLayout constraintLayout = view.findViewById(R.id.Box4);
|
ConstraintLayout constraintLayout = view.findViewById(R.id.Box4);
|
||||||
constraintLayout.setOnClickListener(v -> {
|
constraintLayout.setOnClickListener(v -> {
|
||||||
CouponFragment couponFragment = new CouponFragment();
|
CouponFragment couponFragment = new CouponFragment();
|
||||||
|
|||||||
@@ -27,17 +27,19 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
|||||||
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
private TextView couponCode;
|
private TextView couponCode;
|
||||||
private TextView couponReward;
|
|
||||||
|
|
||||||
public CouponViewHolder(@NonNull View itemView) {
|
public CouponViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the text of the coupon
|
||||||
|
* @param text the text that will be set
|
||||||
|
*/
|
||||||
public void setTextViewName(String text){
|
public void setTextViewName(String text){
|
||||||
this.couponReward = itemView.findViewById(R.id.coupon_name);
|
TextView couponReward = itemView.findViewById(R.id.coupon_name);
|
||||||
this.couponReward.setText(text);
|
couponReward.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,10 +22,9 @@ public enum CouponListManager {
|
|||||||
return couponList;
|
return couponList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coupon getCoupon(int place) {
|
/**
|
||||||
return couponList.get(place);
|
* Prepares the list for loading
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
CouponLoader couponLoader = new CouponLoader(this.context);
|
CouponLoader couponLoader = new CouponLoader(this.context);
|
||||||
this.couponList = couponLoader.load();
|
this.couponList = couponLoader.load();
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ public class CouponLoader implements Loader<List<Coupon>> {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the Arraylist of coupons out of the JSON
|
||||||
|
* @return Arraylist of coupons
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Coupon> load() {
|
public ArrayList<Coupon> load() {
|
||||||
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
||||||
|
|||||||
@@ -42,11 +42,19 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
|
|||||||
clickListener.onItemClick(getAdapterPosition());
|
clickListener.onItemClick(getAdapterPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the text of the location name
|
||||||
|
* @param text the text that will be set
|
||||||
|
*/
|
||||||
public void setTextViewText(String text){
|
public void setTextViewText(String text){
|
||||||
this.locationName = itemView.findViewById(R.id.location_name);
|
this.locationName = itemView.findViewById(R.id.location_name);
|
||||||
locationName.setText(text);
|
this.locationName.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the image of the locatoin
|
||||||
|
* @param text the text of the image filename
|
||||||
|
*/
|
||||||
public void setImageViewImage(String text){
|
public void setImageViewImage(String text){
|
||||||
this.locationImage = itemView.findViewById(R.id.location_image);
|
this.locationImage = itemView.findViewById(R.id.location_image);
|
||||||
Context context = locationImage.getContext();
|
Context context = locationImage.getContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user