diff --git a/app/src/main/java/com/gh/gamecenter/entity/AmwayCommentEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/AmwayCommentEntity.kt index cc2cab0e8c..63ae2c2eb8 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/AmwayCommentEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/AmwayCommentEntity.kt @@ -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? = arrayListOf(), var star: Float) : Parcelable { fun toGameEntity() : GameEntity { diff --git a/app/src/main/java/com/gh/gamecenter/entity/PersonalHistoryEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/PersonalHistoryEntity.kt index 3a500a5264..da43193c98 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/PersonalHistoryEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/PersonalHistoryEntity.kt @@ -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 = ArrayList(), val star: Float = 0F, @SerializedName("libao_exists") diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingAdapter.kt index b13775c6ec..c0482b893e 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingAdapter.kt @@ -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(context) { +class MyRatingAdapter(context: Context, + val mEntrance: String, + val mListViewModel: MyRatingViewModel) : ListAdapter(context) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { val view: View @@ -48,10 +50,32 @@ class MyRatingAdapter(context: Context) : ListAdapter(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) + GameViewUtils.setLabelList(mContext, holder.itemView.label_list, rating.game.tag as List) 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("我的光环_新", "我的游戏评论", "游戏详情") diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingFragment.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingFragment.kt index ec0b2135ba..93956fb2fa 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingFragment.kt @@ -32,7 +32,7 @@ class MyRatingFragment : ListFragment() { 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?.reply = resultData?.reply ?: 0 myRating?.content = resultData?.content ?: "" myRating?.star = resultData?.star ?: 0 + myRating?.me?.isVoted = resultData?.me?.isVoted ?: false mAdapter?.notifyItemChanged(dataPosition) } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingViewModel.kt index 9bc12b83c8..a9acae0c33 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/myrating/MyRatingViewModel.kt @@ -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(application) { + private val mApi = RetrofitManager.getInstance(getApplication()).api + + override fun provideDataObservable(page: Int): Observable>? { return null } override fun provideDataSingle(page: Int): Single> { - 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() { + override fun onResponse(response: ResponseBody?) { + callback.invoke() + } + + override fun onFailure(e: HttpException?) { + val string = e?.response()?.errorBody()?.string() + val errorEntity = string?.toObject() + 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() { + 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) + } + }) + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryAdapter.kt b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryAdapter.kt index 8f6d4eef56..6421db3e26 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryAdapter.kt @@ -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 { diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryFragment.kt b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryFragment.kt index 07a65ece62..dc0c23067c 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryFragment.kt @@ -189,6 +189,7 @@ class UserHistoryFragment : ListFragment { @@ -204,9 +205,9 @@ class UserHistoryFragment : ListFragment(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 -> { diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryViewModel.kt b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryViewModel.kt index e5fe0239ff..bfc291c2c8 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/home/UserHistoryViewModel.kt @@ -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(application) { + private val mApi = RetrofitManager.getInstance(getApplication()).api + + var type: TYPE = TYPE.ALL override fun provideDataObservable(page: Int): Observable> { - 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() { + override fun onResponse(response: ResponseBody?) { + callback.invoke() + } + + override fun onFailure(e: HttpException?) { + val string = e?.response()?.errorBody()?.string() + val errorEntity = string?.toObject() + 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() { + 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 diff --git a/app/src/main/res/layout/fragment_user_history.xml b/app/src/main/res/layout/fragment_user_history.xml index 353e61e2ef..12070bacd2 100644 --- a/app/src/main/res/layout/fragment_user_history.xml +++ b/app/src/main/res/layout/fragment_user_history.xml @@ -4,6 +4,19 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + + + - - - - - + xmlns:fresco="http://schemas.android.com/tools" + xmlns:tools="http://schemas.android.com/tools"> + + @@ -17,8 +20,7 @@ android:orientation="vertical" android:paddingLeft="20dp" android:paddingTop="16dp" - android:paddingRight="20dp" - android:paddingBottom="16dp"> + android:paddingRight="20dp"> - - + + + tools:text="1" /> diff --git a/app/src/main/res/layout/personal_home_rating.xml b/app/src/main/res/layout/personal_home_rating.xml index 0d4d243970..f6dabd0ce7 100644 --- a/app/src/main/res/layout/personal_home_rating.xml +++ b/app/src/main/res/layout/personal_home_rating.xml @@ -1,122 +1,139 @@ - + - + - + - + name="entity" + type="com.gh.gamecenter.entity.PersonalHistoryEntity" /> + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/reuse_listview_item_style" + android:orientation="vertical" + android:paddingLeft="20dp" + android:paddingTop="16dp" + android:paddingRight="20dp"> + android:id="@+id/user_icon_container" + android:layout_width="22dp" + android:layout_height="22dp" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:id="@+id/user_icon" + style="@style/frescoCircleStyle" + imageUrl="@{entity.user.icon}" + android:layout_width="20dp" + android:layout_height="20dp" + fresco:roundAsCircle="true" /> - + android:id="@+id/user_auth_icon" + imageUrl="@{entity.user.auth.icon}" + visibleGone="@{entity.user.auth == null? false: true}" + android:layout_width="10dp" + android:layout_height="10dp" + android:layout_alignParentRight="true" + android:layout_alignParentBottom="true" /> + + android:id="@+id/user_command" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginLeft="12dp" + android:layout_marginBottom="2dp" + android:singleLine="true" + android:textColor="@color/text_999999" + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="@id/user_icon_container" + app:layout_constraintLeft_toRightOf="@id/user_icon_container" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="@id/user_icon_container" /> + android:lineSpacingExtra="4dp" + android:maxLines="3" + android:textColor="@color/text_666666" + android:textSize="14sp" + app:layout_constraintTop_toBottomOf="@id/user_icon_container" /> + android:id="@+id/comment" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:drawableLeft="@drawable/community_comment_count" + android:drawablePadding="4dp" + android:gravity="center_vertical" + android:paddingTop="16dp" + android:paddingRight="12dp" + android:paddingBottom="16dp" + android:text="@{entity.count.reply > 0? NumberUtils.transSimpleCount(entity.count.reply) : ``}" + android:textColor="@color/vote_selector" + android:textSize="13sp" + app:layout_constraintBottom_toBottomOf="@+id/vote" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@+id/vote" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@id/content" + app:layout_constraintTop_toTopOf="@+id/vote" + tools:text="1" /> - + + android:id="@+id/rating_start" + style="@style/Widget.MaterialRatingBar.RatingBar" + android:layout_width="wrap_content" + android:layout_height="10dp" + android:layout_marginLeft="12dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="2dp" + android:isIndicator="true" + android:minWidth="14dp" + android:minHeight="14dp" + android:numStars="5" + android:rating="@{entity.comment.star}" + app:layout_constraintBottom_toBottomOf="@id/vote" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="@id/vote" + app:mrb_progressTint="@color/theme" /> - - + +