diff --git a/app/src/main/java/com/gh/common/constant/Constants.java b/app/src/main/java/com/gh/common/constant/Constants.java index 51e028c783..fe82cf3855 100644 --- a/app/src/main/java/com/gh/common/constant/Constants.java +++ b/app/src/main/java/com/gh/common/constant/Constants.java @@ -347,7 +347,7 @@ public class Constants { //已收录包名更新 cd间隔 public static final int PACKAGES_CD = 60 * 1000; - public static final String[] REPORT_LIST = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其它"}; + public static final String[] REPORT_LIST = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其他原因"}; public static final String ENTRANCE_UNKNOWN = "(unknown)"; diff --git a/app/src/main/java/com/gh/common/util/BbsReportHelper.kt b/app/src/main/java/com/gh/common/util/BbsReportHelper.kt index 7e03c524a4..633d258e7e 100644 --- a/app/src/main/java/com/gh/common/util/BbsReportHelper.kt +++ b/app/src/main/java/com/gh/common/util/BbsReportHelper.kt @@ -2,133 +2,124 @@ package com.gh.common.util import android.annotation.SuppressLint import android.app.Dialog -import android.content.Context -import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.preference.PreferenceManager +import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.Window -import android.widget.EditText -import android.widget.LinearLayout -import android.widget.TextView -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.content.ContextCompat +import androidx.core.widget.doOnTextChanged +import androidx.recyclerview.widget.LinearLayoutManager import com.gh.base.CurrentActivityHolder import com.gh.common.json.json -import com.gh.common.util.ToastUtils.showToast +import com.gh.common.view.VerticalItemDecoration import com.gh.gamecenter.R import com.gh.gamecenter.SuggestionActivity +import com.gh.gamecenter.adapter.ReportReasonAdapter +import com.gh.gamecenter.databinding.DialogReportReasonBinding import com.gh.gamecenter.entity.SettingsEntity import com.gh.gamecenter.retrofit.BiResponse import com.gh.gamecenter.retrofit.RetrofitManager import com.halo.assistant.HaloApp -import com.lightgame.utils.Util_System_Keyboard -import com.lightgame.utils.Utils import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import okhttp3.ResponseBody import org.json.JSONObject +import retrofit2.HttpException object BbsReportHelper { fun showReportDialog(contentId: String) { val sp = PreferenceManager.getDefaultSharedPreferences(HaloApp.getInstance()) - val suggestion: SettingsEntity.Suggestion? = sp.getString(SuggestionActivity.SUGGESTION_HINT_TYPE, null)?.toObject() + val suggestion: SettingsEntity.Suggestion? = + sp.getString(SuggestionActivity.SUGGESTION_HINT_TYPE, null)?.toObject() val reportList = suggestion?.report ?: return CurrentActivityHolder.getCurrentActivity()?.apply { if (this.isFinishing) return@apply - val dialog = Dialog(this) + val dialog = Dialog(this, R.style.DialogWindowTransparent) + val binding: DialogReportReasonBinding = + DialogReportReasonBinding.inflate(LayoutInflater.from(this)) + val reportReasonAdapter = ReportReasonAdapter( + this, reportList as ArrayList + ) { reason -> + if (reason == "其他原因") { + binding.reasonTitle.setText(R.string.report_reason_other_title) + binding.normalReasonContainer.visibility = View.GONE + binding.otherReasonContainer.visibility = View.VISIBLE + } else { + postReport(contentId, json { + "reason" to reason + }) + dialog.cancel() + } + } + binding.reasonRv.layoutManager = LinearLayoutManager(this) + binding.reasonRv.addItemDecoration( + VerticalItemDecoration( + this, + 1f, + false, + R.color.text_f5f5f5 + ) + ) + binding.reasonRv.adapter = reportReasonAdapter - val view = LayoutInflater.from(this).inflate(R.layout.dialog_video_complaint, null, false) - val complaintContainer = view.findViewById(R.id.complaintContainer) - val otherComplaintContainer: ConstraintLayout = view.findViewById(R.id.otherComplaintContainer) - val complaintCommentEt = view.findViewById(R.id.complaintCommentEt) - val backTv = view.findViewById(R.id.backTv) - val commitTv = view.findViewById(R.id.commitTv) - val finalContext: Context = this - //添加透明阴影,实现类似 clipPadding=false 效果 - complaintCommentEt.setShadowLayer(complaintCommentEt.extendedPaddingBottom.toFloat(), 0f, 0f, Color.TRANSPARENT) - - complaintCommentEt.setTextChangedListener { s: CharSequence, _: Int?, _: Int?, _: Int? -> - commitTv.setTextColor(ContextCompat.getColor(finalContext, if (s.toString().trim { it <= ' ' }.isEmpty()) R.color.text_999999 else R.color.theme_font)) + binding.negativeBtn.setOnClickListener { v -> + binding.reasonTitle.setText(R.string.report_reason_title) + binding.normalReasonContainer.visibility = View.VISIBLE + binding.otherReasonContainer.visibility = View.GONE } - for (option in reportList) { - val reportTv = TextView(this) - reportTv.text = option - reportTv.textSize = 16F - reportTv.setTextColor(R.color.title.toColor()) - reportTv.setBackgroundResource(R.drawable.textview_white_style) - reportTv.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT) - reportTv.setPadding(20F.dip2px(), 17F.dip2px(), 20F.dip2px(), 17F.dip2px()) - if (option.contains("其它")) { - val drawable = R.drawable.ic_complaint_arrow_right.toDrawable() - drawable!!.setBounds(0, 0, 6F.dip2px(), 10F.dip2px()) - reportTv.setCompoundDrawables(null, null, drawable, null) - } - complaintContainer.addView(reportTv) - reportTv.setOnClickListener { - if (option.contains("其它")) { - complaintContainer.visibility = View.GONE - otherComplaintContainer.visibility = View.VISIBLE - complaintCommentEt.requestFocus() - Util_System_Keyboard.showSoftKeyboard(finalContext, complaintCommentEt) - } else { - postReport(contentId, json { - "reason" to reportTv.text.toString() - }) - dialog.cancel() - } + binding.positiveBtn.setOnClickListener { v -> + if (TextUtils.isEmpty( + binding.otherReasonEt.text.toString().trim() + ) + ) { + ToastUtils.showToast("请填写举报原因") + } else { + postReport(contentId, json { + "reason" to "其它" + "description" to binding.otherReasonEt.text.toString() + }) + + dialog.cancel() } } - backTv.setOnClickListener { - Util_System_Keyboard.hideSoftKeyboard(finalContext, complaintCommentEt) - complaintContainer.visibility = View.VISIBLE - otherComplaintContainer.visibility = View.GONE - } - commitTv.setOnClickListener { - if (complaintCommentEt.text.toString().isEmpty()) { - showToast("请先输入说明~") - return@setOnClickListener + binding.otherReasonEt.doOnTextChanged { text, start, before, count -> + val tvCount: Int = text.toString().length + if (tvCount >= 500) { + binding.tvCount.setTextColor(R.color.text_FF4147.toColor()) } - postReport(contentId, json { - "reason" to "其它" - "description" to complaintCommentEt.text.toString() - }) - - dialog.cancel() + binding.tvCount.text = "$tvCount/500" } dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) - dialog.setContentView(view) + dialog.setContentView(binding.root) dialog.show() - val window = dialog.window - if (window != null) { - window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) - val params = window.attributes - params.width = resources.displayMetrics.widthPixels - 40F.dip2px() - window.attributes = params - } } } @SuppressLint("CheckResult") private fun postReport(contentId: String, reportContent: JSONObject) { RetrofitManager.getInstance(HaloApp.getInstance()) - .api - .postBbsReport(contentId, reportContent.toRequestBody()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : BiResponse() { - override fun onSuccess(data: ResponseBody) { - Utils.toast(HaloApp.getInstance(), "举报成功") + .api + .postBbsReport(contentId, reportContent.toRequestBody()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + ToastUtils.toast("举报成功") + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + if (exception is HttpException) { + ErrorHelper.handleError(HaloApp.getInstance().application, exception.response().errorBody()?.string()) } - }) + } + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/DialogUtils.java b/app/src/main/java/com/gh/common/util/DialogUtils.java index 610b28ae3b..6c53440eed 100644 --- a/app/src/main/java/com/gh/common/util/DialogUtils.java +++ b/app/src/main/java/com/gh/common/util/DialogUtils.java @@ -45,10 +45,12 @@ import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; import androidx.databinding.DataBindingUtil; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import kotlin.Unit; import kotlin.jvm.functions.Function0; +import kotlin.jvm.functions.Function1; import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.view.SimpleDraweeView; @@ -60,9 +62,11 @@ import com.gh.common.view.DrawableView; import com.gh.common.view.FixLinearLayoutManager; import com.gh.common.view.LimitHeightLinearLayout; import com.gh.common.view.MaxHeightNestedScrollView; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.AboutActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SuggestionActivity; +import com.gh.gamecenter.adapter.ReportReasonAdapter; import com.gh.gamecenter.adapter.viewholder.PrivacyPolicyItemViewHolder; import com.gh.gamecenter.databinding.DialogBindPhoneBinding; import com.gh.gamecenter.databinding.DialogEnergySignBinding; @@ -2013,37 +2017,26 @@ public class DialogUtils { } @SuppressLint("SetTextI18n") - public static void showReportReasonDialog(Context context, ReportReasonCallBack callBack) { + public static void showReportReasonDialog(Context context, ArrayList items,ReportReasonCallBack callBack) { context = checkDialogContext(context); final Dialog dialog = new Dialog(context, R.style.DialogWindowTransparent); DialogReportReasonBinding binding = DialogReportReasonBinding.inflate(LayoutInflater.from(context)); - binding.reasonOne.setOnClickListener(v -> { - dialog.dismiss(); - callBack.onResponse(binding.reasonOne.getText().toString(), ""); - }); - - binding.reasonTwo.setOnClickListener(v -> { - dialog.dismiss(); - callBack.onResponse(binding.reasonTwo.getText().toString(), ""); - }); - - binding.reasonThree.setOnClickListener(v -> { - dialog.dismiss(); - callBack.onResponse(binding.reasonThree.getText().toString(), ""); - }); - - binding.reasonFour.setOnClickListener(v -> { - dialog.dismiss(); - callBack.onResponse(binding.reasonFour.getText().toString(), ""); - }); - - binding.reasonOther.setOnClickListener(v -> { - binding.reasonTitle.setText(R.string.report_reason_other_title); - binding.normalReasonContainer.setVisibility(View.GONE); - binding.otherReasonContainer.setVisibility(View.VISIBLE); + ReportReasonAdapter reportReasonAdapter = new ReportReasonAdapter(context, items, reason -> { + if (reason.equals("其他原因")) { + binding.reasonTitle.setText(R.string.report_reason_other_title); + binding.normalReasonContainer.setVisibility(View.GONE); + binding.otherReasonContainer.setVisibility(View.VISIBLE); + } else { + dialog.dismiss(); + callBack.onResponse(reason, ""); + } + return null; }); + binding.reasonRv.setLayoutManager(new LinearLayoutManager(context)); + binding.reasonRv.addItemDecoration(new VerticalItemDecoration(context, 1F, false, R.color.text_f5f5f5)); + binding.reasonRv.setAdapter(reportReasonAdapter); binding.negativeBtn.setOnClickListener(v -> { binding.reasonTitle.setText(R.string.report_reason_title); @@ -2053,10 +2046,10 @@ public class DialogUtils { binding.positiveBtn.setOnClickListener(v -> { if (TextUtils.isEmpty(binding.otherReasonEt.getText().toString().trim())) { - ToastUtils.INSTANCE.showToast("请填写举报原因"); + ToastUtils.showToast("请填写举报原因"); } else { dialog.dismiss(); - callBack.onResponse("其它", binding.otherReasonEt.getText().toString()); + callBack.onResponse("其他原因", binding.otherReasonEt.getText().toString()); } }); diff --git a/app/src/main/java/com/gh/common/util/ErrorHelper.kt b/app/src/main/java/com/gh/common/util/ErrorHelper.kt index 5aff9508c8..901b42cf57 100644 --- a/app/src/main/java/com/gh/common/util/ErrorHelper.kt +++ b/app/src/main/java/com/gh/common/util/ErrorHelper.kt @@ -133,6 +133,8 @@ object ErrorHelper { 403022 -> Utils.toast(context, "不能回复自己") 403056 -> Utils.toast(context, "发布失败,字数已达上限") 403111 -> Utils.toast(context, "提交失败,评论违规") + 400001 -> Utils.toast(context, "字数超过500或者未填写原因") + 403102 -> Utils.toast(context, "你已经举报过该内容了哦") 403020 -> if (showHighPriorityHint) { DialogUtils.showAlertDialog( diff --git a/app/src/main/java/com/gh/common/util/SimpleRequestHelper.kt b/app/src/main/java/com/gh/common/util/SimpleRequestHelper.kt index af6ab3a6cf..bf9f29fc20 100644 --- a/app/src/main/java/com/gh/common/util/SimpleRequestHelper.kt +++ b/app/src/main/java/com/gh/common/util/SimpleRequestHelper.kt @@ -7,6 +7,7 @@ import com.lightgame.utils.Utils import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import okhttp3.ResponseBody +import org.json.JSONObject import retrofit2.HttpException /** @@ -23,11 +24,11 @@ object SimpleRequestHelper { .observeOn(AndroidSchedulers.mainThread()) .subscribe(object : Response() { override fun onResponse(response: ResponseBody?) { - Utils.toast(HaloApp.getInstance().application, "感谢您的投诉") + Utils.toast(HaloApp.getInstance().application, "举报成功") } override fun onFailure(e: HttpException?) { - ErrorHelper.handleError(HaloApp.getInstance().application, e?.response()?.errorBody()?.string()) + ErrorHelper.handleError(HaloApp.getInstance().application,e?.response()?.errorBody()?.string()) } }) @@ -41,11 +42,11 @@ object SimpleRequestHelper { .observeOn(AndroidSchedulers.mainThread()) .subscribe(object : Response() { override fun onResponse(response: ResponseBody?) { - Utils.toast(HaloApp.getInstance().application, "感谢您的投诉") + Utils.toast(HaloApp.getInstance().application, "举报成功") } override fun onFailure(e: HttpException?) { - ErrorHelper.handleError(HaloApp.getInstance().application, e?.response()?.errorBody()?.string()) + ErrorHelper.handleError(HaloApp.getInstance().application,e?.response()?.errorBody()?.string()) } }) diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ReportReasonAdapter.kt b/app/src/main/java/com/gh/gamecenter/adapter/ReportReasonAdapter.kt new file mode 100644 index 0000000000..cab6368e17 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/adapter/ReportReasonAdapter.kt @@ -0,0 +1,44 @@ +package com.gh.gamecenter.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.gh.common.util.goneIf +import com.gh.gamecenter.databinding.ItemReportReasonBinding +import com.lightgame.adapter.BaseRecyclerAdapter + +class ReportReasonAdapter( + context: Context, + val items: ArrayList, + val onItemClick: (String) -> Unit +) : + BaseRecyclerAdapter(context) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return ReportReasonViewHolder( + ItemReportReasonBinding.inflate( + LayoutInflater.from(mContext), + parent, + false + ) + ) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + if (holder is ReportReasonViewHolder) { + val item = items[position] + holder.binding.reasonTv.text = item + holder.binding.reasonArrowIv.goneIf(item != "其他原因") + holder.binding.root.setOnClickListener { + onItemClick.invoke(item) + } + } + } + + override fun getItemCount(): Int = items.size + + inner class ReportReasonViewHolder(val binding: ItemReportReasonBinding) : + RecyclerView.ViewHolder(binding.root) +} + diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescCommentsAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescCommentsAdapter.kt index f7591f8d96..eb60629c24 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescCommentsAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescCommentsAdapter.kt @@ -161,9 +161,11 @@ class DescCommentsAdapter(context: Context, "投诉" -> { MtaHelper.onEvent("游戏详情_新", "玩家评论_投诉", mViewModel.game?.name) mContext.ifLogin(BaseActivity.mergeEntranceAndPath(mEntrance, path)) { - OptionDialogHelper.showOptionDialog(mContext, Constants.REPORT_LIST.toList(), callback = { reportType -> - SimpleRequestHelper.reportGameComment(mViewModel.game!!.id, commentData.id, reportType) - }) + DialogUtils.showReportReasonDialog(mContext, + Constants.REPORT_LIST.toList() as java.util.ArrayList + ) { reason, desc -> + SimpleRequestHelper.reportGameComment(mViewModel.game?.id ?: "", commentData.id, if (reason != "其他原因") reason else desc) + } } } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingCommentItemViewHolder.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingCommentItemViewHolder.kt index 2ae652db37..1418bfc826 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingCommentItemViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingCommentItemViewHolder.kt @@ -37,6 +37,7 @@ import com.squareup.picasso.Picasso import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers +import java.util.ArrayList import java.util.regex.Pattern class RatingCommentItemViewHolder(val binding: RatingCommentItemBinding) : BaseRecyclerViewHolder(binding.root) { @@ -209,9 +210,11 @@ class RatingCommentItemViewHolder(val binding: RatingCommentItemBinding) : BaseR if (path == "游戏详情:评分") MtaHelper.onEvent("游戏详情_新", "评论Tab_投诉", game?.name) if (path == "折叠评论") MtaHelper.onEvent("折叠评论", "更多-投诉", game?.name) context.ifLogin(BaseActivity.mergeEntranceAndPath(entrance, path)) { - OptionDialogHelper.showOptionDialog(context, Constants.REPORT_LIST.toList(), callback = { reportType -> - SimpleRequestHelper.reportGameComment(game!!.id, commentData.id, reportType) - }) + DialogUtils.showReportReasonDialog(context, + Constants.REPORT_LIST.toList() as ArrayList + ) { reason, desc -> + SimpleRequestHelper.reportGameComment(game?.id ?: "", commentData.id, if (reason != "其他原因") reason else desc) + } } } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyAdapter.kt index d42fe4cd59..8bb9a65983 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyAdapter.kt @@ -362,10 +362,14 @@ class RatingReplyAdapter(context: Context, "投诉" -> { mContext.ifLogin("游戏详情-评分-评论详情- 投诉评论") { OptionDialogHelper.showOptionDialog(mContext, Constants.REPORT_LIST.toList(), callback = { reportType -> - SimpleRequestHelper.reportGameCommentReply( + DialogUtils.showReportReasonDialog(mContext, + Constants.REPORT_LIST.toList() as java.util.ArrayList + ) { reason, desc -> + SimpleRequestHelper.reportGameCommentReply( mEntityList[0].game!!.id, mEntityList[1].comment!!.id, - replyEntity.id, reportType) + replyEntity.id, if (reason != "其他原因") reason else desc) + } }) } } diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeFragment.kt b/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeFragment.kt index d93e75ae50..96a1b1f518 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeFragment.kt @@ -41,6 +41,7 @@ import com.halo.assistant.HaloApp import com.lightgame.utils.Utils import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.reuse_no_connection.* +import java.util.* import kotlin.math.abs class UserHomeFragment : NormalFragment() { @@ -61,7 +62,12 @@ class UserHomeFragment : NormalFragment() { override fun getLayoutId() = 0 override fun getInflatedLayout(): View { - mHomeBinding = DataBindingUtil.inflate(requireActivity().layoutInflater, R.layout.fragment_home, null, false) + mHomeBinding = DataBindingUtil.inflate( + requireActivity().layoutInflater, + R.layout.fragment_home, + null, + false + ) return mHomeBinding!!.root } @@ -71,7 +77,8 @@ class UserHomeFragment : NormalFragment() { mPath = arguments?.getString(EntranceUtils.KEY_PATH) ?: "" val userId = arguments?.getString(EntranceUtils.KEY_USER_ID) ?: "" - mUserHomeViewModel = viewModelProvider(UserHomeViewModel.Factory(HaloApp.getInstance().application, userId)) + mUserHomeViewModel = + viewModelProvider(UserHomeViewModel.Factory(HaloApp.getInstance().application, userId)) mUserViewModel = viewModelProvider(UserViewModel.Factory(HaloApp.getInstance().application)) mMessageUnreadViewModel = viewModelProvider() @@ -128,9 +135,17 @@ class UserHomeFragment : NormalFragment() { if (badge.wear) { ImageUtils.display(mHomeBinding?.badgeIcon, badge.icon) mHomeBinding?.badgeIcon?.setOnClickListener { - DialogUtils.showViewBadgeDialog(requireContext(), Badge(badge.name, badge.icon, badge.actions)) { + DialogUtils.showViewBadgeDialog( + requireContext(), + Badge(badge.name, badge.icon, badge.actions) + ) { if (::mPersonalEntity.isInitialized) { - directToBadgeWall(requireContext(), mPersonalEntity.id, mPersonalEntity.name, mPersonalEntity.icon) + directToBadgeWall( + requireContext(), + mPersonalEntity.id, + mPersonalEntity.name, + mPersonalEntity.icon + ) } } } @@ -234,7 +249,13 @@ class UserHomeFragment : NormalFragment() { set.run { clone(contentContainer) clear(R.id.user_icon, ConstraintSet.BOTTOM) - connect(R.id.user_icon, ConstraintSet.TOP, R.id.statusBarView, ConstraintSet.BOTTOM, 50F.dip2px()) + connect( + R.id.user_icon, + ConstraintSet.TOP, + R.id.statusBarView, + ConstraintSet.BOTTOM, + 50F.dip2px() + ) applyTo(contentContainer) } @@ -248,8 +269,15 @@ class UserHomeFragment : NormalFragment() { newSet.run { clone(contentContainer) clear(R.id.user_icon, ConstraintSet.TOP) - val marginBottom = newHeight - DisplayUtils.getStatusBarHeight(resources) - 50F.dip2px() - 96F.dip2px() - connect(R.id.user_icon, ConstraintSet.BOTTOM, R.id.user_background_container, ConstraintSet.BOTTOM, marginBottom) + val marginBottom = + newHeight - DisplayUtils.getStatusBarHeight(resources) - 50F.dip2px() - 96F.dip2px() + connect( + R.id.user_icon, + ConstraintSet.BOTTOM, + R.id.user_background_container, + ConstraintSet.BOTTOM, + marginBottom + ) applyTo(contentContainer) } } @@ -262,11 +290,20 @@ class UserHomeFragment : NormalFragment() { mHomeBinding?.run { appbar.addOnOffsetChangedListener(OnOffsetChangedListener { _: AppBarLayout?, verticalOffset: Int -> if (isAdded) { - val statusBarHeight = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) 0 else DisplayUtils.getStatusBarHeight(resources) + val statusBarHeight = + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) 0 else DisplayUtils.getStatusBarHeight( + resources + ) val absOffset = abs(verticalOffset) - val invisibleOffset = 264f.dip2px() - 50f.dip2px() - 2f.dip2px() - statusBarHeight + val invisibleOffset = + 264f.dip2px() - 50f.dip2px() - 2f.dip2px() - statusBarHeight if (absOffset < invisibleOffset) { - toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.transparent)) + toolbar.setBackgroundColor( + ContextCompat.getColor( + requireContext(), + R.color.transparent + ) + ) toolbarContainer.background = null userSmallContainer.visibility = View.GONE } else { @@ -274,7 +311,12 @@ class UserHomeFragment : NormalFragment() { toolbar.setBackgroundColor(R.color.white.toColor()) toolbarContainer.background = BitmapDrawable(resources, mBitmap) } else { - toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.theme)) + toolbar.setBackgroundColor( + ContextCompat.getColor( + requireContext(), + R.color.theme + ) + ) } userSmallContainer.visibility = View.VISIBLE } @@ -301,9 +343,14 @@ class UserHomeFragment : NormalFragment() { val tag = "android:switcher:${mHomeBinding?.viewpager?.id}:" val gameFragment = childFragmentManager.findFragmentByTag("${tag}0") - ?: UserGameFragment.getInstance(mUserHomeViewModel.userId, count.gameComment) + ?: UserGameFragment.getInstance(mUserHomeViewModel.userId, count.gameComment) val qaFragment = childFragmentManager.findFragmentByTag("${tag}1") - ?: UserHistoryFragment.getInstance(mUserHomeViewModel.userId, UserHistoryViewModel.SCENE.QUESTION_ANSWER, count, type) + ?: UserHistoryFragment.getInstance( + mUserHomeViewModel.userId, + UserHistoryViewModel.SCENE.QUESTION_ANSWER, + count, + type + ) // val videoFragment = childFragmentManager.findFragmentByTag("${tag}2") // ?: UserVideoHistoryFragment.getInstance(mUserHomeViewModel.userId, count) @@ -330,7 +377,8 @@ class UserHomeFragment : NormalFragment() { } private fun getTabView(title: String): View { - val view = LayoutInflater.from(HaloApp.getInstance().application.baseContext).inflate(R.layout.tab_item_user_home, null) + val view = LayoutInflater.from(HaloApp.getInstance().application.baseContext) + .inflate(R.layout.tab_item_user_home, null) val tabTitle = view.findViewById(R.id.tab_title) if (tabTitle is CheckedTextView) { tabTitle.text = title @@ -339,8 +387,16 @@ class UserHomeFragment : NormalFragment() { } private fun trackMtaEvent(name: String? = "") { - MtaHelper.onEvent("个人主页", mPath, StringUtils.combineTwoString(name, mUserHomeViewModel.userId)) - MtaHelper.onEvent("个人主页", "不区分位置", StringUtils.combineTwoString(name, mUserHomeViewModel.userId)) + MtaHelper.onEvent( + "个人主页", + mPath, + StringUtils.combineTwoString(name, mUserHomeViewModel.userId) + ) + MtaHelper.onEvent( + "个人主页", + "不区分位置", + StringUtils.combineTwoString(name, mUserHomeViewModel.userId) + ) } private fun updateUnreadInfo(messageEntity: MessageUnreadEntity) { @@ -369,23 +425,34 @@ class UserHomeFragment : NormalFragment() { // 截取背景图片,供toolbar使用 if (!personalData.background?.url.isNullOrEmpty()) { - ImageUtils.getBitmap(personalData.background?.url ?: "", object : BiCallback { - override fun onFirst(first: Bitmap) { - userBackground.postDelayed({ - if (activity?.isFinishing == false && !isStateSaved) { - val statusBarHeight = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) 0 else DisplayUtils.getStatusBarHeight(resources) - val bitmap = getBitmapFromView(userBackground) - bitmap?.let { - mBitmap = Bitmap.createBitmap(it, 0, it.height - statusBarHeight - 50f.dip2px(), it.width, statusBarHeight + 50f.dip2px()) + ImageUtils.getBitmap( + personalData.background?.url ?: "", + object : BiCallback { + override fun onFirst(first: Bitmap) { + userBackground.postDelayed({ + if (activity?.isFinishing == false && !isStateSaved) { + val statusBarHeight = + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) 0 else DisplayUtils.getStatusBarHeight( + resources + ) + val bitmap = getBitmapFromView(userBackground) + bitmap?.let { + mBitmap = Bitmap.createBitmap( + it, + 0, + it.height - statusBarHeight - 50f.dip2px(), + it.width, + statusBarHeight + 50f.dip2px() + ) + } } - } - }, 1000) - } + }, 1000) + } - override fun onSecond(second: Boolean) { - Utils.log("获取背景图片失败") - } - }) + override fun onSecond(second: Boolean) { + Utils.log("获取背景图片失败") + } + }) } // 设置有边框挂件的头像 @@ -411,7 +478,11 @@ class UserHomeFragment : NormalFragment() { userChangeBgBtn.visibility = View.VISIBLE recentVisitContainer.visibility = View.VISIBLE recentVisitIcon.setOnClickListener { - DirectUtils.directToHomeActivity(requireContext(), personalData.lastVisitor?.id, "个人主页-最近来访") + DirectUtils.directToHomeActivity( + requireContext(), + personalData.lastVisitor?.id, + "个人主页-最近来访" + ) } // 默认显示悬浮窗,点击图标进入更换背景页,悬浮窗消失 @@ -439,7 +510,12 @@ class UserHomeFragment : NormalFragment() { // 个性签名 userIntroduce.setOnClickListener { IntegralLogHelper.log("click_what's_up", LOCATION) - startActivity(UserInfoEditActivity.getIntent(context, UserViewModel.TYPE_INTRODUCE)) + startActivity( + UserInfoEditActivity.getIntent( + context, + UserViewModel.TYPE_INTRODUCE + ) + ) } } @@ -447,14 +523,24 @@ class UserHomeFragment : NormalFragment() { personalData.background?.url?.let { userBackground.setOnClickListener { - startActivity(ImageViewerActivity.getIntent(requireContext(), arrayListOf(personalData.background!!.url), 0, userIcon, "$mEntrance+($mPath)", true)) + startActivity( + ImageViewerActivity.getIntent( + requireContext(), + arrayListOf(personalData.background!!.url), + 0, + userIcon, + "$mEntrance+($mPath)", + true + ) + ) } } // 礼仪测试标签 regulationTestContainer.setOnClickListener { if (::mPersonalEntity.isInitialized - && mUserHomeViewModel.userId == UserManager.getInstance().userId) { + && mUserHomeViewModel.userId == UserManager.getInstance().userId + ) { IntegralLogHelper.log("click_test_label", LOCATION) DialogUtils.showPassRegulationDialog(requireContext(), mPersonalEntity.icon) } @@ -464,7 +550,12 @@ class UserHomeFragment : NormalFragment() { badgeContainer.setOnClickListener { if (::mPersonalEntity.isInitialized) { IntegralLogHelper.log("click_badge_label", LOCATION) - directToBadgeWall(requireContext(), mPersonalEntity.id, mPersonalEntity.name, mPersonalEntity.icon) + directToBadgeWall( + requireContext(), + mPersonalEntity.id, + mPersonalEntity.name, + mPersonalEntity.icon + ) } } @@ -477,24 +568,50 @@ class UserHomeFragment : NormalFragment() { MtaHelper.onEvent("个人主页详情", "个人主页详情", "头像") startActivity(AvatarBorderActivity.getIntent(requireContext())) } else { - startActivity(ImageViewerActivity.getIntent(requireContext(), arrayListOf(personalData.icon), 0, userIcon, "$mEntrance+($mPath)", true)) + startActivity( + ImageViewerActivity.getIntent( + requireContext(), + arrayListOf(personalData.icon), + 0, + userIcon, + "$mEntrance+($mPath)", + true + ) + ) } } userFollowerContainer.setOnClickListener { IntegralLogHelper.log("click_follow", LOCATION) MtaHelper.onEvent("个人主页详情", "个人主页详情", "关注数") - startActivity(FollowersActivity.getIntent(requireContext(), mUserHomeViewModel.userId, mEntrance, mPath)) + startActivity( + FollowersActivity.getIntent( + requireContext(), + mUserHomeViewModel.userId, + mEntrance, + mPath + ) + ) } userFansContainer.setOnClickListener { IntegralLogHelper.log("click_follower", LOCATION) MtaHelper.onEvent("个人主页详情", "个人主页详情", "粉丝数") - requireContext().startActivity(FansActivity.getIntent(requireContext(), mUserHomeViewModel.userId, mEntrance, mPath)) + requireContext().startActivity( + FansActivity.getIntent( + requireContext(), + mUserHomeViewModel.userId, + mEntrance, + mPath + ) + ) } userVoteContainer.setOnClickListener { IntegralLogHelper.log("click_like", LOCATION) MtaHelper.onEvent("个人主页详情", "个人主页详情", "赞同数") - Utils.toast(requireContext(), "共获得 " + NumberUtils.transSimpleCount(entity?.count?.vote!!) + " 赞同") + Utils.toast( + requireContext(), + "共获得 " + NumberUtils.transSimpleCount(entity?.count?.vote!!) + " 赞同" + ) } userEditBtn.setOnClickListener { IntegralLogHelper.log("click_edit", LOCATION) @@ -511,10 +628,17 @@ class UserHomeFragment : NormalFragment() { userConcernedBtn.setOnClickListener { ifLogin("个人主页-关注-[关注]") { MtaHelper.onEvent("个人主页详情", "个人主页详情", "关注按钮") - DialogUtils.showAlertDialog(requireContext(), "取消关注", "确定要取消关注 ${personalData.name} 吗?", - "确定取消", "暂不取消", DialogUtils.ConfirmListener { - mUserHomeViewModel.unFollow() - }, null) + DialogUtils.showAlertDialog( + requireContext(), + "取消关注", + "确定要取消关注 ${personalData.name} 吗?", + "确定取消", + "暂不取消", + DialogUtils.ConfirmListener { + mUserHomeViewModel.unFollow() + }, + null + ) } } @@ -566,23 +690,30 @@ class UserHomeFragment : NormalFragment() { if (!::mPopupWindow.isInitialized) { val contentView = View.inflate(activity, R.layout.popup_user_home_more, null) mPopupWindow = PopupWindow( - contentView, - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT + contentView, + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT ) contentView.run { findViewById(R.id.shareBtn) - .setOnClickListener { - IntegralLogHelper.log("click_share", "更多面板") - mPopupWindow.dismiss() - shareUserHome() - } + .setOnClickListener { + IntegralLogHelper.log("click_share", "更多面板") + mPopupWindow.dismiss() + shareUserHome() + } findViewById(R.id.reportBtn).setOnClickListener { IntegralLogHelper.log("click_report", "更多面板") mPopupWindow.dismiss() - DialogUtils.showReportReasonDialog(requireContext()) { reason, desc -> + val items = arrayListOf( + context.getString(R.string.report_reason_one), + context.getString(R.string.report_reason_two), + context.getString(R.string.report_reason_three), + context.getString(R.string.report_reason_four), + context.getString(R.string.report_reason_other) + ) + DialogUtils.showReportReasonDialog(requireContext(), items) { reason, desc -> mUserHomeViewModel.postReport(reason, desc) } } @@ -603,18 +734,20 @@ class UserHomeFragment : NormalFragment() { (if (mBadgeCount == 0) "" else "给力~ 已领取 $mBadgeCount 枚徽章\n") + "要好玩,上光环" if (::mPersonalEntity.isInitialized) { - ShareUtils.getInstance(requireContext()).showShareUserHomeWindows(requireActivity(), - mHomeBinding?.root, - if ("internal" == BuildConfig.FLAVOR) { - Constants.SHARE_USER_HOME_ADDRESS_DEV - } else { - Constants.SHARE_USER_HOME_ADDRESS - } + "?user=${mPersonalEntity.id}", - mPersonalEntity.icon, - "【推荐】来自光环助手的${mPersonalEntity.name}", - content, - ShareUtils.ShareEntrance.userHome, - mPersonalEntity.id, null) + ShareUtils.getInstance(requireContext()).showShareUserHomeWindows( + requireActivity(), + mHomeBinding?.root, + if ("internal" == BuildConfig.FLAVOR) { + Constants.SHARE_USER_HOME_ADDRESS_DEV + } else { + Constants.SHARE_USER_HOME_ADDRESS + } + "?user=${mPersonalEntity.id}", + mPersonalEntity.icon, + "【推荐】来自光环助手的${mPersonalEntity.name}", + content, + ShareUtils.ShareEntrance.userHome, + mPersonalEntity.id, null + ) } } diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeViewModel.kt b/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeViewModel.kt index 9c092580be..74bb332798 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/UserHomeViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.gh.common.util.EnergyTaskHelper +import com.gh.common.util.ErrorHelper import com.gh.common.util.ToastUtils import com.gh.common.util.createRequestBody import com.gh.gamecenter.R @@ -167,7 +168,7 @@ class UserHomeViewModel(application: Application, var userId: String) : AndroidV fun postReport(reason: String, desc: String) { val requestMap = hashMapOf() requestMap["reason"] = reason - if (reason == "其它") { + if (reason == "其他原因") { requestMap["description"] = desc } RetrofitManager.getInstance(getApplication()) @@ -182,20 +183,7 @@ class UserHomeViewModel(application: Application, var userId: String) : AndroidV override fun onFailure(exception: Exception) { super.onFailure(exception) if (exception is HttpException) { - try { - val responseBody = exception.response().errorBody() - val string = responseBody!!.string() - val content = JSONObject(string) - when (val code = content.getInt("code")) { - 403102 -> ToastUtils.showToast("你已经举报过该用户了哦") - - 400001 -> ToastUtils.showToast("字数超过500或者未填写原因") - - else -> ToastUtils.showToast(code.toString()) - } - } catch (e1: Exception) { - e1.printStackTrace() - } + ErrorHelper.handleError(HaloApp.getInstance().application, exception.response().errorBody()?.string()) } } }) diff --git a/app/src/main/res/layout/dialog_report_reason.xml b/app/src/main/res/layout/dialog_report_reason.xml index 5bade728cb..0ea4587fb8 100644 --- a/app/src/main/res/layout/dialog_report_reason.xml +++ b/app/src/main/res/layout/dialog_report_reason.xml @@ -5,7 +5,7 @@ @@ -24,12 +24,18 @@ - + + + + + + + + \ No newline at end of file