• Kotlin高仿微信-第57篇-VIP管理列表


      Kotlin高仿微信-项目实践58篇详细讲解了各个功能点,包括:注册、登录、主页、单聊(文本、表情、语音、图片、小视频、视频通话、语音通话、红包、转账)、群聊、个人信息、朋友圈、支付服务、扫一扫、搜索好友、添加好友、开通VIP等众多功能。

    Kotlin高仿微信-项目实践58篇,点击查看详情

    效果图:

    实现代码:

    
    
        
    
            
    
            
    
            
    
            
    
        
    

    /**
     * Author : wangning
     * Email : maoning20080809@163.com
     * Date : 2022/6/19 22:58
     * Description : Vip管理页面
     */
    class VipManagerFragment : BaseDataBindingFragment(){
    
        override fun getLayoutRes() = R.layout.wc_vip_manager_main
        private var adapter: VipManagerAdapter = VipManagerAdapter(mutableListOf())
        private val vipManagerViewModel : VipManagerViewModel by viewModels()
        private val userViewModel: UserViewModel by viewModels()
    
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
    
            super.builder().setTitleContent(R.string.wc_base_top_vip_manager)
    
            var linearLayoutManager = LinearLayoutManager(requireContext())
            linearLayoutManager?.orientation = LinearLayoutManager.VERTICAL
            vip_recyclerview.layoutManager = linearLayoutManager
            vip_recyclerview.adapter = adapter
    
            var account = DataStoreUtils.getAccount()
            var userBean = userViewModel.getUserLocalAsync(account)
            TagUtils.d("获取vip操作员账号:${userBean.account}, ${userBean.nickName}")
            adapter.setOperatorName(userBean.nickName)
            adapter.setOnItemClick(object : OnItemClickVip{
                override fun onItemClick(month: Int, vipBean: VipBean) {
                    showVipConfirmDialog(month, vipBean)
                }
            })
            vipManagerViewModel.getVipListServer(0)
            vipManagerViewModel.vipListServer.observe(viewLifecycleOwner){
                if(it == null){
                    ToastUtils.makeText(R.string.wc_load_data_error)
                } else {
                  adapter.refresh(it)
                }
            }
    
            vipManagerViewModel.isSuccessLiveData.observe(viewLifecycleOwner){
                if(it){
                    ToastUtils.makeText(R.string.wc_vip_renewal_success)
                } else {
                    ToastUtils.makeText(R.string.wc_vip_renewal_failure)
                }
            }
    
            vip_query_btn.setOnClickListener {
                if(TextUtils.isEmpty(vip_query_name.text.toString().trim())){
                    ToastUtils.makeText(R.string.wc_query_name_empty)
                } else {
                    vipManagerViewModel.getVipListLikeServer(0, vip_query_name.text.toString().trim())
                }
            }
    
        }
    
        /**
         * 开通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(R.id.vip_confirm_account)
            var nameTextView = view.findViewById(R.id.vip_confirm_name)
            var monthTextView = view.findViewById(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(R.id.vip_confirm_cancel).setOnClickListener {
                popupWindow.dismiss()
            }
    
            view.findViewById(R.id.vip_confirm_ok).setOnClickListener {
                popupWindow.dismiss()
                vipManagerViewModel.updateVip(vipBean.userAccount, vipBean.operatorAccount, month)
            }
        }
    
        private fun getFocus(isForbidBack : Boolean){
            view?.isFocusableInTouchMode = true
            view?.requestFocus()
            view?.setOnKeyListener { view, keyCode, event ->
                if(event.action == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
                    if(isForbidBack){
                        ToastUtils.makeText(R.string.wc_vip_confirm_back)
                    }
                }
                isForbidBack
            }
        }
    
    }

  • 相关阅读:
    cx3588 display_framework_config
    PMP考试点01
    【React篇】组件错误边界处理(组件错误引起的页面白屏)
    idea的GsonFormatPlus插件教程
    Kmeans
    【H5写雷达图】使用h5写雷达图等动态图表(两种方式实现)
    y118.第七章 服务网格与治理-Istio从入门到精通 -- Istio流量治理快速入门(四)
    Python学习小组课程-课程大纲与Python开发环境安装
    elk安装篇之 Kibana安装
    Spring的@Async使用防坑
  • 原文地址:https://blog.csdn.net/maoning20080808/article/details/128138539