123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- package com.zswc.creativity.activity
- import android.os.Build.VERSION.SDK_INT
- import android.os.Bundle
- import android.os.Handler
- import android.os.Message
- import android.text.TextUtils
- import android.util.Log
- import android.view.View
- import androidx.lifecycle.lifecycleScope
- import coil.Coil
- import coil.ImageLoader
- import coil.decode.GifDecoder
- import coil.decode.ImageDecoderDecoder
- import coil.load
- import com.hwangjr.rxbus.annotation.Subscribe
- import com.hwangjr.rxbus.annotation.Tag
- import com.qmuiteam.qmui.kotlin.onClick
- import com.quansu.alipay.componnent.CpAlipay
- import com.zswc.creativity.R
- import com.zswc.creativity.base.MBActivity
- import com.zswc.creativity.config.ConfigRx
- import com.zswc.creativity.databinding.ActivityTibetanDetailsBinding
- import com.zswc.creativity.utils.WeChatUtil
- import com.zswc.creativity.utils.net.NetEngine
- import com.zswc.creativity.vmodel.TibetanDetailsVModel
- import kotlinx.coroutines.launch
- import java.text.DecimalFormat
- /**
- * 藏品详情
- *on 2022/7/23
- */
- class TibetanDetailsActivity : MBActivity<TibetanDetailsVModel, ActivityTibetanDetailsBinding>() {
- var sumSecond = 300//5分钟的总的秒数
- override fun init(savedInstanceState: Bundle?) {
- super.init(savedInstanceState)
- titleBar()?.imgRight?.setImageResource(R.drawable.ct_share)
- vm.ll = binding.ll
- var id = intent?.extras?.getString("id")
- vm.getInfo(id!!)
- vm.data.observe(this) {
- if (!TextUtils.isEmpty(it.detail_img)) {
- //获取文件后缀
- var ss = it.detail_img.substring(it.detail_img.length - 3, it.detail_img.length);
- if (ss == "gif" || ss == "GIF") {
- binding.imageView.visibility = View.GONE
- //设置图片加载gif
- val imageLoader=ImageLoader.Builder(context = this)
- .crossfade(true)
- .allowRgb565(true)
- .componentRegistry{
- if (SDK_INT>28){
- add(ImageDecoderDecoder())
- }else{
- add(GifDecoder())
- }
- }.build()
- Coil.setImageLoader(imageLoader)
- binding.imageGifView.load(it.detail_img)
- binding.imageGifView.visibility = View.VISIBLE
- } else {
- binding.imageView.visibility = View.VISIBLE
- binding.imageGifView.visibility = View.GONE
- }
- }
- }
- }
- override fun listeners() {
- super.listeners()
- binding.butBuy.onClick {
- vm.toBuy(binding.butBuy)
- }
- binding.imgShare.onClick {
- //分享
- vm.getUrl()
- }
- // screenHeightPixels = UiUtils.getScreenHeightPixels(getContext());
- //
- // obscroll.setOnScrollListener(object : OnScrollChangedListener() {
- // /**
- // * @param x
- // * @param y
- // * @param oldX
- // * @param oldY
- // */
- // fun onScrollChanged(x: Int, y: Int, oldX: Int, oldY: Int) {
- // if (islide) {
- // if (affix_type != null && affix_type.equals("3")) {
- // return
- // }
- // if (y == 0) {
- // tvTitleName.setVisibility(View.INVISIBLE)
- // lineL.setAlpha(0)
- // tvTitleName.setAlpha(1)
- // bar.setBackgroundColor(Color.parseColor("#00000000"))
- // } else if (y - oldY > 0) {
- // if (screenHeightPixels <= 960) {
- // setBarVisibility(y, 100)
- // } else {
- // setBarVisibility(y, 200)
- // }
- // } else if (y - oldY < 0) {
- // }
- // }
- // }
- // })
- }
- // private fun setBarVisibility(y: Int, height: Int) {
- // if (y > 0 && y < height) {
- // line.setVisibility(View.GONE)
- // bar.setVisibility(View.VISIBLE)
- // val df = DecimalFormat("0.00")
- // val s: String = df.format(y.toFloat() / height)
- // val a = s.toFloat() //0~1
- //
- // // float a = y / height;//0~1
- // val ratio = 255 - (255 * a).toInt() //255-(0~255)=255~0
- // val bgColor: Int = ColorUtils.getColorWithAlpha(Color.parseColor("#FFFFFF"), ratio)
- // bar.setBackgroundColor(bgColor)
- // tvTitleName.setAlpha(a)
- // line.setAlpha(a)
- // } else if (y > height) {
- // bar.setBackgroundColor(Color.WHITE)
- // bar.setVisibility(View.VISIBLE)
- // lineL.setVisibility(View.VISIBLE)
- // lineL.setAlpha(1)
- // tvTitleName.setAlpha(1)
- // tvTitleName.setVisibility(View.VISIBLE)
- // }
- // }
- override fun binding(): ActivityTibetanDetailsBinding {
- return ActivityTibetanDetailsBinding.inflate(layoutInflater)
- }
- override fun vmClass(): Class<TibetanDetailsVModel> {
- return TibetanDetailsVModel::class.java
- }
- override fun title(): String? {
- return null
- }
- override val isRxbus: Boolean
- get() = true
- //倒计时
- fun initOrderCancelTime(pay_time_long: String?) {
- //-------
- sumSecond = pay_time_long!!.toInt()
- vm.time.value = "请在 " + formatTime(sumSecond) + "内支付"
- addProgress()
- }
- private fun addProgress() {
- Log.e("-shy-", "isUp=" + vm.isUp)
- if (sumSecond == 0) {
- //结束 todo:
- // vm.isUp = false
- //
- // vm.bean.value?.state = 9
- //去取消订单
- // vm.toCancerOrderTo()
- } else {
- if (vm.isUp) {
- sumSecond--
- handler.sendEmptyMessageDelayed(0x101, 1000)
- }
- }
- }
- private val handler: Handler = object : Handler() {
- override fun handleMessage(msg: Message) {
- super.handleMessage(msg)
- //计算进度
- vm.time.value = "请在 " + formatTime(sumSecond) + "内支付"
- addProgress()
- }
- }
- /**
- * 将秒转化为 HH:mm:io.agora.rtc.ss 的格式
- *
- * @param time 秒
- * @return
- */
- /**
- * 将秒转化为 HH:mm:io.agora.rtc.ss 的格式
- *
- * @param time 秒
- * @return
- */
- var decimalFormat: DecimalFormat? = null
- private fun formatTime(time: Int): String? {
- if (decimalFormat == null) {
- decimalFormat = DecimalFormat("00")
- }
- val hh: String = decimalFormat!!.format(time / 3600)
- val mm: String = decimalFormat!!.format(time % 3600 / 60)
- val ss: String = decimalFormat!!.format(time % 60)
- // return "$hh:$mm:$io.agora.rtc.ss"
- return "$mm:$ss"
- }
- @Subscribe(tags = [Tag(ConfigRx.CHOSE_PAY_TYPE)])
- fun setChosePay(type: String) {
- lifecycleScope.launch {
- //todo:测试 0.01
- val it = vm.repository().lreq { NetEngine.service.amountAdd("0.01",type) }
- if (it.ok(false)) {
- if (type == "1") {//支付宝
- val orderInfo = it.data!!.alipay
- CpAlipay.pay(vm.repository().context!!, orderInfo)
- } else {//微信
- if (WeChatUtil.isWeixinAvilible(context())) {
- WeChatUtil.toWXPay(context(), it.data!!)
- }
- }
- }
- }
- if(type == "1"){//支付宝
- }else{//微信
- }
- }
- @Subscribe(tags = [Tag(ConfigRx.PAY_COMPLETE)])
- fun setPayComplete(money: String) {//充值了保证金后刷新
- //刷新 todo:
- toast("支付完成")
- }
- }
|