special treatments for AirBerlin

This commit is contained in:
ligi 2013-12-26 01:15:16 +01:00
parent 9c34d8d6ac
commit 34f820add4
6 changed files with 82 additions and 17 deletions

View file

@ -2,11 +2,30 @@ package org.ligi.passandroid.model;
public class PassLocation {
private final Passbook connectedPass;
private String description;
public PassLocation(Passbook connectedPass) {
this.connectedPass = connectedPass;
}
public String getDescription() {
if (description == null) {
// fallback for passes with locations without description - e.g. AirBerlin
return connectedPass.getDescription();
}
return description;
}
public void setDescription(String description) {
this.description = description;
}
public LatLng latlng = new LatLng();
public class LatLng {
public double lat;
public double lon;
}
public LatLng latlng = new LatLng();
public String description = "";
}

View file

@ -42,13 +42,19 @@ public class PassStore {
refreshPassesList();
}
public void deleteCache() {
String[] passIdents = getPassesDirSafely().list(new DirectoryFileFilter());
for (String id : passIdents) {
new File(path + "/" + id + "/base_cache.obj").delete();
}
}
public void refreshPassesList() {
path = TicketDefinitions.getPassesDir(context);
File passes_dir = new File(TicketDefinitions.getPassesDir(context));
if (!passes_dir.exists()) {
passes_dir.mkdirs();
}
File passes_dir = getPassesDirSafely();
String[] passIdents = passes_dir.list(new DirectoryFileFilter());
reducedPassInformations = new ArrayList<ReducedPassInformation>();
@ -72,6 +78,15 @@ public class PassStore {
}
private File getPassesDirSafely() {
File passes_dir = new File(TicketDefinitions.getPassesDir(context));
if (!passes_dir.exists()) {
passes_dir.mkdirs();
}
return passes_dir;
}
public int passCount() {
return reducedPassInformations.size();
}

View file

@ -121,10 +121,14 @@ public class Passbook {
for (int i = 0; i < locations_json.length(); i++) {
JSONObject obj = locations_json.getJSONObject(i);
PassLocation location = new PassLocation();
PassLocation location = new PassLocation(this);
location.latlng.lat = obj.getDouble("latitude");
location.latlng.lon = obj.getDouble("longitude");
location.description = obj.getString("relevantText");
if (obj.has("relevantText")) {
location.setDescription(obj.getString("relevantText"));
}
locations.add(location);
}
} catch (JSONException e) {
@ -183,6 +187,30 @@ public class Passbook {
headerFields = getFieldListFromJsonArr(eventTicket, "headerFields");
// for airberlin
if (description.equals("boardcard")) {
final String flight_regex = "\\b\\w{1,3}\\d{3,4}\\b";
final String seat_regex = "\\b\\d\\d?\\w\\b ";
for (Field f : headerFields) {
if (f.label.matches(flight_regex)) {
description = f.label + " " + f.value;
}
}
for (Field f : auxiliaryFields) {
if (f.key != null && f.key.equals("seat")) {
description += " | " + f.label + " " + f.value;
}
}
for (Field f : secondaryFields) {
if (f.key != null && f.key.equals("boardingGroup")) {
description += " | " + f.label + " " + f.value;
}
}
}
}
public String findType(JSONObject obj) {
@ -264,8 +292,12 @@ public class Passbook {
for (int i = 0; i < arr.length(); i++) {
Field f = new Field();
try {
f.label = arr.getJSONObject(i).getString("label");
f.value = arr.getJSONObject(i).getString("value");
final JSONObject jsonObject = arr.getJSONObject(i);
f.label = jsonObject.getString("label");
f.value = jsonObject.getString("value");
if (jsonObject.has("key")) {
f.key = jsonObject.getString("key");
}
res.add(f);
} catch (JSONException e) {
e.printStackTrace();
@ -409,6 +441,7 @@ public class Passbook {
}
public class Field {
public String key;
public String label;
public String value;
}

View file

@ -30,7 +30,7 @@ public class NavigateToLocationsDialog {
int i = 0;
for (PassLocation loc : locations) {
locationDescriptions[i++] = loc.description;
locationDescriptions[i++] = loc.getDescription();
}
new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.choose_location)).setItems(locationDescriptions, new DialogInterface.OnClickListener() {
@Override
@ -58,7 +58,7 @@ public class NavigateToLocationsDialog {
String description = "";
try {
description = URLEncoder.encode(location.description, "UTF-8");
description = URLEncoder.encode(location.getDescription(), "UTF-8");
} catch (UnsupportedEncodingException e1) {
// OK - no descripion
}

View file

@ -181,6 +181,7 @@ public class TicketListActivity extends ActionBarActivity {
.listener(new OnRefreshListener() {
@Override
public void onRefreshStarted(View view) {
App.getPassStore().deleteCache();
new ScanForPassesTask().execute();
}
})

View file

@ -18,7 +18,6 @@ import com.google.android.gms.maps.model.MarkerOptions;
import org.ligi.passandroid.model.PassLocation;
import org.ligi.passandroid.ui.TicketViewActivityBase;
import org.ligi.tracedroid.logging.Log;
import java.util.List;
@ -57,18 +56,16 @@ public class LocationsMapFragment extends SupportMapFragment {
if (locations.size() > 0) {
for (PassLocation l : locations) {
Log.i("adding marker" + l.latlng);
// yea that looks stupid but need to split LatLng free/nonfree - google play services ^^
LatLng latLng = new LatLng(l.latlng.lat, l.latlng.lon);
mMap.addMarker(new MarkerOptions()
.position(latLng)
.title(l.description)
.title(l.getDescription())
//.icon(BitmapDescriptorFactory.fromBitmap(base_activity.passbook.getIconBitmap())));
);
boundser = boundser.include(latLng);
Log.i("added marker");
}
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {