diff --git a/res/layout/main_activity.xml b/res/layout/main_activity.xml
index d96bc0c..3bd86ab 100644
--- a/res/layout/main_activity.xml
+++ b/res/layout/main_activity.xml
@@ -1,56 +1,57 @@
+ android:layout_below="@+id/searchButton"
+ android:scrollbars="horizontal" />
+ android:layout_below="@+id/busStopNumberEditText"
+ android:layout_toLeftOf="@+id/searchButton" />
diff --git a/src/it/reyboz/bustorino/GTTSiteSucker.java b/src/it/reyboz/bustorino/GTTSiteSucker.java
index ebba488..afad109 100644
--- a/src/it/reyboz/bustorino/GTTSiteSucker.java
+++ b/src/it/reyboz/bustorino/GTTSiteSucker.java
@@ -1,127 +1,127 @@
package it.reyboz.bustorino;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import android.util.Log;
public class GTTSiteSucker {
public static class TimePassage {
private String time;
private boolean isInRealTime;
public TimePassage(String time, boolean isInRealTime) {
this.time = time;
this.isInRealTime = isInRealTime;
}
public String getTime() {
return time;
}
public boolean isInRealTime() {
return isInRealTime;
}
}
public static class ArrivalsAtBusStop {
private int codLineaGTT;
- private int lineaGTT;
+ private String lineaGTT;
private ArrayList timesPassages;
public ArrivalsAtBusStop() {
timesPassages = new ArrayList();
}
public void setCodLineaGTT(int codLineaGTT) {
this.codLineaGTT = codLineaGTT;
}
- public void setLineaGTT(int lineaGTT) {
+ public void setLineaGTT(String lineaGTT) {
this.lineaGTT = lineaGTT;
}
public void addTimePassage(String time, boolean isInRealTime) {
timesPassages.add(new TimePassage(time, isInRealTime));
}
public int getCodLineaGTT() {
return codLineaGTT;
}
- public int getLineaGTT() {
+ public String getLineaGTT() {
return lineaGTT;
}
public ArrayList getTimePassages() {
return timesPassages;
}
public String toString() {
return codLineaGTT + " " + lineaGTT;
}
}
public static String arrivalTimesByLineQuery(String busStop) {
return "http://www.5t.torino.it/5t/trasporto/arrival-times-byline.jsp?action=getTransitsByLine&shortName=" + busStop;
}
/**
* Workaround to get all informations from the 5T website
*
* @param html
* @author Valerio Bozzolan
*/
public static ArrivalsAtBusStop[] arrivalTimesBylineHTMLSucker(String html) {
ArrayList arrivalsAtBusStop = new ArrayList();
Document doc = Jsoup.parse(html);
for (Element tr : doc.getElementsByTag("tr")) {
ArrivalsAtBusStop arrivalAtBusStop = new ArrivalsAtBusStop();
boolean codLineaGTTfound = false;
for (Element td : tr.children()) {
String tdContent = td.html();
if (tdContent.isEmpty()) {
continue;
}
if (!codLineaGTTfound) {
Element tdURL = td.select("a").first();
String lineaGTT = tdURL.html();
String codLineaGTT = "";
Matcher matcher = Pattern.compile("([0-9])+").matcher(
tdURL.attr("href"));
if (matcher.find()) {
codLineaGTT = matcher.group();
}
- arrivalAtBusStop.setLineaGTT(Integer.parseInt(lineaGTT));
+ arrivalAtBusStop.setLineaGTT(lineaGTT);
arrivalAtBusStop.setCodLineaGTT(Integer
.parseInt(codLineaGTT));
codLineaGTTfound = true;
continue;
}
// Look for "*"
boolean frozenProduct = !td.select("i").isEmpty();
if(frozenProduct) {
td.select("i").remove();
tdContent = td.html();
}
Log.d("miao", "Prodotto surgelato: " + ((frozenProduct) ? "Yeppa" : "Nopely nope"));
arrivalAtBusStop.addTimePassage(tdContent, frozenProduct);
Log.d("miao td", "td: " + tdContent);
}
arrivalsAtBusStop.add(arrivalAtBusStop);
}
return (ArrivalsAtBusStop[]) arrivalsAtBusStop
.toArray(new ArrivalsAtBusStop[] {});
}
}
diff --git a/src/it/reyboz/bustorino/MainActivity.java b/src/it/reyboz/bustorino/MainActivity.java
index 592c230..6235b93 100644
--- a/src/it/reyboz/bustorino/MainActivity.java
+++ b/src/it/reyboz/bustorino/MainActivity.java
@@ -1,84 +1,90 @@
package it.reyboz.bustorino;
import it.reyboz.bustorino.GTTSiteSucker.ArrivalsAtBusStop;
import it.reyboz.bustorino.GTTSiteSucker.TimePassage;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private EditText bus_stop_number_editText;
private TextView result_textView;
private ProgressBar annoyingFedbackProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
- bus_stop_number_editText = (EditText)findViewById(R.id.bus_stop_number_editText);
+ bus_stop_number_editText = (EditText)findViewById(R.id.busStopNumberEditText);
result_textView = (TextView)findViewById(R.id.result_textView);
annoyingFedbackProgressBar = (ProgressBar)findViewById(R.id.annoyingFedbackProgress);
annoyingFedbackProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Catch the Async action!
* @author boz
*/
public class MyAsyncWget extends AsyncWget {
protected void onPostExecute(String result) {
ArrivalsAtBusStop[] arrivalsAtBusStop = GTTSiteSucker.arrivalTimesBylineHTMLSucker(result);
- boolean done = false;
String out = "";
for(ArrivalsAtBusStop arrivalAtBusStop:arrivalsAtBusStop) {
out += String.format(getResources().getString(R.string.passages), arrivalAtBusStop.getLineaGTT()) + "\n";
for(TimePassage timePassage:arrivalAtBusStop.getTimePassages()) {
out += "-\t" + timePassage.getTime() + (timePassage.isInRealTime() ? "*" : "") + "\n";
}
+
+ if(arrivalAtBusStop.getTimePassages().size() == 0) {
+ out += "\t :( \n";
+ }
+
out += "\n";
- done = true;
}
- annoyingFedbackProgressBar.setVisibility(View.INVISIBLE);
- result_textView.setText(out);
- if(!done) {
+
+ if(arrivalsAtBusStop.length == 0) {
Toast.makeText(getApplicationContext(), R.string.no_arrival_times, Toast.LENGTH_SHORT).show();
}
+
+ annoyingFedbackProgressBar.setVisibility(View.INVISIBLE);
+ result_textView.setText(out);
}
}
public void searchClick(View v) {
if (!NetworkTools.isConnected(this)) {
NetworkTools.showNetworkError(this);
} else {
annoyingFedbackProgressBar.setVisibility(View.VISIBLE);
new MyAsyncWget().execute(GTTSiteSucker.arrivalTimesByLineQuery(bus_stop_number_editText.getText().toString()));
}
}
}