Ejemplo n.º 1
0
 @Override
 public Uri insert(Uri uri, ContentValues values) {
   final SQLiteDatabase db = dbHelper.getWritableDatabase();
   final int match = uriMatcher.match(uri);
   Uri returnUri;
   switch (match) {
     case QUEUE:
       {
         long _id = db.replace(AlexandriaContract.QueueEntry.TABLE_NAME, null, values);
         if (_id > 0) {
           returnUri = AlexandriaContract.QueueEntry.CONTENT_URI;
         } else {
           throw new android.database.SQLException("Failed to insert row into " + uri);
         }
         break;
       }
     case BOOK:
       {
         long _id = db.insert(AlexandriaContract.BookEntry.TABLE_NAME, null, values);
         if (_id > 0) {
           db.delete(
               AlexandriaContract.QueueEntry.TABLE_NAME,
               AlexandriaContract.QueueEntry._ID + " = '" + Long.toString(_id) + "'",
               null);
           returnUri = AlexandriaContract.BookEntry.buildBookUri(_id);
         } else {
           throw new android.database.SQLException("Failed to insert row into " + uri);
         }
         getContext()
             .getContentResolver()
             .notifyChange(AlexandriaContract.BookEntry.buildFullBookUri(_id), null);
         getContext()
             .getContentResolver()
             .notifyChange(AlexandriaContract.BookEntry.CONTENT_URI, null);
         break;
       }
     case AUTHOR:
       {
         long _id = db.insert(AlexandriaContract.AuthorEntry.TABLE_NAME, null, values);
         if (_id > 0)
           returnUri = AlexandriaContract.AuthorEntry.buildAuthorUri(values.getAsLong("_id"));
         else throw new android.database.SQLException("Failed to insert row into " + uri);
         break;
       }
     case CATEGORY:
       {
         long _id = db.insert(AlexandriaContract.CategoryEntry.TABLE_NAME, null, values);
         if (_id > 0)
           returnUri = AlexandriaContract.CategoryEntry.buildCategoryUri(values.getAsLong("_id"));
         else throw new android.database.SQLException("Failed to insert row into " + uri);
         break;
       }
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   return returnUri;
 }
Ejemplo n.º 2
0
 @Override
 public android.support.v4.content.Loader<Cursor> onCreateLoader(int id, Bundle args) {
   return new CursorLoader(
       getActivity(),
       AlexandriaContract.BookEntry.buildFullBookUri(Long.parseLong(ean)),
       null,
       null,
       null,
       null);
 }
Ejemplo n.º 3
0
 @Override
 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
   if (eanEditText.getText().length() == 0) {
     return null;
   }
   String eanStr = eanEditText.getText().toString();
   if (eanStr.length() == 10 && !eanStr.startsWith("978")) {
     eanStr = "978" + eanStr;
   }
   return new CursorLoader(
       getActivity(),
       AlexandriaContract.BookEntry.buildFullBookUri(Long.parseLong(eanStr)),
       null,
       null,
       null,
       null);
 }