// Path: src/it/reyboz/bustorino/fragments/FragmentListenerMain.java
// public interface FragmentListenerMain extends CommonFragmentListener {
// 
//     void toggleSpinner(boolean state);
// 
//     /**
//      * Tell activity that we need to enable/disable the refreshLayout
//      * @param yes or no
//      */
//     void enableRefreshLayout(boolean yes);
// }
// 
// Path: src/it/reyboz/bustorino/util/RoutePositionSorter.java
// public class RoutePositionSorter implements Comparator<Pair<Stop, Route>> {
//     private final Location loc;
//     private final double minutialmetro = 6.0/100; //v = 5km/h
//     private final double distancemultiplier = 2./3;
//     public RoutePositionSorter(Location loc) {
//         this.loc = loc;
//     }
// 
//     @Override
//     public int compare(Pair<Stop, Route> pair1, Pair<Stop, Route> pair2) throws NullPointerException{
//         int delta = 0;
//         final Stop stop1 = pair1.first, stop2 = pair2.first;
//         double dist1 = utils.measuredistanceBetween(loc.getLatitude(),loc.getLongitude(),
//                 stop1.getLatitude(),stop1.getLongitude());
//         double dist2 = utils.measuredistanceBetween(loc.getLatitude(),loc.getLongitude(),
//                 stop2.getLatitude(),stop2.getLongitude());
//         final List<Passaggio> passaggi1 = pair1.second.passaggi,
//                 passaggi2 = pair2.second.passaggi;
//         if(passaggi1.size()<=0 || passaggi2.size()<=0){
//             Log.e("ArrivalsStopAdapter","Cannot compare: No arrivals in one of the stops");
//         } else {
//             Collections.sort(passaggi1);
//             Collections.sort(passaggi2);
//             int deltaOre = passaggi1.get(0).hh-passaggi2.get(0).hh;
//             if(deltaOre>12)
//                 deltaOre -= 24;
//             else if (deltaOre<-12)
//                 deltaOre  += 24;
//             delta+=deltaOre*60 + passaggi1.get(0).mm-passaggi2.get(0).mm;
//         }
//         delta += (int)((dist1 -dist2)*minutialmetro*distancemultiplier);
//         return delta;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return obj instanceof RoutePositionSorter;
//     }
// }
// 
// Path: src/it/reyboz/bustorino/util/StopSorterByDistance.java
// public class StopSorterByDistance implements Comparator<Stop> {
//     private final Location locToCompare;
// 
//     public StopSorterByDistance(Location locToCompare) {
//         this.locToCompare = locToCompare;
//     }
// 
//     @Override
//     public int compare(Stop o1, Stop o2) {
//         return (int) (o1.getDistanceFromLocation(locToCompare)-o2.getDistanceFromLocation(locToCompare));
//     }
// }


