package in.tosc.ghumo.fetchdata;

import android.content.Context;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import in.tosc.ghumo.pojos.Fare;

/**
 * Created by championswimmer on 22/8/15.
 */
public class FareOps {

    public static ArrayList<Fare> getFares(Context ctx) {
        ArrayList<Fare> fares = new ArrayList<>();
        String jsonString = getJsonFromAssets("fares.json", ctx);
        try {
            JSONArray fareArr = new JSONArray(jsonString);
            Gson gson = new Gson();
            for (int i = 0; i < fareArr.length(); i++) {
                fares.add(gson.fromJson((fareArr.getJSONObject(i)).toString(), Fare.class));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return fares;
    }

    public static float calcFare(float kiloMeters, Fare fare) {
        float totalFare = 0;
        totalFare += fare.getBooking_fee();
        totalFare += fare.getMin_fare();

        float chargeableKm = kiloMeters - fare.getMin_dist();
        chargeableKm = (chargeableKm>0) ? chargeableKm : 0;

        totalFare += chargeableKm * fare.getFare_per_km();

        return totalFare;
    }

    public static String getJsonFromAssets (String assetFileName, Context c) {
        String json = null;
        try {
            InputStream is = c.getAssets().open(assetFileName);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return json;
    }
}

@@ -703,84 +703,345 @@
     
-fares.add(gson.fromJson((fareArr.getJSONObject(i)).toString(), Fare.class));
+if(fareArr.getJSONObject(i).getString(%22city%22).toUpperCase().contains(%22DELHI%22)) %7B%0A                    try %7B%0A                        fares.add(gson.fromJson((fareArr.getJSONObject(i)).toString(), Fare.class));%0A                    %7D catch (Exception e) %7B%0A                        // Do fucking nothing%0A                    %7D%0A                %7D
 %0A   

add fares carefully