コード例 #1
0
  public static List<CompanyPost> findCompanyPost(
      int skip, int limit, String dateString, String cityName) throws AVException {

    AVQuery<CompanyPost> q = CompanyPost.getQuery(CompanyPost.class);
    // hehe 还好哟示例
    // TODO  这里如果include user 其他用户没法发布评论啊....尼玛啊  但是为什么能取到ObjectId呢啊啊啊啊,ffff  这里查到了是不是要保存到cache里边啊?!
    q.include(CompanyPost.USER);
    q.include(CompanyPost.COMMENT);
    if (dateString != null && !dateString.isEmpty()) {
      Date startDate;
      Date endDate;
      Date nowDate = new Date();
      try {
        startDate = DateUtils.getFirstDayOfMonth(dateString, "yyyy-MM-dd");
        // 必须比今天要早不是么...
        if (nowDate.getTime() > startDate.getTime()) {
          startDate = nowDate;
        }
        endDate = DateUtils.getLastDayOfMonth(dateString, "yyyy-MM-dd");
      } catch (Exception e) {
        e.printStackTrace();
        return new ArrayList<>();
      }
      q.whereGreaterThan("datePlanned", startDate);
      q.whereLessThan("datePlanned", endDate);
    }

    if (cityName != null && !cityName.isEmpty()) {
      q.whereEqualTo("destination", cityName);
    }
    q.skip(skip);
    q.limit(limit);
    q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
    q.orderByDescending(AVObject.CREATED_AT);
    List<CompanyPost> posts = q.find();
    for (int i = 0; i < posts.size(); i++) {
      CacheService.registerUser((LeanchatUser) posts.get(i).getPublisher());
    }
    return posts;
  }
コード例 #2
0
 public static void findFriendsWithCachePolicy(
     AVQuery.CachePolicy cachePolicy, FindCallback<AVUser> findCallback) {
   AVUser curUser = AVUser.getCurrentUser();
   AVQuery<AVUser> q = null;
   try {
     q = curUser.followeeQuery(AVUser.class);
   } catch (Exception e) {
     throw new NullPointerException();
   }
   q.setCachePolicy(cachePolicy);
   q.include("followee");
   q.findInBackground(findCallback);
 }
コード例 #3
0
 private void loadData() {
   AVQuery<AVObject> query = new AVQuery<AVObject>("dream");
   query.whereEqualTo("objectId", objectId);
   query.include("user");
   query.findInBackground(
       new FindCallback<AVObject>() {
         @Override
         public void done(List<AVObject> list, AVException e) {
           if (e == null) {
             if (list.size() == 1) {
               mDream = list.get(0);
               showToast("数据加载完毕");
             }
           }
         }
       });
 }