/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
*
* 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.
*
* 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 fr.gotorennes.remote;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.util.Log;
import fr.gotorennes.domain.NextMetroDeparture;
public class NextMetroDepartureService extends RemoteService<NextMetroDeparture> {
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
private static NextMetroDepartureService instance;
private Date remoteDate;
private NextMetroDepartureService(Context context) {
super();
}
public static synchronized NextMetroDepartureService getInstance(Context context) {
if (instance == null) {
instance = new NextMetroDepartureService(context);
}
return instance;
}
public List<NextMetroDeparture> getNextDeparture(String stationName) {
return loadList("refine.nomarret=" + encode(stationName));
}
@Override
protected NextMetroDeparture populate(JSONObject jsonObject) throws JSONException {
NextMetroDeparture nextDeparture = new NextMetroDeparture();
try {
nextDeparture.departure = dateFormat.parse(jsonObject.getString("depart"));
}
catch (ParseException ex) {}
nextDeparture.name = jsonObject.getString("nomarret");
nextDeparture.direction = jsonObject.getInt("sens");
nextDeparture.remoteDate = remoteDate;
return nextDeparture;
}
protected void onDataLoad(JSONObject data) throws JSONException {
try {
remoteDate = dateFormat.parse(data.getString("record_timestamp"));
}
catch (ParseException ex) {}
}
@Override
protected String getDataSet() {
return "tco-metro-circulation-passages-tr";
}
}