Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/AppDataProvider.java
Show All 20 Lines | |||||
import android.database.Cursor; | import android.database.Cursor; | ||||
import android.database.sqlite.SQLiteConstraintException; | import android.database.sqlite.SQLiteConstraintException; | ||||
import android.database.sqlite.SQLiteDatabase; | import android.database.sqlite.SQLiteDatabase; | ||||
import android.net.Uri; | import android.net.Uri; | ||||
import android.util.Log; | import android.util.Log; | ||||
import it.reyboz.bustorino.BuildConfig; | import it.reyboz.bustorino.BuildConfig; | ||||
import it.reyboz.bustorino.backend.DBStatusManager; | import it.reyboz.bustorino.backend.DBStatusManager; | ||||
import it.reyboz.bustorino.backend.Stop; | |||||
import it.reyboz.bustorino.data.NextGenDB.Contract.*; | import it.reyboz.bustorino.data.NextGenDB.Contract.*; | ||||
import java.util.List; | import java.util.List; | ||||
import static it.reyboz.bustorino.data.UserDB.getFavoritesColumnNamesAsArray; | |||||
public class AppDataProvider extends ContentProvider { | public class AppDataProvider extends ContentProvider { | ||||
public static final String AUTHORITY = BuildConfig.APPLICATION_ID +".provider"; | public static final String AUTHORITY = BuildConfig.APPLICATION_ID +".provider"; | ||||
private static final int STOP_OP = 1; | private static final int STOP_OP = 1; | ||||
private static final int LINE_OP = 2; | private static final int LINE_OP = 2; | ||||
private static final int BRANCH_OP = 3; | private static final int BRANCH_OP = 3; | ||||
private static final int FAVORITES_OP =4; | private static final int FAVORITES_OP =4; | ||||
private static final int MANY_STOPS = 5; | private static final int MANY_STOPS = 5; | ||||
private static final int ADD_UPDATE_BRANCHES = 6; | private static final int ADD_UPDATE_BRANCHES = 6; | ||||
private static final int LINE_INSERT_OP = 7; | private static final int LINE_INSERT_OP = 7; | ||||
private static final int CONNECTIONS = 8; | private static final int CONNECTIONS = 8; | ||||
private static final int LOCATION_SEARCH = 9; | private static final int LOCATION_SEARCH = 9; | ||||
private static final int GET_ALL_FAVORITES =10; | |||||
public static final String FAVORITES = "favorites"; | |||||
private static final String DEBUG_TAG="AppDataProvider"; | private static final String DEBUG_TAG="AppDataProvider"; | ||||
private Context con; | private Context con; | ||||
private NextGenDB appDBHelper; | private NextGenDB appDBHelper; | ||||
private UserDB userDBHelper; | private UserDB userDBHelper; | ||||
private SQLiteDatabase db; | private SQLiteDatabase db; | ||||
private DBStatusManager preferences; | private DBStatusManager preferences; | ||||
public AppDataProvider() { | public AppDataProvider() { | ||||
Show All 16 Lines | static { | ||||
*/ | */ | ||||
sUriMatcher.addURI(AUTHORITY, "line/#", LINE_OP); | sUriMatcher.addURI(AUTHORITY, "line/#", LINE_OP); | ||||
sUriMatcher.addURI(AUTHORITY,"branch/#",BRANCH_OP); | sUriMatcher.addURI(AUTHORITY,"branch/#",BRANCH_OP); | ||||
sUriMatcher.addURI(AUTHORITY,"line/insert",LINE_INSERT_OP); | sUriMatcher.addURI(AUTHORITY,"line/insert",LINE_INSERT_OP); | ||||
sUriMatcher.addURI(AUTHORITY,"branches",ADD_UPDATE_BRANCHES); | sUriMatcher.addURI(AUTHORITY,"branches",ADD_UPDATE_BRANCHES); | ||||
sUriMatcher.addURI(AUTHORITY,"connections",CONNECTIONS); | sUriMatcher.addURI(AUTHORITY,"connections",CONNECTIONS); | ||||
sUriMatcher.addURI(AUTHORITY,"favorites/#",FAVORITES_OP); | sUriMatcher.addURI(AUTHORITY,"favorites/#",FAVORITES_OP); | ||||
sUriMatcher.addURI(AUTHORITY,FAVORITES,GET_ALL_FAVORITES); | |||||
} | } | ||||
@Override | @Override | ||||
public int delete(Uri uri, String selection, String[] selectionArgs) { | public int delete(Uri uri, String selection, String[] selectionArgs) { | ||||
// Implement this to handle requests to delete one or more rows. | // Implement this to handle requests to delete one or more rows. | ||||
db = appDBHelper.getWritableDatabase(); | db = appDBHelper.getWritableDatabase(); | ||||
int rows; | int rows; | ||||
switch (sUriMatcher.match(uri)){ | switch (sUriMatcher.match(uri)){ | ||||
case MANY_STOPS: | case MANY_STOPS: | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | public Cursor query(Uri uri, String[] projection, String selection, | ||||
} | } | ||||
else { | else { | ||||
Log.w(DEBUG_TAG,"Not enough parameters"); | Log.w(DEBUG_TAG,"Not enough parameters"); | ||||
if(parts.size()>=5) for(String s:parts) Log.d(DEBUG_TAG,"\t element "+parts.indexOf(s)+" is: "+s); | if(parts.size()>=5) for(String s:parts) Log.d(DEBUG_TAG,"\t element "+parts.indexOf(s)+" is: "+s); | ||||
return null; | return null; | ||||
} | } | ||||
case FAVORITES_OP: | case FAVORITES_OP: | ||||
final String stopFavSelection = UserDB.getFavoritesColumnNamesAsArray[0]+" = ?"; | final String stopFavSelection = getFavoritesColumnNamesAsArray[0]+" = ?"; | ||||
db = userDBHelper.getReadableDatabase(); | db = userDBHelper.getReadableDatabase(); | ||||
Log.d(DEBUG_TAG,"Asked information on Favorites about stop with id "+uri.getLastPathSegment()); | Log.d(DEBUG_TAG,"Asked information on Favorites about stop with id "+uri.getLastPathSegment()); | ||||
return db.query(UserDB.TABLE_NAME,projection,stopFavSelection,new String[]{uri.getLastPathSegment()},null,null,sortOrder); | return db.query(UserDB.TABLE_NAME,projection,stopFavSelection,new String[]{uri.getLastPathSegment()},null,null,sortOrder); | ||||
case STOP_OP: | case STOP_OP: | ||||
//Let's try this plain and simple | //Let's try this plain and simple | ||||
final String[] selectionValues = {uri.getLastPathSegment()}; | final String[] selectionValues = {uri.getLastPathSegment()}; | ||||
final String stopSelection = StopsTable.COL_ID+" = ?"; | final String stopSelection = StopsTable.COL_ID+" = ?"; | ||||
Log.d(DEBUG_TAG,"Asked information about stop with id "+selectionValues[0]); | Log.d(DEBUG_TAG,"Asked information about stop with id "+selectionValues[0]); | ||||
return db.query(StopsTable.TABLE_NAME,projection,stopSelection,selectionValues,null,null,sortOrder); | return db.query(StopsTable.TABLE_NAME,projection,stopSelection,selectionValues,null,null,sortOrder); | ||||
case MANY_STOPS: | |||||
return db.query(StopsTable.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); | |||||
case GET_ALL_FAVORITES: | |||||
db = userDBHelper.getReadableDatabase(); | |||||
return db.query(UserDB.TABLE_NAME, projection, selection, selectionArgs, null, null,sortOrder); | |||||
default: | default: | ||||
Log.d("DataProvider","got request "+uri.getPath()+" which doesn't match anything"); | Log.e("DataProvider","got request "+uri.getPath()+" which doesn't match anything"); | ||||
} | } | ||||
throw new UnsupportedOperationException("Not yet implemented"); | throw new UnsupportedOperationException("Not yet implemented"); | ||||
} | } | ||||
@Override | @Override | ||||
public int update(Uri uri, ContentValues values, String selection, | public int update(Uri uri, ContentValues values, String selection, | ||||
String[] selectionArgs) { | String[] selectionArgs) { | ||||
Show All 16 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register