Esempio n. 1
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();
    }
  }
  @Click(R.id.bt_activity_advice)
  public void sendAdvice() {
    if (mEditTextAdvice.getText().toString().equals("")) {
      CustomToast.showToast(AdviceActivity.this, "意见不能为空", 2000);
      return;
    }
    progressBar.show();
    AVObject backAdvice = new AVObject("advice");
    backAdvice.put("usernumb", Application.user.getId());
    backAdvice.put("username", Application.user.getName());
    backAdvice.put("From", Application.user.getFromData());
    backAdvice.put("To", Application.user.getToData());
    backAdvice.put("Department", Application.user.getDepartment());
    backAdvice.put("advice", mEditTextAdvice.getText().toString());
    backAdvice.saveInBackground(
        new SaveCallback() {

          @Override
          public void done(AVException e) {
            if (e == null) {
              handler.sendEmptyMessage(0x0001);
            } else {
              handler.sendEmptyMessage(0x0002);
            }
          }
        });
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.action_collect:
        showToast("收藏");
        AVUser user = AVUser.getCurrentUser();
        final AVObject collect = new AVObject("user_collect");
        collect.put("user", user);
        collect.put("event", mDream);
        collect.saveInBackground(
            new SaveCallback() {
              @Override
              public void done(AVException e) {
                if (e == null) {
                  showToast("收藏成功");
                  mDream.increment("collectNum");
                  mDream.saveInBackground();
                }
              }
            });
        break;

      case R.id.action_share:
        showToast("分享");
        break;
      case android.R.id.home:
        finish();
        break;
    }

    return super.onOptionsItemSelected(item);
  }
Esempio n. 4
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();
    }
  }
  @Click(R.id.id_btn_join)
  void join() {

    AVUser user = AVUser.getCurrentUser();
    final AVObject object = new AVObject("user_join");
    object.put("user", user);
    object.put("dream", mDream);
    object.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(AVException e) {
            if (e == null) {
              showToast("保存成功");
              mDream.increment("joinNum");
              mDream.saveInBackground();
            }
          }
        });
  }