完善个人主页相关数据
This commit is contained in:
@ -46,6 +46,7 @@ import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -96,6 +97,19 @@ public class BindingAdapters {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果超过10000,则转换为1.0W
|
||||
@BindingAdapter("transSimpleCount")
|
||||
public static void transSimpleCount(TextView view, int count) {
|
||||
String s;
|
||||
if (count > 10000) {
|
||||
DecimalFormat df = new DecimalFormat("#.0W");
|
||||
s = df.format(count / 10000f);
|
||||
} else {
|
||||
s = String.valueOf(count);
|
||||
}
|
||||
view.setText(s);
|
||||
}
|
||||
|
||||
@BindingAdapter({"addKaiFuView", "clickListener"})
|
||||
public static void addKaiFuView(LinearLayout view, List<KaiFuCalendarEntity> list, OnViewClickListener listener) {
|
||||
if (list == null) return;
|
||||
|
||||
@ -24,9 +24,7 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
private var mUnreadViewModel: MessageUnreadViewModel? = null
|
||||
|
||||
override fun provideListAdapter(): PersonalHomeAdapter {
|
||||
if (mAdapter == null) mAdapter = PersonalHomeAdapter(this, mListViewModel, {
|
||||
mUnreadViewModel?.markRead(MessageUnreadViewModel.ReadType.FANS)
|
||||
})
|
||||
if (mAdapter == null) mAdapter = PersonalHomeAdapter(this, mListViewModel)
|
||||
return mAdapter!!
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,9 @@ import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||||
import com.gh.gamecenter.qa.recommends.AskQuestionsRecommendsViewHolder
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter
|
||||
|
||||
@ -21,7 +23,14 @@ class GameDetailAnswerAdapter(context: Context,
|
||||
|
||||
override fun onBindViewHolder(holder: AskQuestionsRecommendsViewHolder, position: Int) {
|
||||
holder.mLine.visibility = View.VISIBLE
|
||||
holder.initQuestionsHotViewHolder(mContext, mAnswerList[position])
|
||||
val entity = mAnswerList[position]
|
||||
holder.initQuestionsHotViewHolder(mContext, entity)
|
||||
holder.mAskTitle.setOnClickListener {
|
||||
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, entity.questions.id, "(游戏详情)"))
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, entity.id, "(游戏详情)"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -90,6 +90,12 @@ public class MessageUnreadViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
if (isChange) {
|
||||
// 重新统计总数
|
||||
cacheUnreadData.setTotal(cacheUnreadData.getInvited() + cacheUnreadData.getAnswerVote() +
|
||||
cacheUnreadData.getCommentVote() + cacheUnreadData.getAnswerCommentVote() +
|
||||
cacheUnreadData.getService() + cacheUnreadData.getAnswer() + cacheUnreadData.getReply() +
|
||||
cacheUnreadData.getFollowQuestion() + cacheUnreadData.getReplyAnswerComment() + cacheUnreadData.getAnswerComment() +
|
||||
cacheUnreadData.getSystemInvited() + cacheUnreadData.getFans());
|
||||
liveData.postValue(cacheUnreadData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ public class PersonalFragment extends BaseFragment implements Observer<ApiRespon
|
||||
@BindView(R.id.personal_service_unread)
|
||||
TextView mServiceUnread;
|
||||
@BindView(R.id.personal_home_fans_hint)
|
||||
View mFansHint;
|
||||
TextView mFansHint;
|
||||
// @BindView(R.id.personal_game_rv)
|
||||
// RecyclerView mGameRv;
|
||||
|
||||
@ -176,6 +176,7 @@ public class PersonalFragment extends BaseFragment implements Observer<ApiRespon
|
||||
, messageUnread -> {
|
||||
if (messageUnread != null && messageUnread.getTotal() > 0) {
|
||||
mFansHint.setVisibility(messageUnread.getFans() > 0 ? View.VISIBLE : View.GONE);
|
||||
mFansHint.setText(("新增了" + messageUnread.getFans() + "个粉丝"));
|
||||
mLoginMessageHint.setVisibility(messageUnread.getTotal() - messageUnread.getFans() > 0 ?
|
||||
View.VISIBLE : View.GONE);
|
||||
EventBus.getDefault().post(new EBReuse(MESSAGE_UNREAD_TAG));
|
||||
|
||||
@ -13,6 +13,7 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.databinding.FollowersOrFansItemBinding
|
||||
import com.gh.gamecenter.entity.FollowersOrFansEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.personalhome.FollowersOrFansViewHolder
|
||||
import com.gh.gamecenter.personalhome.FollowersOrFansViewModel
|
||||
|
||||
@ -46,7 +47,11 @@ class FollowersOrFansAdapter(context: Context, val mViewModel: FollowersOrFansVi
|
||||
val entity = mEntityList[position]
|
||||
holder.binding.entity = entity
|
||||
holder.binding.followerBtn.run {
|
||||
if (entity?.me?.isFollower!!) {
|
||||
if (entity.id == UserManager.getInstance().userId) {
|
||||
setText(R.string.myself)
|
||||
setTextColor(ContextCompat.getColor(mContext, R.color.button_gray))
|
||||
setBackgroundResource(R.drawable.button_border_gray)
|
||||
} else if (entity?.me?.isFollower!!) {
|
||||
setText(R.string.cancel_concern)
|
||||
setTextColor(ContextCompat.getColor(mContext, R.color.theme))
|
||||
setBackgroundResource(R.drawable.button_normal_border)
|
||||
@ -57,19 +62,21 @@ class FollowersOrFansAdapter(context: Context, val mViewModel: FollowersOrFansVi
|
||||
}
|
||||
}
|
||||
holder.binding.followerBtn.setOnClickListener {
|
||||
mViewModel.followingCommand(true, callback = {
|
||||
holder.binding.followerBtn.run {
|
||||
if (it) { // 关注成功
|
||||
setText(R.string.cancel_concern)
|
||||
setBackgroundResource(R.drawable.button_normal_border)
|
||||
setTextColor(ContextCompat.getColor(mContext, R.color.theme))
|
||||
} else { // 取消关注成功
|
||||
setText(R.string.concern)
|
||||
setBackgroundResource(R.drawable.button_normal_style)
|
||||
setTextColor(Color.WHITE)
|
||||
if (entity.id != UserManager.getInstance().userId) {
|
||||
mViewModel.followingCommand(!entity?.me?.isFollower!!, entity.id, callback = {
|
||||
holder.binding.followerBtn.run {
|
||||
if (it) { // 关注成功
|
||||
setText(R.string.cancel_concern)
|
||||
setBackgroundResource(R.drawable.button_normal_border)
|
||||
setTextColor(ContextCompat.getColor(mContext, R.color.theme))
|
||||
} else { // 取消关注成功
|
||||
setText(R.string.concern)
|
||||
setBackgroundResource(R.drawable.button_normal_style)
|
||||
setTextColor(Color.WHITE)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
PersonalHomeActivity.startTargetActivity(mContext, entity.id)
|
||||
|
||||
@ -6,6 +6,7 @@ import com.gh.common.util.EntranceUtils
|
||||
import com.gh.gamecenter.baselist.ListFragment
|
||||
import com.gh.gamecenter.entity.FollowersOrFansEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.message.MessageUnreadViewModel
|
||||
import com.gh.gamecenter.personalhome.FollowersOrFansViewModel
|
||||
import com.gh.gamecenter.personalhome.fans.FansActivity
|
||||
import com.gh.gamecenter.personalhome.fans.FollowersOrFansAdapter
|
||||
@ -17,6 +18,8 @@ class FollowersOrFansFragment : ListFragment<FollowersOrFansEntity, FollowersOrF
|
||||
const val PAGE_SOURCE = "PAGE_SOURCE"
|
||||
}
|
||||
|
||||
private var mUnreadViewModel: MessageUnreadViewModel? = null
|
||||
|
||||
private var mAdapter: FollowersOrFansAdapter? = null
|
||||
|
||||
override fun provideListAdapter(): FollowersOrFansAdapter {
|
||||
@ -34,6 +37,9 @@ class FollowersOrFansFragment : ListFragment<FollowersOrFansEntity, FollowersOrF
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val factory = MessageUnreadViewModel.Factory(HaloApp.getInstance().application)
|
||||
mUnreadViewModel = ViewModelProviders.of(this, factory).get(MessageUnreadViewModel::class.java)
|
||||
|
||||
if (mListViewModel.mPageSource == FansActivity::class.java.name) {
|
||||
if (mListViewModel.userId == UserManager.getInstance().userId) {
|
||||
setNavigationTitle("我的的粉丝")
|
||||
@ -49,4 +55,11 @@ class FollowersOrFansFragment : ListFragment<FollowersOrFansEntity, FollowersOrF
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLoadDone() {
|
||||
super.onLoadDone()
|
||||
if (mListViewModel.mPageSource == FansActivity::class.java.name) {
|
||||
mUnreadViewModel?.markRead(MessageUnreadViewModel.ReadType.FANS)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,7 +17,7 @@ import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
|
||||
class FollowersOrFansViewModel(application: Application,
|
||||
class FollowersOrFansViewModel(application: Application,
|
||||
var mPageSource: String,
|
||||
val userId: String) : ListViewModel<FollowersOrFansEntity, FollowersOrFansEntity>(application) {
|
||||
|
||||
@ -33,11 +33,11 @@ class FollowersOrFansViewModel(application: Application,
|
||||
}
|
||||
}
|
||||
|
||||
fun followingCommand(isFollow: Boolean, callback: (isFollow: Boolean) -> Unit) {
|
||||
fun followingCommand(isFollow: Boolean, targetUserId: String, callback: (isFollow: Boolean) -> Unit) {
|
||||
val observable = if (isFollow) {
|
||||
RetrofitManager.getInstance(getApplication()).api.postFollowing(userId)
|
||||
RetrofitManager.getInstance(getApplication()).api.postFollowing(targetUserId)
|
||||
} else {
|
||||
RetrofitManager.getInstance(getApplication()).api.deleteFollowing(userId)
|
||||
RetrofitManager.getInstance(getApplication()).api.deleteFollowing(targetUserId)
|
||||
}
|
||||
observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -61,7 +61,7 @@ class FollowersOrFansViewModel(application: Application,
|
||||
})
|
||||
}
|
||||
|
||||
class Factory(private val mApplication: Application,
|
||||
class Factory(private val mApplication: Application,
|
||||
private val mPageSource: String,
|
||||
private val mUserId: String) : ViewModelProvider.NewInstanceFactory() {
|
||||
|
||||
|
||||
@ -24,11 +24,11 @@ import com.gh.gamecenter.personalhome.fans.FollowersActivity
|
||||
import com.gh.gamecenter.personalhome.question.PersonalQuestionActivity
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||||
import com.lightgame.utils.Utils
|
||||
import java.util.*
|
||||
|
||||
class PersonalHomeAdapter(context: Context,
|
||||
private val mListViewModel: PersonalHomeViewModel,
|
||||
private val unreadItemClick: () -> Unit) : ListAdapter<PersonalHistoryEntity>(context) {
|
||||
private val mListViewModel: PersonalHomeViewModel) : ListAdapter<PersonalHistoryEntity>(context) {
|
||||
private var mUnreadEntity: MessageUnreadEntity? = null
|
||||
|
||||
var personalData: PersonalEntity? = null
|
||||
@ -102,7 +102,6 @@ class PersonalHomeAdapter(context: Context,
|
||||
mContext.startActivity(FollowersActivity.getIntent(mContext, mListViewModel.userId))
|
||||
}
|
||||
userFansContainer.setOnClickListener {
|
||||
unreadItemClick.invoke()
|
||||
mContext.startActivity(FansActivity.getIntent(mContext, mListViewModel.userId))
|
||||
}
|
||||
userQuestionText.setOnClickListener {
|
||||
@ -111,6 +110,9 @@ class PersonalHomeAdapter(context: Context,
|
||||
userAnswerText.setOnClickListener {
|
||||
mContext.startActivity(PersonalAnswerActivity.getIntent(mContext, mListViewModel.userId))
|
||||
}
|
||||
userVoteContainer.setOnClickListener {
|
||||
Utils.toast(mContext, "共获得" + entity?.count?.answerVote + "赞同")
|
||||
}
|
||||
userConcernOrEdit.setOnClickListener({
|
||||
if (mListViewModel.userId == UserManager.getInstance().userId) {
|
||||
mContext.startActivity(UserInfoActivity.getIntent(mContext))
|
||||
@ -161,8 +163,8 @@ class PersonalHomeAdapter(context: Context,
|
||||
"answer" -> personalData?.name + "回答了问题·" + NewsUtils.getFormattedTime(time)
|
||||
"question" -> personalData?.name + "提交了问题·" + NewsUtils.getFormattedTime(time)
|
||||
"answer_vote" -> personalData?.name + "关注了问题·" + NewsUtils.getFormattedTime(time)
|
||||
"question_follow" -> personalData?.name + "关注了问题·" + NewsUtils.getFormattedTime(time)
|
||||
else -> ""
|
||||
"follow_question" -> personalData?.name + "关注了问题·" + NewsUtils.getFormattedTime(time)
|
||||
else -> personalData?.name + ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user