微调文章详情和答案的关注按钮样式

This commit is contained in:
chenjuntao
2018-10-24 16:49:58 +08:00
parent 788817f485
commit 17aed59317
2 changed files with 59 additions and 27 deletions

View File

@ -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())));

View File

@ -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)
}
}