Search in sources :

Example 6 with Bahnhof

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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) NonNull(android.support.annotation.NonNull)

Example 7 with 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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 8 with Bahnhof

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();
    }
}
Also used : ContentValues(android.content.ContentValues) Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof)

Example 9 with Bahnhof

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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) Cursor(android.database.Cursor)

Example 10 with Bahnhof

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();
    }
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) Intent(android.content.Intent)

Aggregations

Bahnhof (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof)13 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 LatLng (com.google.android.gms.maps.model.LatLng)2 ArrayList (java.util.ArrayList)2 ContentValues (android.content.ContentValues)1 NonNull (android.support.annotation.NonNull)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1 Window (android.view.Window)1 GridView (android.widget.GridView)1 ListView (android.widget.ListView)1 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)1