Commit fcad0507 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 93dca57a
...@@ -6,9 +6,49 @@ import com.duben.miniplaylet.mvp.model.DrawInfoBean ...@@ -6,9 +6,49 @@ import com.duben.miniplaylet.mvp.model.DrawInfoBean
import com.duben.miniplaylet.mvp.views.DrawCashView import com.duben.miniplaylet.mvp.views.DrawCashView
import com.duben.library.net.neterror.BaseSubscriber import com.duben.library.net.neterror.BaseSubscriber
import com.duben.library.net.neterror.Throwable import com.duben.library.net.neterror.Throwable
import com.duben.miniplaylet.manager.UserManager
import com.duben.miniplaylet.mvp.model.UserBean
import java.util.HashMap
class DrawCashPresenter : BasePresenter<DrawCashView>() { class DrawCashPresenter : BasePresenter<DrawCashView>() {
/**
* 微信登录
*/
fun wxLogin(wxInfo: String) {
view.showLoading("加载中...")
val vo = HashMap<String, Any>()
vo["wxInfo"] = wxInfo
AppHttpManager.getInstance(loanApplication)
.call(loanService.wechatlogin(vo),
object : BaseSubscriber<BaseResponse<UserBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<UserBean>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
val data = baseResponse.data
when (code) {
200 -> if (data != null) {
UserManager.getInstance().saveUserInfo(data)
view.showToast("微信授权成功")
}
else -> view.showToast(message)
}
}
})
}
fun cashPageCoin() { fun cashPageCoin() {
AppHttpManager.getInstance(loanApplication) AppHttpManager.getInstance(loanApplication)
.call(loanService.cashPageCoin(), .call(loanService.cashPageCoin(),
......
...@@ -8,6 +8,9 @@ import android.view.View ...@@ -8,6 +8,9 @@ import android.view.View
import android.widget.RadioGroup import android.widget.RadioGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.friends.Wechat
import com.duben.library.utils.json.JsonUtil
import com.duben.miniplaylet.R import com.duben.miniplaylet.R
import com.duben.miniplaylet.ad.AdManager import com.duben.miniplaylet.ad.AdManager
import com.duben.miniplaylet.ad.AdStatusListener import com.duben.miniplaylet.ad.AdStatusListener
...@@ -26,12 +29,17 @@ import com.duben.miniplaylet.utils.ConsumerToastUtil ...@@ -26,12 +29,17 @@ import com.duben.miniplaylet.utils.ConsumerToastUtil
import com.duben.miniplaylet.utils.SpanUtils import com.duben.miniplaylet.utils.SpanUtils
import com.duben.miniplaylet.utils.ToastUtil import com.duben.miniplaylet.utils.ToastUtil
import com.duben.library.utils.nodoubleclick.AntiShake import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.miniplaylet.login.LoginApi
import com.duben.miniplaylet.login.OnLoginListener
import com.duben.miniplaylet.manager.UserManager
import com.duben.miniplaylet.mvp.model.WXInfo
import kotlinx.android.synthetic.main.fragment_draw.* import kotlinx.android.synthetic.main.fragment_draw.*
/** /**
* 提现 * 提现
*/ */
class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.OnClickListener, class DrawCashFragment : LazyLoadBaseFragment(), OnLoginListener, DrawCashView,
DrawCashAdapter.OnClickListener,
View.OnClickListener { View.OnClickListener {
companion object { companion object {
...@@ -52,7 +60,9 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -52,7 +60,9 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
} }
private val drawCashPresenter by lazy { DrawCashPresenter() } private val drawCashPresenter by lazy { DrawCashPresenter() }
private val loginApi by lazy { LoginApi() }
private var wxInfo: WXInfo? = null
private var drawType = DRAW_TYPE_CASH private var drawType = DRAW_TYPE_CASH
private var mDrawCashAdapter: DrawCashAdapter? = null private var mDrawCashAdapter: DrawCashAdapter? = null
private var redPkgBean: DrawInfoBean? = null private var redPkgBean: DrawInfoBean? = null
...@@ -93,6 +103,7 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -93,6 +103,7 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
} }
override fun onFragmentResume() { override fun onFragmentResume() {
if (drawType == DRAW_TYPE_CASH) { if (drawType == DRAW_TYPE_CASH) {
// 红包 // 红包
drawCashPresenter.cashPageCoin() drawCashPresenter.cashPageCoin()
...@@ -191,7 +202,21 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -191,7 +202,21 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
1 -> { 1 -> {
//1、支付渠道 //1、支付渠道
if (TextUtils.equals(payChannel, WEIXIN_PAY)) { if (TextUtils.equals(payChannel, WEIXIN_PAY)) {
// showToast("微信支付维护中")
// 微信授权
// if (TextUtils.isEmpty(UserManager.getInstance().wxOpenid)) {
// val wechat = ShareSDK.getPlatform(Wechat.NAME)
// if (!wechat.isClientValid) {
// showToast("请先安装微信")
// return
// }
//
// showToast("微信拉起授权")
// loginApi.setOnLoginListener(this)
// loginApi.setPlatform(Wechat.NAME)
// loginApi.login(requireActivity())
// }
return return
} }
...@@ -222,7 +247,7 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -222,7 +247,7 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
showToast("发起提现成功") showToast("发起提现成功")
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
(requireActivity() as MainActivity).dismissDrawDialog() (requireActivity() as MainActivity).dismissDrawDialog()
}, 800) }, 800)
...@@ -319,21 +344,21 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -319,21 +344,21 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
Constant.CARRIERTYPE_ONLY_SHOW -> { Constant.CARRIERTYPE_ONLY_SHOW -> {
TrackManager.getInstance().addCashoutReq(currentDrawInfo?.unitId) TrackManager.getInstance().addCashoutReq(currentDrawInfo?.unitId)
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
showToast("发起提现成功") showToast("发起提现成功")
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
(requireActivity() as MainActivity).dismissDrawDialog() (requireActivity() as MainActivity).dismissDrawDialog()
}, 800) }, 800)
}, 1000) }, 1000)
} }
Constant.CARRIERTYPE_REWARD_COIN -> { Constant.CARRIERTYPE_REWARD_COIN -> {
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
ConsumerToastUtil.showAwardText(requireContext(), AppConfig.awardRedpkg, 0) ConsumerToastUtil.showAwardText(requireContext(), AppConfig.awardRedpkg, 0)
}, 800) }, 800)
...@@ -343,10 +368,10 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -343,10 +368,10 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
} }
Constant.CARRIERTYPE_REWARD_DI -> { Constant.CARRIERTYPE_REWARD_DI -> {
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if(!isAdded) return@postDelayed if (!isAdded) return@postDelayed
ConsumerToastUtil.showAwardText(requireContext(), 0, AppConfig.awardYuanbao) ConsumerToastUtil.showAwardText(requireContext(), 0, AppConfig.awardYuanbao)
}, 800) }, 800)
...@@ -355,4 +380,27 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O ...@@ -355,4 +380,27 @@ class DrawCashFragment : LazyLoadBaseFragment(), DrawCashView, DrawCashAdapter.O
} }
} }
} }
override fun onLogin(platform: String?, res: HashMap<String, Any>): Boolean {
try {
wxInfo = WXInfo()
wxInfo?.let {
it.unionid = res["unionid"].toString() + ""
it.openid = res["openid"].toString() + ""
it.province = res["province"].toString() + ""
it.city = res["city"].toString() + ""
it.country = res["country"].toString() + ""
it.headimgurl = res["headimgurl"].toString() + ""
it.nickname = res["nickname"].toString() + ""
it.sex = (res["sex"].toString() + "").toInt()
}
if (isAdded) {
drawCashPresenter.wxLogin(JsonUtil.toJson(wxInfo))
}
} catch (e: Exception) {
e.printStackTrace()
}
return false
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment