diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/AnswerDetailFragment.java b/app/src/main/java/com/gh/gamecenter/qa/answer/detail/AnswerDetailFragment.java index 139a238b7a..f6bb119d95 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/AnswerDetailFragment.java +++ b/app/src/main/java/com/gh/gamecenter/qa/answer/detail/AnswerDetailFragment.java @@ -371,9 +371,9 @@ public class AnswerDetailFragment extends NormalFragment { if (isFollowed) { toast(R.string.concern_success); - mBinding.answerDetailFollow.setText(R.string.cancel_concern); + updateFollowBtn(true); } else { - mBinding.answerDetailFollow.setText(R.string.concern); + updateFollowBtn(false); } }); } @@ -551,17 +551,18 @@ public class AnswerDetailFragment extends NormalFragment { PersonalHomeActivity.startTargetActivity(getContext(), mDetailEntity.getUser().getId(), mEntrance, "回答详情"); break; case R.id.answer_detail_follow: - if (mBinding.answerDetailFollow.getText().equals("关注")) { - mViewModel.follow(mDetailEntity.getUser().getId()); - } else { - DialogUtils.showAlertDialog(getContext(), "取消关注", "确定要取消关注 " + mDetailEntity.getUser().getName() + " 吗?", - "确定取消", "暂不取消", new DialogUtils.ConfirmListener() { - @Override - public void onConfirm() { - mViewModel.unfollow(mDetailEntity.getUser().getId()); - } - }, null); - } + CheckLoginUtils.checkLogin(getContext(), () -> { + if (mBinding.answerDetailFollow.getText().equals("关注")) { + mViewModel.follow(mDetailEntity.getUser().getId()); + } else { + DialogUtils.showAlertDialog(getContext(), + "取消关注", + "确定要取消关注 " + mDetailEntity.getUser().getName() + " 吗?", + "确定取消", + "暂不取消", + () -> mViewModel.unfollow(mDetailEntity.getUser().getId()), null); + } + }); break; } } @@ -653,15 +654,27 @@ public class AnswerDetailFragment extends NormalFragment { } else { mBinding.answerDetailFollow.setVisibility(View.VISIBLE); if (mDetailEntity.getMe().isFollower()) { - mBinding.answerDetailFollow.setText(R.string.cancel_concern); + updateFollowBtn(true); } else { - mBinding.answerDetailFollow.setText(R.string.concern); + updateFollowBtn(false); } } updateVote(); } + private void updateFollowBtn(boolean isFollowed) { + if (isFollowed) { + mBinding.answerDetailFollow.setText(R.string.cancel_concern); + mBinding.answerDetailFollow.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.button_normal_border)); + mBinding.answerDetailFollow.setTextColor(ContextCompat.getColor(getContext(), R.color.theme)); + } else { + mBinding.answerDetailFollow.setText(R.string.concern); + mBinding.answerDetailFollow.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.button_normal_style)); + mBinding.answerDetailFollow.setTextColor(ContextCompat.getColor(getContext(), R.color.all_white)); + } + } + private void updateVote() { mAnswerDetailLikeTv.setText(getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(mDetailEntity.getVote()))); diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt index d1ce655f3e..64a0902687 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt @@ -10,6 +10,7 @@ import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.support.v4.content.ContextCompat import android.text.TextUtils import android.view.* import android.webkit.JavascriptInterface @@ -106,13 +107,13 @@ class ArticleDetailActivity : BaseActivity() { } }) - mViewModel.followLiveData.observe(this, Observer { isFollowed-> + mViewModel.followLiveData.observe(this, Observer { isFollowed -> isFollowed?.let { if (isFollowed) { toast(R.string.concern_success) - mBinding.articleDetailFollow.setText(R.string.cancel_concern) + updateFollowBtn(true) } else { - mBinding.articleDetailFollow.setText(R.string.concern) + updateFollowBtn(false) } } }) @@ -175,18 +176,36 @@ class ArticleDetailActivity : BaseActivity() { mViewModel.getArticleDetail() } R.id.article_detail_follow -> { - if (mBinding.articleDetailFollow.text == "关注") { - mViewModel.follow() - } else { - DialogUtils.showAlertDialog(this, "取消关注", "确定要取消关注 ${mViewModel.detailEntity?.user?.name} 吗?", - "确定取消", "暂不取消", DialogUtils.ConfirmListener { - mViewModel.unfollow() - }, null) + CheckLoginUtils.checkLogin(this) { + if (mBinding.articleDetailFollow.text == "关注") { + mViewModel.follow() + } else { + DialogUtils.showAlertDialog(this, + "取消关注", + "确定要取消关注 ${mViewModel.detailEntity?.user?.name} 吗?", + "确定取消", + "暂不取消", + DialogUtils.ConfirmListener { + mViewModel.unfollow() + }, null) + } } } } } + private fun updateFollowBtn(isFollowed: Boolean) { + if (isFollowed) { + mBinding.articleDetailFollow.background = ContextCompat.getDrawable(this, R.drawable.button_normal_border) + mBinding.articleDetailFollow.setText(R.string.cancel_concern) + mBinding.articleDetailFollow.setTextColor(ContextCompat.getColor(this, R.color.theme)) + } else { + mBinding.articleDetailFollow.background = ContextCompat.getDrawable(this, R.drawable.button_normal_style) + mBinding.articleDetailFollow.setTextColor(ContextCompat.getColor(this, R.color.all_white)) + mBinding.articleDetailFollow.setText(R.string.concern) + } + } + inner class JsInterface { @JavascriptInterface fun imageClick(url: String) { @@ -320,9 +339,9 @@ class ArticleDetailActivity : BaseActivity() { } else { mBinding.articleDetailFollow.visibility = View.VISIBLE if (mViewModel.detailEntity?.me?.isFollower!!) { - mBinding.articleDetailFollow.setText(R.string.cancel_concern) + updateFollowBtn(true) } else { - mBinding.articleDetailFollow.setText(R.string.concern) + updateFollowBtn(false) } }