Ejemplo n.º 1
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();
    }
  }
  /** 重新验证当前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.º 3
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();
   }
 }
Ejemplo n.º 4
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);
     }
   }
 }
Ejemplo n.º 6
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;
 }
 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);
    }
  }