/** 重新验证当前ChannelList是否是对的 */
  private void checkChannelList() {
    ArrayList<SubItem> groupSubItems = adapter.getSubLists().get(1);
    groupSubItems.clear();
    if (UserAPI.isLoggedIn()) {
      groupSubItems.add(
          new SubItem(SubItem.Section_Post, SubItem.Type_Private_Channel, "我的小组", "user_group"));
    }
    if (GroupHelper.getMyGroupsNumber() > 0) {
      // 如果已经加载了栏目
      groupSubItems.add(
          new SubItem(SubItem.Section_Post, SubItem.Type_Collections, "小组热贴", "hot_posts"));
      groupSubItems.addAll(GroupHelper.getSelectedGroupSubItems());
    } else {
      groupSubItems.addAll(ChannelHelper.getPosts());
    }

    ArrayList<SubItem> questionSubItems = adapter.getSubLists().get(2);
    questionSubItems.clear();
    if (AskTagHelper.getAskTagsNumber() > 0) {
      // 如果已经加载了栏目
      questionSubItems.add(
          new SubItem(SubItem.Section_Question, SubItem.Type_Collections, "热门问答", "hottest"));
      questionSubItems.add(
          new SubItem(SubItem.Section_Question, SubItem.Type_Collections, "精彩回答", "highlight"));
      questionSubItems.addAll(AskTagHelper.getSelectedQuestionSubItems());
    } else {
      questionSubItems.addAll(ChannelHelper.getQuestions());
    }
    adapter.notifyDataSetInvalidated();
  }
Ejemplo n.º 2
0
 private void mergeMyGroups(ArrayList<AskTag> myTags) {
   if (AskTagHelper.getAskTagsNumber() > 0) {
     List<AskTag> selectedGroups = AskTagHelper.getSelectedTags();
     for (int i = 0; i < myTags.size(); i++) {
       AskTag tmpTag = myTags.get(i);
       boolean selected = false;
       for (int j = 0; j < selectedGroups.size(); j++) {
         if (selectedGroups.get(j).getValue().equals(tmpTag.getValue())) {
           selected = true;
           break;
         }
       }
       tmpTag.setSelected(selected);
       if (selected) {
         tmpTag.setOrder(i);
       } else {
         tmpTag.setOrder(1024 + i);
       }
     }
   }
 }
  private void recheckData() {
    if (isFirstLoad) {
      if (UserAPI.isLoggedIn()) {
        String nameString = SharedPreferencesUtil.readString(Consts.Key_User_Name, "");
        if (!TextUtils.isEmpty(nameString)) {
          userName.setText(nameString);
        }
        String avatarString = SharedPreferencesUtil.readString(Consts.Key_User_Avatar, "");
        if (!TextUtils.isEmpty(avatarString)) {
          if (Config.shouldLoadImage()) {
            Picasso.with(getActivity())
                .load(avatarString)
                .resizeDimen(
                    R.dimen.list_standard_comment_avatar_dimen,
                    R.dimen.list_standard_comment_avatar_dimen)
                .placeholder(R.drawable.default_avatar)
                .transform(new RoundTransformation(Color.parseColor("#00000000"), 0, true))
                .into(avatarView);
          } else {
            avatarView.setImageResource(R.drawable.default_avatar);
          }
        }
        testLogin();
      }
      isFirstLoad = false;
    } else {
      if (loginState != UserAPI.isLoggedIn()) {
        checkChannelList();
        if (UserAPI.isLoggedIn()) {
          loadUserInfo();
        } else {
          back2UnLogged();
        }
      } else {
        if (UserAPI.isLoggedIn()) {
          if (userKey != null
              && userKey.equals(SharedPreferencesUtil.readString(Consts.Key_Ukey, ""))) {
            String avatarString = SharedPreferencesUtil.readString(Consts.Key_User_Avatar, "");
            if (!TextUtils.isEmpty(avatarString)) {
              if (Config.shouldLoadImage()) {
                Picasso.with(getActivity())
                    .load(avatarString)
                    .placeholder(R.drawable.default_avatar)
                    .resizeDimen(
                        R.dimen.list_standard_comment_avatar_dimen,
                        R.dimen.list_standard_comment_avatar_dimen)
                    .transform(new RoundTransformation(Color.parseColor("#00000000"), 0, true))
                    .into(avatarView);
              } else {
                avatarView.setImageResource(R.drawable.default_avatar);
              }
            }
            // 重新加载小组数据库
            long lastGroupDBVersion =
                SharedPreferencesUtil.readLong(Consts.Key_Last_Post_Groups_Version, 0);
            if (currentGroupDBVersion != lastGroupDBVersion) {
              ArrayList<SubItem> groupSubItems = adapter.getSubLists().get(1);
              groupSubItems.clear();
              groupSubItems.add(
                  new SubItem(
                      SubItem.Section_Post, SubItem.Type_Private_Channel, "我的小组", "user_group"));
              if (GroupHelper.getMyGroupsNumber() > 0) {
                // 如果已经加载了栏目
                groupSubItems.add(
                    new SubItem(
                        SubItem.Section_Post, SubItem.Type_Collections, "小组热贴", "hot_posts"));
                groupSubItems.addAll(GroupHelper.getSelectedGroupSubItems());
              } else {
                groupSubItems.addAll(ChannelHelper.getPosts());
              }
            }
            currentGroupDBVersion = lastGroupDBVersion;

            // 重新加载标签数据库
            long lastTagDBVersion =
                SharedPreferencesUtil.readLong(Consts.Key_Last_Ask_Tags_Version, 0);
            if (currentTagDBVersion != lastTagDBVersion) {
              ArrayList<SubItem> questionSubItems = adapter.getSubLists().get(2);
              if (AskTagHelper.getAskTagsNumber() > 0) {
                // 如果已经加载了栏目
                questionSubItems.clear();
                questionSubItems.add(
                    new SubItem(
                        SubItem.Section_Question, SubItem.Type_Collections, "热门问答", "hottest"));
                questionSubItems.add(
                    new SubItem(
                        SubItem.Section_Question, SubItem.Type_Collections, "精彩回答", "highlight"));
                questionSubItems.addAll(AskTagHelper.getSelectedQuestionSubItems());
              } else {
                questionSubItems.clear();
                questionSubItems.addAll(ChannelHelper.getQuestions());
              }
            }
            currentTagDBVersion = lastTagDBVersion;
            adapter.notifyDataSetChanged();
          } else {
            // 切换了用户的话
            checkChannelList();
            loadUserInfo();
          }
        }
      }
    }
    loginState = UserAPI.isLoggedIn();
    userKey = SharedPreferencesUtil.readString(Consts.Key_Ukey, "");
    if (loginState) {
      loadMessages();
    } else {
      noticeView.setVisibility(View.GONE);
    }
  }