/** 重新验证当前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();
  }
예제 #2
0
 @Override
 protected ResponseObject doInBackground(String[] params) {
   ResponseObject<ArrayList<SubItem>> result = QuestionAPI.getAllMyTags();
   if (TextUtils.isEmpty(UserAPI.getUserID())) {
     result.error_message = "无法获得用户id";
     result.error = ResponseError.NO_USER_ID;
   } else if (result.ok) {
     ArrayList<SubItem> subItems = result.result;
     ArrayList<AskTag> myTags = new ArrayList<>();
     for (int i = 0; i < subItems.size(); i++) {
       SubItem item = subItems.get(i);
       AskTag myTag = new AskTag();
       myTag.setName(item.getName());
       myTag.setValue(item.getValue());
       myTag.setType(item.getType());
       myTag.setSection(item.getSection());
       myTag.setSelected(i < defaultTagsNumber);
       myTag.setOrder(i);
       myTags.add(myTag);
     }
     mergeMyGroups(myTags);
     AskTagHelper.putAllMyTags(myTags);
     getButtons();
   }
   return result;
 }
예제 #3
0
  private void recommend() {
    if (!UserAPI.isLoggedIn()) {
      notifyNeedLog();
    } else {
      MobclickAgent.onEvent(this, Mob.Event_Recommend_Question);
      InputDialog.Builder builder = new InputDialog.Builder(this);
      builder.setTitle(R.string.recommend_question);
      builder.setCancelable(true);
      builder.setCanceledOnTouchOutside(false);
      builder.setOnClickListener(
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              if (which == DialogInterface.BUTTON_POSITIVE) {
                InputDialog d = (InputDialog) dialog;
                String text = d.InputString;
                RecommendTask recommendTask = new RecommendTask();
                recommendTask.executeOnExecutor(
                    AsyncTask.THREAD_POOL_EXECUTOR,
                    question.getId(),
                    question.getTitle(),
                    question.getSummary(),
                    text);
              }
            }
          });
      InputDialog inputDialog = builder.create();
      inputDialog.show();
    }
  }
예제 #4
0
 private void favor() {
   if (!UserAPI.isLoggedIn()) {
     notifyNeedLog();
   } else {
     MobclickAgent.onEvent(this, Mob.Event_Favor_Question);
     new FavorDialog.Builder(this).setTitle(R.string.action_favor).create(question).show();
   }
 }
예제 #5
0
 private void answerQuestion() {
   if (!UserAPI.isLoggedIn()) {
     notifyNeedLog();
   } else {
     Intent intent = new Intent(this, ReplyActivity.class);
     intent.putExtra(Consts.Extra_Ace_Model, question);
     startActivity(intent);
     overridePendingTransition(R.anim.slide_in_right, 0);
   }
 }
 private void onUserViewClicked() {
   if (!UserAPI.isLoggedIn()) {
     Intent intent = new Intent(getActivity(), LoginActivity.class);
     startActivityForResult(intent, Consts.Code_Login);
     getActivity().overridePendingTransition(R.anim.slide_in_right, 0);
   } else {
     String nameString = SharedPreferencesUtil.readString(Consts.Key_User_Name, "");
     if (TextUtils.isEmpty(nameString)) {
       loadUserInfo();
     } else {
       Intent intent = new Intent(getActivity(), MessageCenterActivity.class);
       startActivityForResult(intent, Consts.Code_Message_Center);
       getActivity().overridePendingTransition(R.anim.slide_in_right, 0);
     }
   }
 }
예제 #7
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.menu_question, menu);
   try {
     Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
     m.setAccessible(true);
     m.invoke(menu, true);
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (!UserAPI.isLoggedIn()) {
     menu.findItem(R.id.action_follow_question).setVisible(false);
     menu.findItem(R.id.action_unfollow_question).setVisible(false);
   }
   return true;
 }
예제 #8
0
 @Override
 protected ResultObject<ArrayList<AceModel>> doInBackground(Integer... params) {
   if (!TextUtils.isEmpty(notice_id)) {
     UserAPI.ignoreOneNotice(notice_id);
     notice_id = null;
   }
   offset = params[0];
   if (offset < 0) {
     ResultObject<Question> questionResult = QuestionAPI.getQuestionDetailByID(question.getId());
     if (questionResult.ok) {
       publishProgress(questionResult);
       return QuestionAPI.getQuestionAnswers(question.getId(), 0);
     } else {
       return new ResultObject<>();
     }
   } else {
     return QuestionAPI.getQuestionAnswers(question.getId(), offset);
   }
 }
예제 #9
0
 @Override
 protected void onPostExecute(ResponseObject result) {
   progressDialog.dismiss();
   if (result.ok) {
     MobclickAgent.onEvent(ShuffleTagActivity.this, Mob.Event_Load_My_Tags_OK);
     initView();
   } else {
     MobclickAgent.onEvent(ShuffleTagActivity.this, Mob.Event_Load_My_Tags_Failed);
     MobclickAgent.reportError(
         ShuffleTagActivity.this,
         "加载标签失败\n是否WIFI:"
             + Config.isWifi()
             + "\n"
             + UserAPI.getUserInfoString()
             + result.error_message);
     if (result.error == ResponseError.NO_USER_ID) {
       toast("未获得用户ID,无法加载");
     } else {
       toast("加载标签失败");
     }
   }
 }
 @Override
 protected ResultObject<UserInfo> doInBackground(String... params) {
   return UserAPI.getUserInfoByUkey(UserAPI.getUkey());
 }
 @Override
 protected ResultObject doInBackground(Void... params) {
   return UserAPI.testLogin();
 }
 @Override
 protected ResultObject<ReminderNoticeNum> doInBackground(Void... params) {
   return UserAPI.getReminderAndNoticeNum();
 }
 private void loadUserInfo() {
   if (UserAPI.isLoggedIn()) {
     UserInfoTask task = new UserInfoTask();
     task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
   }
 }
  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);
    }
  }