use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method createBahnhofFromCursor.
@NonNull
private Bahnhof createBahnhofFromCursor(@NonNull Cursor cursor) {
String title = cursor.getString(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_TITLE));
int bahnhofsnr = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_ID));
Double lon = cursor.getDouble(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_LON));
Double lat = cursor.getDouble(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_LAT));
String photoflag = cursor.getString(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG));
Bahnhof bahnhof = new Bahnhof();
bahnhof.setTitle(title);
bahnhof.setId(bahnhofsnr);
bahnhof.setLat(lat);
bahnhof.setLon(lon);
bahnhof.setPhotoflag(photoflag);
return bahnhof;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method getBahnhoefeByLatLngRectangle.
// Getting All Bahnhoefe
public List<Bahnhof> getBahnhoefeByLatLngRectangle(LatLng position, boolean withPhoto) {
double lat = position.latitude;
double lng = position.longitude;
List<Bahnhof> bahnhofList = new ArrayList<Bahnhof>();
// Select All Query with rectangle - might be later change with it
String selectQuery = "SELECT " + KEY_ID + ", " + Constants.DB_JSON_CONSTANTS.KEY_TITLE + ", " + Constants.DB_JSON_CONSTANTS.KEY_LAT + ", " + Constants.DB_JSON_CONSTANTS.KEY_LON + ", " + Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG + " FROM " + DATABASE_TABLE + " where " + Constants.DB_JSON_CONSTANTS.KEY_LAT + " < " + (lat + 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LAT + " > " + (lat - 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LON + " < " + (lng + 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LON + " > " + (lng - 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG + " IS " + (withPhoto ? "NOT" : "") + " NULL";
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Bahnhof bahnhof = createBahnhofFromCursor(cursor);
// Adding bahnhof to list
bahnhofList.add(bahnhof);
} while (cursor.moveToNext());
}
cursor.close();
// returns bahnhof list
return bahnhofList;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method insertBahnhoefe.
public void insertBahnhoefe(List<Bahnhof> bahnhoefe) {
if (bahnhoefe.isEmpty()) {
// nothing todo
return;
}
// soll die Performance verbessern, heißt's.
db.beginTransaction();
try {
deleteBahnhoefe();
for (Bahnhof bahnhof : bahnhoefe) {
ContentValues values = new ContentValues();
values.put(KEY_ID, bahnhof.getId());
values.put(Constants.DB_JSON_CONSTANTS.KEY_TITLE, bahnhof.getTitle());
values.put(Constants.DB_JSON_CONSTANTS.KEY_LAT, bahnhof.getLat());
values.put(Constants.DB_JSON_CONSTANTS.KEY_LON, bahnhof.getLon());
values.put(Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG, bahnhof.getPhotoflag());
db.insert(DATABASE_TABLE, null, values);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method fetchBahnhofByRowId.
public Bahnhof fetchBahnhofByRowId(long id) {
Cursor cursor = db.query(DATABASE_TABLE, null, Constants.DB_JSON_CONSTANTS.KEY_ROWID + "=?", new String[] { id + "" }, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
Bahnhof bahnhof = createBahnhofFromCursor(cursor);
cursor.close();
return bahnhof;
} else
return null;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class MapsActivity method onInfoWindowClick.
@Override
public void onInfoWindowClick(Marker marker) {
BaseApplication baseApplication = (BaseApplication) getApplication();
String countryShortCode = baseApplication.getCountryShortCode();
if (marker.getSnippet() != null) {
Class cls = DetailsActivity.class;
Intent intent = new Intent(MapsActivity.this, cls);
long id = Long.valueOf(marker.getSnippet());
try {
Bahnhof bahnhof = dbAdapter.fetchBahnhofByBahnhofId(id);
intent.putExtra(DetailsActivity.EXTRA_BAHNHOF, bahnhof);
startActivity(intent);
} catch (RuntimeException e) {
Log.wtf(TAG, String.format("Could not fetch station id %s that we put onto the map", id), e);
}
} else {
marker.hideInfoWindow();
}
}
Aggregations