예제 #1
0
 public Observable<List<Message>> fetchMessageByType(Message.Type type) {
   return Observable.create(
       subscriber -> {
         if (!isClosed()) {
           List<Message> messages = null;
           final String whereClause = "message_type = ?";
           try {
             messages =
                 cupboard()
                     .withDatabase(getReadableDatabase())
                     .query(Message.class)
                     .withSelection(whereClause, type.name())
                     .orderBy("messages_date DESC")
                     .list();
           } catch (Exception e) {
             subscriber.onError(e);
           }
           if (messages != null) {
             subscriber.onNext(messages);
             subscriber.onCompleted();
           } else {
             subscriber.onError(new MessageNotFoundException());
           }
         } else {
           subscriber.onError(new Exception());
         }
       });
 }
예제 #2
0
 public List<Message> fetchMessage(Message.Type type) {
   List<Message> messages = new ArrayList<Message>();
   final String whereClause = "message_type = ?";
   try {
     messages =
         cupboard()
             .withDatabase(getReadableDatabase())
             .query(Message.class)
             .withSelection(whereClause, type.name())
             .orderBy("messages_date DESC")
             .list();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return messages;
 }