/******************************************************************************* * 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 android.content.Context; import org.json.JSONException; import org.json.JSONObject; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import fr.gotorennes.domain.LineAlert; public class LineAlertService extends RemoteService<LineAlert> { private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); private static LineAlertService instance; private Date remoteDate; private LineAlertService(Context context) { super(); } public static synchronized LineAlertService getInstance(Context context) { if (instance == null) { instance = new LineAlertService(context); } return instance; } public List<LineAlert> getAlerts(String routeId) { return loadList("refine.idligne=" + routeId); } @Override protected LineAlert populate(JSONObject jsonObject) throws JSONException { LineAlert lineAlert = new LineAlert(); lineAlert.titre = jsonObject.getString("titre"); try { lineAlert.debut = dateFormat.parse(jsonObject.getString("debutvalidite")); } catch (ParseException ex) {} try { lineAlert.fin = dateFormat.parse(jsonObject.getString("finvalidite")); } catch (ParseException ex) {} lineAlert.detail = jsonObject.getString("description"); lineAlert.perturbationMajeure = !"Mineure".equals(jsonObject.getString("niveau")); return lineAlert; } @Override protected String getDataSet() { return "tco-busmetro-trafic-alertes-tr"; } }