Ejemplo n.º 1
0
 public Single<List<LocationRecord>> getLocationRecordList() {
   return Single.create(
       singleSubscriber -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           List<LocationRecord> result = new ArrayList<>();
           Cursor unsentCursor =
               mBriteDatabase.query("SELECT * FROM " + LocalUnsentLocationRecordTable.NAME);
           Cursor sentCursor =
               mBriteDatabase.query("SELECT * FROM " + RemoteLocationRecordTable.NAME);
           if (!singleSubscriber.isUnsubscribed()) {
             while (sentCursor.moveToNext()) {
               result.add(RemoteLocationRecordTable.parseCursor(sentCursor));
             }
           }
           if (!singleSubscriber.isUnsubscribed()) {
             while (unsentCursor.moveToNext()) {
               result.add(LocalUnsentLocationRecordTable.parseCursor(unsentCursor));
             }
           }
           unsentCursor.close();
           sentCursor.close();
           singleSubscriber.onSuccess(result);
         } finally {
           transaction.end();
         }
       });
 }
Ejemplo n.º 2
0
 @Provides
 @Singleton
 BriteDatabase provideDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) {
   BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
   db.setLoggingEnabled(true);
   return db;
 }
Ejemplo n.º 3
0
 public Completable addUnsentLocationRecord(LocationRecord locationRecord) {
   return Completable.create(
       subscribe -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           mBriteDatabase.insert(
               LocalUnsentLocationRecordTable.NAME,
               LocalUnsentLocationRecordTable.toContentValues(locationRecord));
           transaction.markSuccessful();
           subscribe.onCompleted();
         } finally {
           transaction.end();
         }
       });
 }
Ejemplo n.º 4
0
 public Observable<Void> saveToSentLocationsTable(List<LocationRecord> locationRecords) {
   return Observable.create(
       subscriber -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           mBriteDatabase.delete(RemoteLocationRecordTable.NAME, null);
           for (LocationRecord locationRecord : locationRecords) {
             mBriteDatabase.insert(
                 RemoteLocationRecordTable.NAME,
                 RemoteLocationRecordTable.toContentValues(locationRecord));
           }
           transaction.markSuccessful();
           subscriber.onCompleted();
         } finally {
           transaction.end();
         }
       });
 }
Ejemplo n.º 5
0
 public Completable clearTables() {
   return Completable.create(
       subscribe -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           Cursor cursor =
               mBriteDatabase.query("SELECT name FROM sqlite_master WHERE type='table'");
           while (cursor.moveToNext()) {
             mBriteDatabase.delete(cursor.getString(cursor.getColumnIndex("name")), null);
           }
           cursor.close();
           transaction.markSuccessful();
           subscribe.onCompleted();
         } finally {
           transaction.end();
         }
       });
 }
Ejemplo n.º 6
0
  @Override
  public void onResume() {
    super.onResume();

    getActivity().setTitle("To-Do");

    subscription =
        db.createQuery(ListsItem.TABLES, ListsItem.QUERY)
            .mapToList(ListsItem.MAPPER)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(adapter);
  }
Ejemplo n.º 7
0
 public Observable<UnsentAndResponseLocationRecordPair> moveLocationRecordToSent(
     UnsentAndResponseLocationRecordPair unsentAndFromResponse) {
   return Observable.create(
       subscriber -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           mBriteDatabase.delete(
               LocalUnsentLocationRecordTable.NAME,
               LocalUnsentLocationRecordTable.COLUMN_ID + "= ?",
               Integer.toString(unsentAndFromResponse.getUnsentLocationRecord().getId()));
           mBriteDatabase.insert(
               RemoteLocationRecordTable.NAME,
               RemoteLocationRecordTable.toContentValues(
                   unsentAndFromResponse.getLocationRecordFromResponse()));
           subscriber.onNext(unsentAndFromResponse);
           transaction.markSuccessful();
           subscriber.onCompleted();
         } finally {
           transaction.end();
         }
       });
 }
Ejemplo n.º 8
0
 public Observable<LocationRecord> getUnsentLocationRecords() {
   return Observable.create(
       subscriber -> {
         Cursor cursor =
             mBriteDatabase.query("SELECT * FROM " + LocalUnsentLocationRecordTable.NAME);
         if (!subscriber.isUnsubscribed()) {
           while (cursor.moveToNext()) {
             subscriber.onNext(LocalUnsentLocationRecordTable.parseCursor(cursor));
           }
         }
         cursor.close();
         subscriber.onCompleted();
       });
 }