光环前端优化汇总(2020年5月第2周)(11,12)https://gitlab.ghzs.com/pm/halo-app-issues/-/issues/858
This commit is contained in:
@ -18,7 +18,7 @@ data class AmwayCommentEntity(
|
||||
var id: String,
|
||||
var icon: String,
|
||||
var name: String,
|
||||
@SerializedName(value="tag", alternate=["tag_style"])
|
||||
@SerializedName(value="new_tag_style")
|
||||
var tag: List<TagStyleEntity>? = arrayListOf(),
|
||||
var star: Float) : Parcelable {
|
||||
fun toGameEntity() : GameEntity {
|
||||
|
||||
@ -70,7 +70,7 @@ data class PersonalHistoryEntity(
|
||||
val nameSuffix: String = "",
|
||||
|
||||
val icon: String = "",
|
||||
@SerializedName(value = "tag", alternate = ["tag_style"])
|
||||
@SerializedName(value = "new_tag_style")
|
||||
val tag: ArrayList<TagStyleEntity> = ArrayList(),
|
||||
val star: Float = 0F,
|
||||
@SerializedName("libao_exists")
|
||||
|
||||
@ -17,7 +17,9 @@ import com.gh.gamecenter.personalhome.rating.MyRating
|
||||
import kotlinx.android.synthetic.main.item_my_game_rating.view.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class MyRatingAdapter(context: Context) : ListAdapter<MyRating>(context) {
|
||||
class MyRatingAdapter(context: Context,
|
||||
val mEntrance: String,
|
||||
val mListViewModel: MyRatingViewModel) : ListAdapter<MyRating>(context) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val view: View
|
||||
@ -48,10 +50,32 @@ class MyRatingAdapter(context: Context) : ListAdapter<MyRating>(context) {
|
||||
} else {
|
||||
holder.itemView.tv_comment.setTextWithHighlightedTextWrappedInsideWrapper(text = rating.content, copyClickedText = true)
|
||||
}
|
||||
GameViewUtils.setLabelList(mContext, holder.itemView.label_list, "type", rating.game.tag as List<TagStyleEntity>)
|
||||
GameViewUtils.setLabelList(mContext, holder.itemView.label_list, rating.game.tag as List<TagStyleEntity>)
|
||||
holder.itemView.label_list.goneIf(holder.itemView.label_list.childCount == 0)
|
||||
holder.itemView.gamedetail_iv_libao.goneIf(!rating.game.isLibaoExists)
|
||||
|
||||
holder.binding.vote.setOnClickListener {
|
||||
mContext.ifLogin(mEntrance) {
|
||||
if (!holder.binding.vote.isChecked) {
|
||||
mListViewModel.voteComment(rating.game.id, rating.id, callback = {
|
||||
val count = rating.vote + 1
|
||||
holder.binding.vote.text = count.toString()
|
||||
holder.binding.vote.isChecked = true
|
||||
rating.vote = count
|
||||
rating.me.isVoted = true
|
||||
})
|
||||
} else {
|
||||
mListViewModel.unVoteComment(rating.game.id, rating.id, callback = {
|
||||
val count = rating.vote - 1
|
||||
holder.binding.vote.text = if (count == 0) "" else count.toString()
|
||||
holder.binding.vote.isChecked = false
|
||||
rating.vote = count
|
||||
rating.me.isVoted = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.itemView.apply {
|
||||
game_info.setOnClickListener {
|
||||
MtaHelper.onEvent("我的光环_新", "我的游戏评论", "游戏详情")
|
||||
|
||||
@ -32,7 +32,7 @@ class MyRatingFragment : ListFragment<MyRating, MyRatingViewModel>() {
|
||||
|
||||
override fun provideListAdapter(): ListAdapter<*> {
|
||||
if (mAdapter == null) {
|
||||
mAdapter = MyRatingAdapter(requireContext())
|
||||
mAdapter = MyRatingAdapter(requireContext(), mEntrance, mListViewModel)
|
||||
}
|
||||
return mAdapter!!
|
||||
}
|
||||
@ -51,6 +51,7 @@ class MyRatingFragment : ListFragment<MyRating, MyRatingViewModel>() {
|
||||
myRating?.reply = resultData?.reply ?: 0
|
||||
myRating?.content = resultData?.content ?: ""
|
||||
myRating?.star = resultData?.star ?: 0
|
||||
myRating?.me?.isVoted = resultData?.me?.isVoted ?: false
|
||||
mAdapter?.notifyItemChanged(dataPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,72 @@
|
||||
package com.gh.gamecenter.gamedetail.myrating
|
||||
|
||||
import android.app.Application
|
||||
import com.gh.common.util.ErrorHelper
|
||||
import com.gh.common.util.toObject
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.entity.ErrorEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.personalhome.rating.MyRating
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
|
||||
class MyRatingViewModel(application: Application) : ListViewModel<MyRating, MyRating>(application) {
|
||||
private val mApi = RetrofitManager.getInstance(getApplication()).api
|
||||
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<MyRating>>? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun provideDataSingle(page: Int): Single<MutableList<MyRating>> {
|
||||
return RetrofitManager.getInstance(getApplication()).api.getMyRating(UserManager.getInstance().userId, page,"view:halo")
|
||||
return mApi.getMyRating(UserManager.getInstance().userId, page, "view:halo")
|
||||
}
|
||||
|
||||
override fun mergeResultLiveData() {
|
||||
mResultLiveData.addSource(mListLiveData) { mResultLiveData.postValue(it) }
|
||||
}
|
||||
|
||||
fun voteComment(gameId: String, commentId: String, callback: () -> Unit) {
|
||||
mApi.voteGameComment(gameId, commentId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
val string = e?.response()?.errorBody()?.string()
|
||||
val errorEntity = string?.toObject<ErrorEntity>()
|
||||
if (errorEntity?.code == 403008) {
|
||||
onResponse(null)
|
||||
return
|
||||
}
|
||||
ErrorHelper.handleError(getApplication(), string)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun unVoteComment(gameId: String, commentId: String, callback: () -> Unit) {
|
||||
mApi.unvoteGameComment(gameId, commentId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
val string = e?.response()?.errorBody()?.string()
|
||||
ErrorHelper.handleError(getApplication(), string)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -68,8 +68,6 @@ class UserHistoryAdapter(context: Context,
|
||||
}
|
||||
|
||||
private fun bindNormalItem(holder: PersonalItemViewHolder, position: Int) {
|
||||
holder.binding.root.setPadding(20F.dip2px(), if (position == 0) 0 else 16F.dip2px(), 20F.dip2px(), 0)
|
||||
|
||||
val historyEntity = mEntityList[holder.adapterPosition]
|
||||
|
||||
holder.bindPersonalItem(historyEntity, mEntrance)
|
||||
@ -115,6 +113,28 @@ class UserHistoryAdapter(context: Context,
|
||||
holder.binding.root.setOnClickListener {
|
||||
itemClickCallback.invoke(historyEntity, position)
|
||||
}
|
||||
|
||||
holder.binding.vote.setOnClickListener {
|
||||
mContext.ifLogin(mEntrance) {
|
||||
if (!holder.binding.vote.isChecked) {
|
||||
mListViewModel.voteComment(historyEntity.comment.game.id, historyEntity.comment.id, callback = {
|
||||
val count = historyEntity.count.vote + 1
|
||||
holder.binding.vote.text = count.toString()
|
||||
holder.binding.vote.isChecked = true
|
||||
historyEntity.count.vote = count
|
||||
historyEntity.me.isVoted = true
|
||||
})
|
||||
} else {
|
||||
mListViewModel.unVoteComment(historyEntity.comment.game.id, historyEntity.comment.id, callback = {
|
||||
val count = historyEntity.count.vote - 1
|
||||
holder.binding.vote.text = if (count == 0) "" else count.toString()
|
||||
holder.binding.vote.isChecked = false
|
||||
historyEntity.count.vote = count
|
||||
historyEntity.me.isVoted = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getEntityList(): List<PersonalHistoryEntity> {
|
||||
|
||||
@ -189,6 +189,7 @@ class UserHistoryFragment : ListFragment<PersonalHistoryEntity, UserHistoryViewM
|
||||
count.reply = resultData?.reply ?: 0
|
||||
comment.content = resultData?.content ?: ""
|
||||
comment.star = resultData?.star ?: 0
|
||||
me.isVoted = resultData?.me?.isVoted ?: false
|
||||
}
|
||||
}
|
||||
101 -> {
|
||||
@ -204,9 +205,9 @@ class UserHistoryFragment : ListFragment<PersonalHistoryEntity, UserHistoryViewM
|
||||
val resultData = data.getParcelableExtra<AnswerDetailEntity>(AnswerDetailEntity::class.java.simpleName)
|
||||
historyEntity?.apply {
|
||||
count.vote = resultData?.vote ?: 0
|
||||
count.comment = resultData?.commentCount?:0
|
||||
count.comment = resultData?.commentCount ?: 0
|
||||
brief = HtmlUtils.stripHtmlCode(resultData?.content ?: "")
|
||||
question.title = resultData?.question?.title?:""
|
||||
question.title = resultData?.question?.title ?: ""
|
||||
}
|
||||
}
|
||||
103 -> {
|
||||
|
||||
@ -3,21 +3,32 @@ package com.gh.gamecenter.personalhome.home
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.gh.common.util.ErrorHelper
|
||||
import com.gh.common.util.UrlFilterUtils
|
||||
import com.gh.common.util.toObject
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.baselist.LoadType
|
||||
import com.gh.gamecenter.entity.ErrorEntity
|
||||
import com.gh.gamecenter.entity.PersonalHistoryEntity
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
|
||||
class UserHistoryViewModel(application: Application, var userId: String, private var mScene: SCENE)
|
||||
: ListViewModel<PersonalHistoryEntity, PersonalHistoryEntity>(application) {
|
||||
|
||||
private val mApi = RetrofitManager.getInstance(getApplication()).api
|
||||
|
||||
|
||||
var type: TYPE = TYPE.ALL
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<PersonalHistoryEntity>> {
|
||||
return RetrofitManager.getInstance(getApplication()).api.getPersonalHistory(userId, page,
|
||||
return mApi.getPersonalHistory(userId, page,
|
||||
HaloApp.getInstance().channel, getFilter())
|
||||
}
|
||||
|
||||
@ -25,6 +36,45 @@ class UserHistoryViewModel(application: Application, var userId: String, private
|
||||
mResultLiveData.addSource(mListLiveData) { mResultLiveData.postValue(it) }
|
||||
}
|
||||
|
||||
fun voteComment(gameId: String, commentId: String, callback: () -> Unit) {
|
||||
mApi.voteGameComment(gameId, commentId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
val string = e?.response()?.errorBody()?.string()
|
||||
val errorEntity = string?.toObject<ErrorEntity>()
|
||||
if (errorEntity?.code == 403008) {
|
||||
onResponse(null)
|
||||
return
|
||||
}
|
||||
ErrorHelper.handleError(getApplication(), string)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun unVoteComment(gameId: String, commentId: String, callback: () -> Unit) {
|
||||
mApi.unvoteGameComment(gameId, commentId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
val string = e?.response()?.errorBody()?.string()
|
||||
ErrorHelper.handleError(getApplication(), string)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fun changeType(type: TYPE) {
|
||||
if (this.type != type) {
|
||||
this.type = type
|
||||
|
||||
Reference in New Issue
Block a user