From 169814d6a9c6a37ac61ba7d509d06efcfb5afccc Mon Sep 17 00:00:00 2001 From: lyr <15622190878@163.com> Date: Tue, 23 Mar 2021 18:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=89=E7=8E=AF=E5=8A=A9=E6=89=8BV4.7.0-?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E4=BD=93=E7=B3=BB=EF=BC=88=E7=AC=AC2?= =?UTF-8?q?=E6=9C=9F=EF=BC=89--=E9=82=80=E8=AF=B7=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=EF=BC=88V4.7.0-=E7=A7=AF=E5=88=86=E4=BD=93=E7=B3=BB=EF=BC=88?= =?UTF-8?q?=E7=AC=AC2=E6=9C=9F=EF=BC=89--=E9=82=80=E8=AF=B7=E5=A5=BD?= =?UTF-8?q?=E5=8F=8B-UI=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98-4=E3=80=810319?= =?UTF-8?q?=20=E4=BA=A7=E5=93=81=E9=AA=8C=E6=94=B6=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E7=AC=AC1=E7=82=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gh/common/DefaultJsApi.kt | 2 +- .../energy/HorizontalTaskAdapter.kt | 20 +-- .../gh/gamecenter/energy/InviteCodeHelper.kt | 163 ------------------ .../com/gh/gamecenter/energy/TaskAdapter.kt | 20 +-- .../gamedetail/dialog/InviteCodeDialog.kt | 119 +++++++++++++ .../security/BindPhoneConflictFragment.kt | 1 - ...invite_bind.xml => dialog_invite_bind.xml} | 0 ...invite_code.xml => dialog_invite_code.xml} | 55 +++++- 8 files changed, 189 insertions(+), 191 deletions(-) delete mode 100644 app/src/main/java/com/gh/gamecenter/energy/InviteCodeHelper.kt create mode 100644 app/src/main/java/com/gh/gamecenter/gamedetail/dialog/InviteCodeDialog.kt rename app/src/main/res/layout/{popup_invite_bind.xml => dialog_invite_bind.xml} (100%) rename app/src/main/res/layout/{popup_invite_code.xml => dialog_invite_code.xml} (60%) diff --git a/app/src/main/java/com/gh/common/DefaultJsApi.kt b/app/src/main/java/com/gh/common/DefaultJsApi.kt index 41cae2f25f..ee0e5d9b38 100644 --- a/app/src/main/java/com/gh/common/DefaultJsApi.kt +++ b/app/src/main/java/com/gh/common/DefaultJsApi.kt @@ -244,7 +244,7 @@ class DefaultJsApi(var context: Context) { Base64ImageHolder.image = inviteEvent.poster.run { if (this.startsWith("data:image/png;base64")) this.split(",")[1] else this } - MessageShareUtils.getInstance(context).shareFromWeb(context, inviteEvent.way) + MessageShareUtils.getInstance(context).shareInviteFriends(context, inviteEvent.way) } else { ShareUtils.getInstance(context).shareInviteFriends(context, inviteEvent.url, inviteEvent.way) } diff --git a/app/src/main/java/com/gh/gamecenter/energy/HorizontalTaskAdapter.kt b/app/src/main/java/com/gh/gamecenter/energy/HorizontalTaskAdapter.kt index 80a09665e5..5dd7fe6163 100644 --- a/app/src/main/java/com/gh/gamecenter/energy/HorizontalTaskAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/energy/HorizontalTaskAdapter.kt @@ -1,8 +1,8 @@ package com.gh.gamecenter.energy -import android.app.Activity import android.content.Context import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import com.gh.base.BaseRecyclerViewHolder import com.gh.common.constant.Constants @@ -10,6 +10,7 @@ import com.gh.common.util.* import com.gh.gamecenter.R import com.gh.gamecenter.databinding.NoviceTaskItemBinding import com.gh.gamecenter.entity.TaskEntity +import com.gh.gamecenter.gamedetail.dialog.InviteCodeDialog import com.gh.gamecenter.manager.UserManager import com.lightgame.adapter.BaseRecyclerAdapter @@ -63,16 +64,13 @@ class HorizontalTaskAdapter(context: Context, when (task.status) { "normal" -> { if (task.action == "enter_invite_code") { - if (UserManager.getInstance().userInfoEntity?.loginMobile.isNullOrEmpty()) { - InviteCodeHelper.showBindPhonePopUp(mContext as Activity) - } else { - InviteCodeHelper.showInviteCodePopUp( - mContext as Activity, - "task_list") - { - task.status = "finished" - notifyItemChanged(position) - } + InviteCodeDialog.showInviteCodeDialog( + mContext as AppCompatActivity, + UserManager.getInstance().userInfoEntity?.loginMobile?.isNotEmpty() ?: false, + "task_list") + { + task.status = "finished" + notifyItemChanged(position) } } else { SPUtils.setBoolean(Constants.SP_SHOW_TASK_FLOAT, true) diff --git a/app/src/main/java/com/gh/gamecenter/energy/InviteCodeHelper.kt b/app/src/main/java/com/gh/gamecenter/energy/InviteCodeHelper.kt deleted file mode 100644 index 43e323d83e..0000000000 --- a/app/src/main/java/com/gh/gamecenter/energy/InviteCodeHelper.kt +++ /dev/null @@ -1,163 +0,0 @@ -package com.gh.gamecenter.energy - -import android.annotation.SuppressLint -import android.app.Activity -import android.view.Gravity -import android.view.View -import android.widget.* -import com.gh.common.util.* -import com.gh.gamecenter.R -import com.gh.gamecenter.manager.UserManager -import com.gh.gamecenter.retrofit.BiResponse -import com.gh.gamecenter.retrofit.RetrofitManager -import com.gh.gamecenter.security.BindPhoneActivity -import com.halo.assistant.HaloApp -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.schedulers.Schedulers -import okhttp3.MediaType -import okhttp3.RequestBody -import okhttp3.ResponseBody -import org.json.JSONObject - -/** - * 邀请码弹窗辅助类 - */ -object InviteCodeHelper: KeyboardHeightObserver { - - private var mKeyboardHeightProvider: KeyboardHeightProvider? = null - private var contentView: View? = null - - // 绑定手机弹窗 - @JvmStatic - fun showBindPhonePopUp (activity: Activity) { - val contentView = View.inflate(activity, R.layout.popup_invite_bind, null) - val popWindow = PopupWindow ( - contentView, - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.MATCH_PARENT - ) - - contentView.run { - findViewById(R.id.closeIv) - .setOnClickListener { - if (popWindow != null && popWindow.isShowing) { - popWindow.dismiss() - } - } - - findViewById(R.id.bindBtn).setOnClickListener { - activity.startActivity(BindPhoneActivity.getNormalIntent(activity, false)) - } - - isFocusable = true - isFocusableInTouchMode = true - - setOnClickListener { - if (popWindow != null && popWindow.isShowing) { - popWindow.dismiss() - } - } - } - - popWindow.run { - isClippingEnabled = false - showAtLocation( - activity.window.decorView, - Gravity.BOTTOM, 0, 0 - ) - } - } - - // 好友邀请码弹窗 - @JvmStatic - fun showInviteCodePopUp (activity: Activity, from: String, callback: () -> Unit) { - mKeyboardHeightProvider = KeyboardHeightProvider(activity) - mKeyboardHeightProvider?.start() - mKeyboardHeightProvider?.setKeyboardHeightObserver(this) - - contentView = View.inflate(activity, R.layout.popup_invite_code, null) - val popWindow = PopupWindow ( - contentView, - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.MATCH_PARENT - ) - - contentView?.run { - findViewById(R.id.closeIv) - .setOnClickListener { - if (popWindow != null && popWindow.isShowing) { - popWindow.dismiss() - } - } - - val inviteCodeEt = findViewById(R.id.inviteEt) - findViewById(R.id.confirmBtn).setOnClickListener { - val code = inviteCodeEt.text.toString().trim { it <= ' ' }.replace(" ".toRegex(), "") - val newCallback = { - if (popWindow != null && popWindow.isShowing) { - popWindow.dismiss() - } - callback.invoke() - } - checkInviteCode(code, from, newCallback, {}) - } - - isFocusable = true - isFocusableInTouchMode = true - - setOnClickListener { - if (popWindow != null && popWindow.isShowing) { - popWindow.dismiss() - } - } - } - - popWindow.run { - isFocusable = true - isClippingEnabled = false - - setOnDismissListener { - mKeyboardHeightProvider?.close() - } - - showAtLocation( - activity.window.decorView, - Gravity.BOTTOM, 0, 0 - ) - } - } - - @SuppressLint("CheckResult") - @JvmStatic - fun checkInviteCode(code: String, from: String, successCallback: () -> Unit, failCallback: () -> Unit) { - val params = JSONObject() - params.put("code", code) - params.put("type", "new") - params.put("from", "from") - - val body = RequestBody.create(MediaType.parse("application/json"), params.toString()) - RetrofitManager.getInstance(HaloApp.getInstance().application) - .api.checkInviteCode(UserManager.getInstance().userId, body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : BiResponse() { - override fun onSuccess(data: ResponseBody) { - EnergyTaskHelper.postInviteCodeTask(code, from, successCallback, failCallback) - } - - override fun onFailure(exception: Exception) { - super.onFailure(exception) - ToastUtils.showToast("邀请码错误") - failCallback.invoke() -// EnergyTaskHelper.postInviteCodeTask(code, from, callback) - } - }) - } - - override fun onKeyboardHeightChanged(height: Int, orientation: Int) { - contentView?.setPadding( - 0, 0, 0, - if (height > 0) height else 0 - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/energy/TaskAdapter.kt b/app/src/main/java/com/gh/gamecenter/energy/TaskAdapter.kt index 9a42ee48a9..aba69f6c92 100644 --- a/app/src/main/java/com/gh/gamecenter/energy/TaskAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/energy/TaskAdapter.kt @@ -1,9 +1,9 @@ package com.gh.gamecenter.energy -import android.app.Activity import android.content.Context import android.view.View import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -16,6 +16,7 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder import com.gh.gamecenter.baselist.ListAdapter import com.gh.gamecenter.baselist.LoadStatus import com.gh.gamecenter.databinding.* +import com.gh.gamecenter.gamedetail.dialog.InviteCodeDialog import com.gh.gamecenter.manager.UserManager class TaskAdapter(context: Context) : ListAdapter(context) { @@ -153,16 +154,13 @@ class TaskAdapter(context: Context) : ListAdapter(context) { when (task.status) { "normal" -> { if (task.action == "enter_invite_code") { - if (UserManager.getInstance().userInfoEntity?.loginMobile.isNullOrEmpty()) { - InviteCodeHelper.showBindPhonePopUp(mContext as Activity) - } else { - InviteCodeHelper.showInviteCodePopUp( - mContext as Activity, - "task_list") - { - task.status = "finished" - notifyItemChanged(position) - } + InviteCodeDialog.showInviteCodeDialog( + mContext as AppCompatActivity, + UserManager.getInstance().userInfoEntity?.loginMobile?.isNotEmpty() ?: false, + "task_list") + { + task.status = "finished" + notifyItemChanged(position) } } else { SPUtils.setBoolean(Constants.SP_SHOW_TASK_FLOAT, true) diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/dialog/InviteCodeDialog.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/dialog/InviteCodeDialog.kt new file mode 100644 index 0000000000..0f110ea3d5 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/dialog/InviteCodeDialog.kt @@ -0,0 +1,119 @@ +package com.gh.gamecenter.gamedetail.dialog + +import android.annotation.SuppressLint +import android.os.Bundle +import android.view.* +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.FragmentTransaction +import com.gh.common.dialog.BaseDraggableDialogFragment +import com.gh.common.util.EnergyTaskHelper +import com.gh.common.util.ToastUtils +import com.gh.gamecenter.databinding.DialogInviteCodeBinding +import com.gh.gamecenter.manager.UserManager +import com.gh.gamecenter.retrofit.BiResponse +import com.gh.gamecenter.retrofit.RetrofitManager +import com.gh.gamecenter.security.BindPhoneActivity +import com.halo.assistant.HaloApp +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers +import okhttp3.MediaType +import okhttp3.RequestBody +import okhttp3.ResponseBody +import org.json.JSONObject + +class InviteCodeDialog : BaseDraggableDialogFragment() { + + private lateinit var mBinding: DialogInviteCodeBinding + var isBind: Boolean = false + var from: String = "" + var callback: () -> Unit = {} + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return DialogInviteCodeBinding.inflate(inflater, container, false).apply { mBinding = this }.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + mBinding.run { + if (isBind) { + bindPhoneContainer.visibility = View.GONE + inviteCodeContainer.visibility = View.VISIBLE + } else { + bindPhoneContainer.visibility = View.VISIBLE + inviteCodeContainer.visibility = View.GONE + } + + bindCloseIv.setOnClickListener { + dismissAllowingStateLoss() + } + + bindBtn.setOnClickListener { + requireActivity().startActivity(BindPhoneActivity.getNormalIntent(requireActivity(), false)) + dismissAllowingStateLoss() + } + + inviteCloseIv.setOnClickListener { + dismissAllowingStateLoss() + } + + confirmBtn.setOnClickListener { + val code = inviteEt.text.toString().trim { it <= ' ' }.replace(" ".toRegex(), "") + val newCallback = { + dismissAllowingStateLoss() + callback.invoke() + } + checkInviteCode(code, from, newCallback, {}) + } + } + } + + @SuppressLint("CheckResult") + fun checkInviteCode(code: String, from: String, successCallback: () -> Unit, failCallback: () -> Unit) { + val params = JSONObject() + params.put("code", code) + params.put("type", "new") + params.put("from", "from") + + val body = RequestBody.create(MediaType.parse("application/json"), params.toString()) + RetrofitManager.getInstance(HaloApp.getInstance().application) + .api.checkInviteCode(UserManager.getInstance().userId, body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + EnergyTaskHelper.postInviteCodeTask(code, from, successCallback, failCallback) + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + ToastUtils.showToast("邀请码错误") + failCallback.invoke() + } + }) + } + + override fun getRootView(): View = mBinding.root + override fun getDragCloseView(): View = if (isBind) mBinding.inviteCloseIv else mBinding.bindCloseIv + + companion object { + @JvmStatic + fun showInviteCodeDialog(activity: AppCompatActivity, isBind: Boolean, from: String, callback: () -> Unit) { + var fragment = activity.supportFragmentManager.findFragmentByTag(InviteCodeDialog::class.java.name) as? InviteCodeDialog + if (fragment == null) { + fragment = InviteCodeDialog() + fragment.isBind = isBind + fragment.from = from + fragment.callback = callback + fragment.show(activity.supportFragmentManager, InviteCodeDialog::class.java.name) + } else { + fragment.isBind = isBind + fragment.from = from + fragment.callback = callback + val transaction: FragmentTransaction = activity.supportFragmentManager.beginTransaction() + transaction.show(fragment) + transaction.commit() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/security/BindPhoneConflictFragment.kt b/app/src/main/java/com/gh/gamecenter/security/BindPhoneConflictFragment.kt index 89ac6081b6..fc1cd24191 100644 --- a/app/src/main/java/com/gh/gamecenter/security/BindPhoneConflictFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/security/BindPhoneConflictFragment.kt @@ -93,7 +93,6 @@ class BindPhoneConflictFragment : NormalFragment() { mContentView = layoutInflater.inflate(R.layout.dialog_conflict_guide, null) mPopupWindow = PopupWindow(mContentView, 330f.dip2px(), ViewGroup.LayoutParams.WRAP_CONTENT) mPopupWindow.run { - contentView = contentView isOutsideTouchable = true isFocusable = true } diff --git a/app/src/main/res/layout/popup_invite_bind.xml b/app/src/main/res/layout/dialog_invite_bind.xml similarity index 100% rename from app/src/main/res/layout/popup_invite_bind.xml rename to app/src/main/res/layout/dialog_invite_bind.xml diff --git a/app/src/main/res/layout/popup_invite_code.xml b/app/src/main/res/layout/dialog_invite_code.xml similarity index 60% rename from app/src/main/res/layout/popup_invite_code.xml rename to app/src/main/res/layout/dialog_invite_code.xml index c0f3f78850..e8858e4295 100644 --- a/app/src/main/res/layout/popup_invite_code.xml +++ b/app/src/main/res/layout/dialog_invite_code.xml @@ -5,7 +5,56 @@ android:background="@color/bg_popup"> + + + + + + + + + + +