package fr.tvbarthel.apps.simpleweatherforcast.openweathermap;


import android.content.Context;
import android.location.Location;
import android.os.AsyncTask;

import java.io.IOException;
import java.net.MalformedURLException;

import fr.tvbarthel.apps.simpleweatherforcast.utils.SharedPreferenceUtils;
import fr.tvbarthel.apps.simpleweatherforcast.utils.URLUtils;

public class DailyForecastJsonGetter extends AsyncTask<Location, Void, String> {

	private Context mContext;

	public DailyForecastJsonGetter(Context context) {
		super();
		mContext = context;
	}

	@Override
	protected String doInBackground(Location... params) {
		final Location lastKnownLocation = params[0];
		String json = getJsonAsString(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
		if (json != null) {
			SharedPreferenceUtils.storeWeather(mContext, json);
		}
		return json;
	}

	private String getJsonAsString(double latitude, double longitude) {
		String result = null;
		try {
			//TODO use real locale.
			result = URLUtils.getAsString("http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + String.valueOf(latitude) + "&lon=" + String.valueOf(longitude) + "&cnt=14&mode=json&lang=fr&units=metric&APPID=c756ce72a59777bd32a5762e12e74057");
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
}

@@ -220,16 +220,41 @@
 ception;
+%0Aimport java.util.Locale;
 %0A%0Aimport
@@ -1025,16 +1025,74 @@
 locale.%0A
+%09%09%09final String lang = Locale.getDefault().getLanguage();%0A
 %09%09%09resul
@@ -1268,18 +1268,28 @@
 on&lang=
-fr
+%22 + lang + %22
 &units=m

Use real locale language.