Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/AppDataProvider.java
- This file was moved from src/it/reyboz/bustorino/middleware/AppDataProvider.java.
Show All 9 Lines | BusTO (middleware) | ||||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | ||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
GNU General Public License for more details. | GNU General Public License for more details. | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
package it.reyboz.bustorino.middleware; | package it.reyboz.bustorino.data; | ||||
import android.content.*; | import android.content.*; | ||||
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.middleware.NextGenDB.Contract.*; | import it.reyboz.bustorino.data.NextGenDB.Contract.*; | ||||
import java.util.List; | import java.util.List; | ||||
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 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 udbhelper; | private UserDB userDBHelper; | ||||
private SQLiteDatabase db; | private SQLiteDatabase db; | ||||
private DBStatusManager preferences; | private DBStatusManager preferences; | ||||
public AppDataProvider() { | public AppDataProvider() { | ||||
} | } | ||||
private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); | private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); | ||||
static { | static { | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | public Uri insert(Uri uri, ContentValues values) throws IllegalArgumentException{ | ||||
finalUri = ContentUris.withAppendedId(uri,last_rowid); | finalUri = ContentUris.withAppendedId(uri,last_rowid); | ||||
return finalUri; | return finalUri; | ||||
} | } | ||||
@Override | @Override | ||||
public boolean onCreate() { | public boolean onCreate() { | ||||
con = getContext(); | con = getContext(); | ||||
appDBHelper = new NextGenDB(getContext()); | appDBHelper = new NextGenDB(getContext()); | ||||
udbhelper = new UserDB(getContext()); | userDBHelper = new UserDB(getContext()); | ||||
if(con!=null) { | if(con!=null) { | ||||
preferences = new DBStatusManager(con,null); | preferences = new DBStatusManager(con,null); | ||||
} else { | } else { | ||||
preferences = null; | preferences = null; | ||||
Log.e(DEBUG_TAG,"Cannot get shared preferences"); | Log.e(DEBUG_TAG,"Cannot get shared preferences"); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
Show All 30 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 = UserDB.getFavoritesColumnNamesAsArray[0]+" = ?"; | ||||
db = udbhelper.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); | ||||
Show All 26 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