/**
  * 异步从云端分页查询辅食
  *
  * @param page 第几页(从0开始)
  * @param per 每页显示数量
  * @param callback 回调接口
  */
 public void findSuppsFromCloud(
     final int page, final int per, final FindCallback<Supplement> callback) {
   query.orderByAscending(FIND_SORT);
   query.whereNotEqualTo("isDel", true);
   query.setSkip(page * per);
   query.findInBackground(callback);
 }
Esempio n. 2
0
  /**
   * 将用户名为username的用户从群中删除,同时在用户列表中删除群的信息
   *
   * @param username
   */
  public static void deleteMemberFromGroup(String username) {
    AVQuery<AVObject> query = new AVQuery<AVObject>("Group");
    try {
      sharegroup = query.get(groupid(username));
      // 获取群的id,并从用户列表中删除所在群的id,表明脱离群关系
      String objectid = sharegroup.getObjectId();
      groupShareid.remove(objectid);
      if (groupShareid != null && groupShareid.size() != 0) {
        LoginUtil.userinfo.put("groupsharedidsstr", Utils.strCombine(groupShareid));
      } else {
        LoginUtil.userinfo.put("groupsharedidsstr", "");
      }
      LoginUtil.userinfo.save();

      // 从群中删除用户的信息,如果群为空,则删除群
      String memberidsstr = sharegroup.getString("memberids"); // �获取所有群成员的id
      List<String> memberids = Utils.strParse(memberidsstr);
      for (String id : memberids) {
        if (id.equals(LoginUtil.userinfo.getObjectId())) {
          memberids.remove(id);
          break;
        }
      }
      if (memberids != null && memberids.size() != 0) {
        sharegroup.put("memberids", Utils.strCombine(memberids));
        sharegroup.save();
      } else {
        sharegroup.delete();
      }
    } catch (AVException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 3
0
  /** 删除单个用户名为username成员 */
  public static void deleteMember(String username) {
    AVObject person = new AVObject();
    AVQuery<AVObject> query1 = new AVQuery<AVObject>("UserInfo");
    try {
      person = query1.get(id(username));
      String singlesharedstr = person.getString("singlesharedidsstr");
      List<String> singleids = Utils.strParse(singlesharedstr);
      singleids.remove(LoginUtil.userinfo.getObjectId());

      // 从被动好友一方删除登陆用户
      if (singleids != null && singleids.size() != 0) {
        person.put("singlesharedidsstr", Utils.strCombine(singleids));
      } else {
        person.put("singlesharedidsstr", "");
      }
      person.save();
      // 从登陆用户列表中删除
      singleShareid.remove(person.getObjectId());
      if (singleShareid != null && singleShareid.size() != 0) {
        LoginUtil.userinfo.put("singlesharedidsstr", Utils.strCombine(singleShareid));
      } else {
        LoginUtil.userinfo.put("singlesharedidsstr", "");
      }
      LoginUtil.userinfo.save();

    } catch (AVException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 4
0
 public static void findUserInConversationAllInfo(
     String objectId, FindCallback<AVObject> callback) {
   AVQuery<AVObject> query = new AVQuery<AVObject>(USERINFO);
   query.whereEqualTo(OBJECTID, objectId);
   query.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
   query.findInBackground(callback);
 }
Esempio n. 5
0
 private void setSelectCourse(int position) {
   selectSubjectName = mSubjectModels.get(position).getSubjectName();
   selectSubjectId = mSubjectModels.get(position).getSubjectId();
   AVQuery<AVUser> mAvQuery = AVUser.getQuery();
   mAvQuery.whereEqualTo(
       "username",
       ShareTools.getInstance().readUserInfo(LoginInitMemory.this).get(ShareTools.USER_NAME));
   mAvQuery.findInBackground(
       new FindCallback<AVUser>() {
         @Override
         public void done(List<AVUser> arg0, AVException arg1) {
           // TODO Auto-generated method stub
           if (arg1 == null) {
             if (arg0 != null && !arg0.isEmpty()) {
               Message message = Message.obtain();
               message.what = 1000;
               message.obj = arg0.get(0);
               mHandler.sendMessage(message);
             } else {
               Toast.makeText(LoginInitMemory.this, "用户为空", Toast.LENGTH_SHORT).show();
             }
           } else {
             Log.e("ShareTools", arg1.getMessage());
           }
         }
       });
 }
 /**
  * 同步地从云端获得辅食信息
  *
  * @param page 页码
  * @param per 每页显示数
  * @return 辅食列表
  */
 public List<Supplement> findSuppsFromCloud(final int page, final int per) {
   query.orderByAscending(FIND_SORT);
   query.whereNotEqualTo("isDel", true);
   query.setSkip(page * per);
   try {
     return query.find();
   } catch (AVException e) {
     e.printStackTrace();
     return null;
   }
 }
 private UpdateInfo getNewestUpdateInfo() throws AVException {
   AVQuery<UpdateInfo> query = AVObject.getQuery(UpdateInfo.class);
   query.setLimit(1);
   query.orderByDescending(UpdateInfo.VERSION);
   if (policy != null) {
     query.setCachePolicy(policy);
   }
   List<UpdateInfo> updateInfos = query.find();
   if (updateInfos.size() > 0) {
     return updateInfos.get(0);
   }
   return null;
 }
Esempio n. 8
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);
 }
  private void queryFood(String queryString) {
    AVQuery<AVObject> query = new AVQuery<AVObject>(Food.CLASS_NAME);
    query.whereEqualTo(Food.CATEGORY, queryString);
    System.out.println("queryString:" + queryString);
    query.findInBackground(
        new FindCallback<AVObject>() {

          @Override
          public void done(List<AVObject> l, AVException e) {
            if (e == null) {
              mDialog.dismiss();
              set = new TreeSet<String>();
              int size = l.size();
              for (int i = 0; i < size; i++) {
                String restaurant = l.get(i).getString(Food.RESTURANT);
                set.add(restaurant);
              }
              int setSize = set.size();
              mActionBar.setSubtitle("共查找到" + setSize + "家商家");
              // restaurants = set.toArray(new String[set.size()]);
              /** 将Set转化成List */
              restaurants = new ArrayList<String>(set);
              foods = new ArrayList<List<AVObject>>();
              for (int i = 0; i < restaurants.size(); i++) {
                System.out.println(restaurants.get(i));
                List<AVObject> array = new ArrayList<AVObject>();
                for (int j = 0; j < size; j++) {
                  AVObject obj = l.get(j);
                  if (restaurants.get(i).equals(obj.getString(Food.RESTURANT))) {
                    array.add(obj);
                  }
                }
                foods.add(array);
              }
              adapter = new CategoryAdapter(CategorySearchActivity.this, restaurants, foods);
              mListView.setAdapter(adapter);
            } else {
              log.e("CategorySearchActivity", "按类查询获取数据异常", e);
              mDialog.dismiss();
              Toast.makeText(CategorySearchActivity.this, R.string.loading_fail, Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });
    mListView.setOnChildClickListener(this);
  }
 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("数据加载完毕");
             }
           }
         }
       });
 }
  private void addQueryRule(T anchor, boolean afterwards, int pageSize, AVQuery<T> query) {

    // set page size
    query.limit(pageSize);
    // before or after

    String queryOrder = query.getOrder();
    if ((anchor != null) && (queryOrder != null)) {
      boolean isDescending = queryOrder.startsWith("-");
      String field = isDescending ? queryOrder.substring(1) : queryOrder;
      if ((isDescending && afterwards) || (!isDescending && !afterwards)) {
        query.whereLessThan(field, anchor.get(field));
      } else {
        query.whereGreaterThan(field, anchor.get(field));
      }
    }
  }
  /** 从云端获取数据并加入本地的listView */
  private void getLeanCloudData() {
    // leanCloud数据读取

    AVQuery.doCloudQueryInBackground(
        "select * from " + swicthCategory(),
        new CloudQueryCallback<AVCloudQueryResult>() {

          @SuppressWarnings("null")
          @Override
          public void done(AVCloudQueryResult result, AVException cqlException) {

            List<String> names = new ArrayList<String>();

            if (cqlException == null) {
              for (int i = 0; i < result.getResults().size(); i++) {
                String categoryName = titleName;
                String name = result.getResults().get(i).getString("name");
                String remainDays = result.getResults().get(i).getString("remainDays");
                String kiloNum = result.getResults().get(i).getString("kiloNum");
                boolean state = result.getResults().get(i).getBoolean("state");
                Log.e("result: i", "" + name + remainDays + kiloNum);

                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("name", name);
                map.put("remainDays", remainDays);
                map.put("kiloNum", kiloNum);
                list.add(map);

                //  加入是否过期的物品
                if (!state) {
                  if (!names.isEmpty()) {
                    for (int j = 0; j < names.size(); j++) {
                      if (!names.get(i).equals(name)) {
                        names.add(name);
                      }
                    }
                  } else {
                    names.add(name);
                  }
                }
              }
              if (!names.isEmpty()) {
                createDialog(names, "过期提示");
              }
              // 适配器
              SimpleAdapter adapter =
                  new SimpleAdapter(
                      CategoryActivity.this,
                      list,
                      R.layout.category_list_item,
                      new String[] {"name", "remainDays", "kiloNum"},
                      new int[] {R.id.item_name, R.id.item_days, R.id.item_kilo_num});
              categoryListView.setAdapter(adapter);
            }
          }
        });
  }