import it.reyboz.bustorino.backend.*;
import it.reyboz.bustorino.fragments.FragmentListenerMain;
import it.reyboz.bustorino.util.RoutePositionSorter;
import it.reyboz.bustorino.util.StopSorterByDistance;
import java.util.*;
import android.content.Context;
import android.location.Location;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import it.reyboz.bustorino.R;
/*
	BusTO  - UI components
    Copyright (C) 2017 Fabio Mazza

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.reyboz.bustorino.adapters;




public class ArrivalsStopAdapter extends RecyclerView.Adapter<ArrivalsStopAdapter.ViewHolder> {
    private final static int layoutRes = R.layout.arrivals_nearby_card;
    //private List<Stop> stops;
    private @Nullable Location userPosition;
    private FragmentListenerMain listener;
    private List< Pair<Stop, Route> > routesPairList = new ArrayList<>();
    private final Context context;
    //Maximum number of stops to keep
    private final int MAX_STOPS = 20; //TODO: make it programmable

// Path: src/it/reyboz/bustorino/fragments/FragmentListenerMain.java
// public interface FragmentListenerMain extends CommonFragmentListener {
// 
//     void toggleSpinner(boolean state);
// 
//     /**
//      * Tell activity that we need to enable/disable the refreshLayout
//      * @param yes or no
//      */
//     void enableRefreshLayout(boolean yes);
// }
// 
// Path: src/it/reyboz/bustorino/util/RoutePositionSorter.java
// public class RoutePositionSorter implements Comparator<Pair<Stop, Route>> {
//     private final Location loc;
//     private final double minutialmetro = 6.0/100; //v = 5km/h
//     private final double distancemultiplier = 2./3;
//     public RoutePositionSorter(Location loc) {
//         this.loc = loc;
//     }
// 
//     @Override
//     public int compare(Pair<Stop, Route> pair1, Pair<Stop, Route> pair2) throws NullPointerException{
//         int delta = 0;
//         final Stop stop1 = pair1.first, stop2 = pair2.first;
//         double dist1 = utils.measuredistanceBetween(loc.getLatitude(),loc.getLongitude(),
//                 stop1.getLatitude(),stop1.getLongitude());
//         double dist2 = utils.measuredistanceBetween(loc.getLatitude(),loc.getLongitude(),
//                 stop2.getLatitude(),stop2.getLongitude());
//         final List<Passaggio> passaggi1 = pair1.second.passaggi,
//                 passaggi2 = pair2.second.passaggi;
//         if(passaggi1.size()<=0 || passaggi2.size()<=0){
//             Log.e("ArrivalsStopAdapter","Cannot compare: No arrivals in one of the stops");
//         } else {
//             Collections.sort(passaggi1);
//             Collections.sort(passaggi2);
//             int deltaOre = passaggi1.get(0).hh-passaggi2.get(0).hh;
//             if(deltaOre>12)
//                 deltaOre -= 24;
//             else if (deltaOre<-12)
//                 deltaOre  += 24;
//             delta+=deltaOre*60 + passaggi1.get(0).mm-passaggi2.get(0).mm;
//         }
//         delta += (int)((dist1 -dist2)*minutialmetro*distancemultiplier);
//         return delta;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return obj instanceof RoutePositionSorter;
//     }
// }
// 
// Path: src/it/reyboz/bustorino/util/StopSorterByDistance.java
// public class StopSorterByDistance implements Comparator<Stop> {
//     private final Location locToCompare;
// 
//     public StopSorterByDistance(Location locToCompare) {
//         this.locToCompare = locToCompare;
//     }
// 
//     @Override
//     public int compare(Stop o1, Stop o2) {
//         return (int) (o1.getDistanceFromLocation(locToCompare)-o2.getDistanceFromLocation(locToCompare));
//     }
// }


// Path: src/it/reyboz/bustorino/adapters/ArrivalsStopAdapter.java
import it.reyboz.bustorino.backend.*;
import it.reyboz.bustorino.fragments.FragmentListenerMain;
import it.reyboz.bustorino.util.RoutePositionSorter;
import it.reyboz.bustorino.util.StopSorterByDistance;
import java.util.*;
import android.content.Context;
import android.location.Location;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import it.reyboz.bustorino.R;

/*
	BusTO  - UI components
    Copyright (C) 2017 Fabio Mazza

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.reyboz.bustorino.adapters;




public class ArrivalsStopAdapter extends RecyclerView.Adapter<ArrivalsStopAdapter.ViewHolder> {
    private final static int layoutRes = R.layout.arrivals_nearby_card;
    //private List<Stop> stops;
    private @Nullable Location userPosition;
    private FragmentListenerMain listener;
    private List< Pair<Stop, Route> > routesPairList = new ArrayList<>();
    private final Context context;
    //Maximum number of stops to keep
    private final int MAX_STOPS = 20; //TODO: make it programmable

    public ArrivalsStopAdapter(@Nullable List< Pair<Stop, Route> > routesPairList, FragmentListenerMain fragmentListener, Context con, @Nullable Location pos) {