// Path: app/src/main/java/fr/corenting/edcompanion/utils/MathUtils.java
// public class MathUtils {
// 
//     public static NumberFormat getNumberFormat(Context context) {
//         Locale userLocale = DateUtils.getCurrentLocale(context);
//         return NumberFormat.getIntegerInstance(userLocale);
//     }
// 
//     public static String getPriceDifferenceString(NumberFormat numberFormat, int priceDifference) {
//         String result = numberFormat.format(priceDifference);
//         if (priceDifference >= 0) {
//             return "+" + result;
//         } else {
//             return result;
//         }
//     }
// }


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import org.threeten.bp.Instant;
import java.text.NumberFormat;
import fr.corenting.edcompanion.R;
import fr.corenting.edcompanion.databinding.ListItemCommodityDetailsStationBinding;
import fr.corenting.edcompanion.models.CommodityDetailsStationResult;
import fr.corenting.edcompanion.utils.MathUtils;
import static android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE;

            @Override
            public boolean areContentsTheSame(@NonNull CommodityDetailsStationResult oldItem,
                                              @NonNull CommodityDetailsStationResult newItem) {
                return oldItem.getStation().getName().equals(newItem.getStation().getName()) &&
                        oldItem.getStation().getSystemName().equals(newItem.getStation().getSystemName());
            }
        });

        this.context = ctx;
        this.numberFormat = MathUtils.getNumberFormat(ctx);
        this.isSellMode = isSellMode;
    }

    @NonNull
    @Override
    public stationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ListItemCommodityDetailsStationBinding itemBinding = ListItemCommodityDetailsStationBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new stationViewHolder(itemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull final stationViewHolder holder, final int position) {
        CommodityDetailsStationResult currentStation = getItem(holder.getAdapterPosition());

        holder.viewBinding.titleTextView.setText(String.format("%s - %s", currentStation.getStation().getSystemName(),
                currentStation.getStation().getName()));
        holder.viewBinding.typeTextView.setText(currentStation.getStation().getType());
        holder.viewBinding.starDistanceTextView.setText(context.getString(R.string.distance_ls,
// Path: app/src/main/java/fr/corenting/edcompanion/utils/MathUtils.java
// public class MathUtils {
// 
//     public static NumberFormat getNumberFormat(Context context) {
//         Locale userLocale = DateUtils.getCurrentLocale(context);
//         return NumberFormat.getIntegerInstance(userLocale);
//     }
// 
//     public static String getPriceDifferenceString(NumberFormat numberFormat, int priceDifference) {
//         String result = numberFormat.format(priceDifference);
//         if (priceDifference >= 0) {
//             return "+" + result;
//         } else {
//             return result;
//         }
//     }
// }


// Path: app/src/main/java/fr/corenting/edcompanion/adapters/CommodityDetailsStationsAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import org.threeten.bp.Instant;
import java.text.NumberFormat;
import fr.corenting.edcompanion.R;
import fr.corenting.edcompanion.databinding.ListItemCommodityDetailsStationBinding;
import fr.corenting.edcompanion.models.CommodityDetailsStationResult;
import fr.corenting.edcompanion.utils.MathUtils;
import static android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE;


            @Override
            public boolean areContentsTheSame(@NonNull CommodityDetailsStationResult oldItem,
                                              @NonNull CommodityDetailsStationResult newItem) {
                return oldItem.getStation().getName().equals(newItem.getStation().getName()) &&
                        oldItem.getStation().getSystemName().equals(newItem.getStation().getSystemName());
            }
        });

        this.context = ctx;
        this.numberFormat = MathUtils.getNumberFormat(ctx);
        this.isSellMode = isSellMode;
    }

    @NonNull
    @Override
    public stationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ListItemCommodityDetailsStationBinding itemBinding = ListItemCommodityDetailsStationBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new stationViewHolder(itemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull final stationViewHolder holder, final int position) {
        CommodityDetailsStationResult currentStation = getItem(holder.getAdapterPosition());

        holder.viewBinding.titleTextView.setText(String.format("%s - %s", currentStation.getStation().getSystemName(),
                currentStation.getStation().getName()));
        holder.viewBinding.typeTextView.setText(currentStation.getStation().getType());
        holder.viewBinding.starDistanceTextView.setText(context.getString(R.string.distance_ls,
                numberFormat.format(currentStation.getStation().getDistanceToStar())));