Esempio n. 13
0
 public static boolean isNameLeagal(String groupname) {
   List<AVObject> avObjects;
   AVQuery<AVObject> singlequery = new AVQuery<AVObject>("UserInfo");
   AVQuery<AVObject> groupquery = new AVQuery<AVObject>("Group");
   singlequery.whereEqualTo("username", groupname);
   try {
     avObjects = singlequery.find();
     if (avObjects.size() != 0) {
       return false;
     }
   } catch (AVException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   groupquery.whereEqualTo("groupname", groupname);
   try {
     avObjects = groupquery.find();
     if (avObjects.size() != 0) {
       return false;
     }
   } catch (AVException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 14
0
 public static List<AVUser> searchUser(String searchName, int skip) throws AVException {
   AVQuery<AVUser> q = AVUser.getQuery(AVUser.class);
   q.whereContains(User.USERNAME, searchName);
   q.limit(Constant.PAGE_SIZE);
   q.skip(skip);
   AVUser user = AVUser.getCurrentUser();
   List<String> friendIds = new ArrayList<String>(CacheService.getFriendIds());
   friendIds.add(user.getObjectId());
   q.whereNotContainedIn(Constant.OBJECT_ID, friendIds);
   q.orderByDescending(Constant.UPDATED_AT);
   q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
   List<AVUser> users = q.find();
   CacheService.registerUsers(users);
   return users;
 }
 private void loadMoreFriend(int skip, final int limit, final boolean isRefresh) {
   AVQuery<LeanchatUser> q = LeanchatUser.getQuery(LeanchatUser.class);
   q.whereContains(LeanchatUser.USERNAME, searchName);
   q.limit(Constants.PAGE_SIZE);
   q.skip(skip);
   LeanchatUser user = LeanchatUser.getCurrentUser();
   List<String> friendIds = new ArrayList<String>(FriendsManager.getFriendIds());
   friendIds.add(user.getObjectId());
   q.whereNotContainedIn(Constants.OBJECT_ID, friendIds);
   q.orderByDescending(Constants.UPDATED_AT);
   q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
   q.findInBackground(
       new FindCallback<LeanchatUser>() {
         @Override
         public void done(List<LeanchatUser> list, AVException e) {
           UserCacheUtils.cacheUsers(list);
           recyclerView.setLoadComplete(list.toArray(), false);
         }
       });
 }
Esempio n. 16
0
/** SupplementDao Desc: 数据访问层--辅食 Team: InHand User: Wooxxx Date: 2015-07-27 Time: 21:03 */
public class SupplementDao {

  private AVQuery<Supplement> query = AVQuery.getQuery(Supplement.class);
  public static final String FIND_SORT = "sort";

  /**
   * 异步从云端分页查询辅食
   *
   * @param page 第几页(从0开始)
   * @param per 每页显示数量
   * @param callback 回调接口
   */
  public void findSuppsFromCloud(
      final int page, final int per, final FindCallback<Supplement> callback) {
    query.orderByAscending(FIND_SORT);
    query.whereNotEqualTo("isDel", true);
    query.setSkip(page * per);
    query.findInBackground(callback);
  }

  /**
   * 同步地从云端获得辅食信息
   *
   * @param page 页码
   * @param per 每页显示数
   * @return 辅食列表
   */
  public List<Supplement> findSuppsFromCloud(final int page, final int per) {
    query.orderByAscending(FIND_SORT);
    query.whereNotEqualTo("isDel", true);
    query.setSkip(page * per);
    try {
      return query.find();
    } catch (AVException e) {
      e.printStackTrace();
      return null;
    }
  }
}
  public void getOverdue() {
    AVQuery.doCloudQueryInBackground(
        "select * from overdue",
        new CloudQueryCallback<AVCloudQueryResult>() {

          @Override
          public void done(AVCloudQueryResult result, AVException e) {
            List<String> names = new ArrayList<String>();

            if (e == null) {
              for (int i = 0; i < result.getResults().size(); i++) {
                String name = result.getResults().get(i).getString("name");

                names.add(name);
              }

              if (!names.isEmpty()) {
                createDialog(names, "物品不足提示");
              }
            }
          }
        });
  }
  private void initData() {

    String friendUsername = getIntent().getStringExtra("username");
    mUsername.setText(friendUsername);
    mUserAcount.setText(getIntent().getStringExtra("email"));

    switch (getIntent().getStringExtra("gender")) {
      case "男":
        mGender.setImageDrawable(getResources().getDrawable(R.drawable.user_boy));
        break;

      case "女":
        mGender.setImageDrawable(getResources().getDrawable(R.drawable.user_girl));
        break;
    }

    // 用户头像(大图)
    AVQuery<AVObject> queryAvater = new AVQuery<AVObject>("Gender");
    queryAvater.whereEqualTo("username", friendUsername);
    queryAvater.findInBackground(findGenderCallback(this, mAvatar));

    AVQuery<AVObject> query = new AVQuery<AVObject>("UserInformation");
    query.whereEqualTo("username", friendUsername);
    query.findInBackground(
        new FindCallback<AVObject>() {
          public void done(List<AVObject> avObjects, AVException e) {
            if (e == null) {
              Message msg = new Message();
              msg.what = 1;
              msg.obj = avObjects;
              mFriendHandler.sendMessage(msg);
            } else {
              // Toast.makeText(AlterActivity.this, "请检查网络!",
              // Toast.LENGTH_LONG).show();
            }
          }
        });

    // 查找好友距离
    findLocation(AVUser.getCurrentUser().getUsername(), friendUsername);
  }
 private void addQueryRule(int pageIndex, int pageSize, AVQuery<T> query) {
   query.skip(pageIndex * pageSize).limit(pageSize);
 }
Esempio n. 20
0
  public static void init() {
    try {
      LoginUtil.userinfo.refresh();
    } catch (AVException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    String single = LoginUtil.userinfo.getString("singlesharedidsstr");
    if (single != null && single.length() != 0) {
      singleShareid = Utils.strParse(single);
    }
    String group = LoginUtil.userinfo.getString("groupsharedidsstr");
    if (group != null && group.length() != 0) {
      groupShareid = Utils.strParse(group);
    }
    List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
    AVQuery<AVObject> query = new AVQuery<AVObject>("UserInfo");
    AVQuery<AVObject> query1 = new AVQuery<AVObject>("Group");
    if (singleShareid == null && groupShareid == null) {
      return;
    } else {

      if (singleShareid != null && singleShareid.size() != 0) {
        singleShareName.clear();
        for (String shareid : singleShareid) {
          try {
            singleShareName.add(query.get(shareid).getString("username"));
          } catch (AVException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        for (String singlesharename : singleShareName) {
          HashMap<String, Object> item = new HashMap<String, Object>();
          item.put("name", singlesharename);
          data.add(item);
        }
      }
      if (groupShareid != null && groupShareid.size() != 0) {
        groupShareName.clear();
        for (String shareid : groupShareid) {
          try {
            query1.get(shareid).refresh();
            groupShareName.add(query1.get(shareid).getString("groupname"));
          } catch (AVException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        for (String groupsharename : groupShareName) {
          HashMap<String, Object> item = new HashMap<String, Object>();
          item.put("name", groupsharename);
          data.add(item);
        }
      }
      SimpleAdapter adapter =
          new SimpleAdapter(
              context, data, R.layout.item, new String[] {"name"}, new int[] {R.id.name});
      listview.setAdapter(adapter);
    }
  }
  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;
  }
Esempio n. 22
0
 public static AVUser findUser(String id) throws AVException {
   AVQuery<AVUser> q = AVUser.getQuery(AVUser.class);
   q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
   return q.get(id);
 }
Esempio n. 23
0
 public static void findUserUrl(String id, FindCallback<AVObject> call) throws AVException {
   AVQuery<AVObject> query = new AVQuery<AVObject>(USERINFO);
   query.whereEqualTo(USERID, id);
   query.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
   query.findInBackground(call); // q.get(id);
 }