Kotlin高仿微信-第58篇-开通VIP
实现代码:
**
* 开通vip确认框
*/
private fun showVipConfirmDialog(month: Int, vipBean: VipBean){
if(month < 1 || vipBean == null){
ToastUtils.makeText(R.string.wc_vip_confirm_show_error)
return
}
getFocus(true)
var view = LayoutInflater.from(requireContext()).inflate(R.layout.wc_vip_confirm_view, null)
var width = DisplayUtils.getScreenWidth() - BaseUtils.getDimension(R.dimen.distance_40) * 2
val popupWindow = PopupWindow(view, width, ViewGroup.LayoutParams.WRAP_CONTENT)
popupWindow.isOutsideTouchable = false //点击弹窗外部是否取消弹窗
//弹窗出现外部为阴影
val attributes: WindowManager.LayoutParams = requireActivity().window.getAttributes()
attributes.alpha = 0.5f
requireActivity().window.setAttributes(attributes)
//弹窗取消监听 取消之后恢复阴影
popupWindow.setOnDismissListener {
val attributes: WindowManager.LayoutParams = requireActivity().window.getAttributes()
attributes.alpha = 1f
requireActivity().window.setAttributes(attributes)
getFocus(false)
}
popupWindow.showAtLocation(vip_recyclerview, Gravity.CENTER, 0, 0)
var accountTextView = view.findViewById<TextView>(R.id.vip_confirm_account)
var nameTextView = view.findViewById<TextView>(R.id.vip_confirm_name)
var monthTextView = view.findViewById<TextView>(R.id.vip_confirm_month)
accountTextView.text = BaseUtils.getString(R.string.wc_vip_manager_user_account, vipBean.userAccount)
nameTextView.text = BaseUtils.getString(R.string.wc_vip_manager_user_name, vipBean.userName)
monthTextView.text = BaseUtils.getString(R.string.wc_vip_confirm_month, "${month}")
view.findViewById<TextView>(R.id.vip_confirm_cancel).setOnClickListener {
popupWindow.dismiss()
}
view.findViewById<TextView>(R.id.vip_confirm_ok).setOnClickListener {
popupWindow.dismiss()
vipManagerViewModel.updateVip(vipBean.userAccount, vipBean.operatorAccount, month)
}
}
/**
* vip会员续费
*/
fun updateVip(userAccount : String, operatorAccount : String, month : Int){
if(TextUtils.isEmpty(userAccount)
||TextUtils.isEmpty(operatorAccount)
|| month < 1){
isSuccessLiveData.postValue(false)
return
}
CoroutineScope(Dispatchers.IO).launch {
var result = VipManagerRepository.updateVip(userAccount, operatorAccount, month)
isSuccessLiveData.postValue(result.isSuccess)
}
}
