TibetanDetailsActivity.kt 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. package com.zswc.creativity.activity
  2. import android.os.Build.VERSION.SDK_INT
  3. import android.os.Bundle
  4. import android.os.Handler
  5. import android.os.Message
  6. import android.text.TextUtils
  7. import android.util.Log
  8. import android.view.View
  9. import androidx.lifecycle.lifecycleScope
  10. import coil.Coil
  11. import coil.ImageLoader
  12. import coil.decode.GifDecoder
  13. import coil.decode.ImageDecoderDecoder
  14. import coil.load
  15. import com.hwangjr.rxbus.annotation.Subscribe
  16. import com.hwangjr.rxbus.annotation.Tag
  17. import com.qmuiteam.qmui.kotlin.onClick
  18. import com.quansu.alipay.componnent.CpAlipay
  19. import com.zswc.creativity.R
  20. import com.zswc.creativity.base.MBActivity
  21. import com.zswc.creativity.config.ConfigRx
  22. import com.zswc.creativity.databinding.ActivityTibetanDetailsBinding
  23. import com.zswc.creativity.utils.WeChatUtil
  24. import com.zswc.creativity.utils.net.NetEngine
  25. import com.zswc.creativity.vmodel.TibetanDetailsVModel
  26. import kotlinx.coroutines.launch
  27. import java.text.DecimalFormat
  28. /**
  29. * 藏品详情
  30. *on 2022/7/23
  31. */
  32. class TibetanDetailsActivity : MBActivity<TibetanDetailsVModel, ActivityTibetanDetailsBinding>() {
  33. var sumSecond = 300//5分钟的总的秒数
  34. override fun init(savedInstanceState: Bundle?) {
  35. super.init(savedInstanceState)
  36. titleBar()?.imgRight?.setImageResource(R.drawable.ct_share)
  37. vm.ll = binding.ll
  38. var id = intent?.extras?.getString("id")
  39. vm.getInfo(id!!)
  40. vm.data.observe(this) {
  41. if (!TextUtils.isEmpty(it.detail_img)) {
  42. //获取文件后缀
  43. var ss = it.detail_img.substring(it.detail_img.length - 3, it.detail_img.length);
  44. if (ss == "gif" || ss == "GIF") {
  45. binding.imageView.visibility = View.GONE
  46. //设置图片加载gif
  47. val imageLoader=ImageLoader.Builder(context = this)
  48. .crossfade(true)
  49. .allowRgb565(true)
  50. .componentRegistry{
  51. if (SDK_INT>28){
  52. add(ImageDecoderDecoder())
  53. }else{
  54. add(GifDecoder())
  55. }
  56. }.build()
  57. Coil.setImageLoader(imageLoader)
  58. binding.imageGifView.load(it.detail_img)
  59. binding.imageGifView.visibility = View.VISIBLE
  60. } else {
  61. binding.imageView.visibility = View.VISIBLE
  62. binding.imageGifView.visibility = View.GONE
  63. }
  64. }
  65. }
  66. }
  67. override fun listeners() {
  68. super.listeners()
  69. binding.butBuy.onClick {
  70. vm.toBuy(binding.butBuy)
  71. }
  72. binding.imgShare.onClick {
  73. //分享
  74. vm.getUrl()
  75. }
  76. // screenHeightPixels = UiUtils.getScreenHeightPixels(getContext());
  77. //
  78. // obscroll.setOnScrollListener(object : OnScrollChangedListener() {
  79. // /**
  80. // * @param x
  81. // * @param y
  82. // * @param oldX
  83. // * @param oldY
  84. // */
  85. // fun onScrollChanged(x: Int, y: Int, oldX: Int, oldY: Int) {
  86. // if (islide) {
  87. // if (affix_type != null && affix_type.equals("3")) {
  88. // return
  89. // }
  90. // if (y == 0) {
  91. // tvTitleName.setVisibility(View.INVISIBLE)
  92. // lineL.setAlpha(0)
  93. // tvTitleName.setAlpha(1)
  94. // bar.setBackgroundColor(Color.parseColor("#00000000"))
  95. // } else if (y - oldY > 0) {
  96. // if (screenHeightPixels <= 960) {
  97. // setBarVisibility(y, 100)
  98. // } else {
  99. // setBarVisibility(y, 200)
  100. // }
  101. // } else if (y - oldY < 0) {
  102. // }
  103. // }
  104. // }
  105. // })
  106. }
  107. // private fun setBarVisibility(y: Int, height: Int) {
  108. // if (y > 0 && y < height) {
  109. // line.setVisibility(View.GONE)
  110. // bar.setVisibility(View.VISIBLE)
  111. // val df = DecimalFormat("0.00")
  112. // val s: String = df.format(y.toFloat() / height)
  113. // val a = s.toFloat() //0~1
  114. //
  115. // // float a = y / height;//0~1
  116. // val ratio = 255 - (255 * a).toInt() //255-(0~255)=255~0
  117. // val bgColor: Int = ColorUtils.getColorWithAlpha(Color.parseColor("#FFFFFF"), ratio)
  118. // bar.setBackgroundColor(bgColor)
  119. // tvTitleName.setAlpha(a)
  120. // line.setAlpha(a)
  121. // } else if (y > height) {
  122. // bar.setBackgroundColor(Color.WHITE)
  123. // bar.setVisibility(View.VISIBLE)
  124. // lineL.setVisibility(View.VISIBLE)
  125. // lineL.setAlpha(1)
  126. // tvTitleName.setAlpha(1)
  127. // tvTitleName.setVisibility(View.VISIBLE)
  128. // }
  129. // }
  130. override fun binding(): ActivityTibetanDetailsBinding {
  131. return ActivityTibetanDetailsBinding.inflate(layoutInflater)
  132. }
  133. override fun vmClass(): Class<TibetanDetailsVModel> {
  134. return TibetanDetailsVModel::class.java
  135. }
  136. override fun title(): String? {
  137. return null
  138. }
  139. override val isRxbus: Boolean
  140. get() = true
  141. //倒计时
  142. fun initOrderCancelTime(pay_time_long: String?) {
  143. //-------
  144. sumSecond = pay_time_long!!.toInt()
  145. vm.time.value = "请在 " + formatTime(sumSecond) + "内支付"
  146. addProgress()
  147. }
  148. private fun addProgress() {
  149. Log.e("-shy-", "isUp=" + vm.isUp)
  150. if (sumSecond == 0) {
  151. //结束 todo:
  152. // vm.isUp = false
  153. //
  154. // vm.bean.value?.state = 9
  155. //去取消订单
  156. // vm.toCancerOrderTo()
  157. } else {
  158. if (vm.isUp) {
  159. sumSecond--
  160. handler.sendEmptyMessageDelayed(0x101, 1000)
  161. }
  162. }
  163. }
  164. private val handler: Handler = object : Handler() {
  165. override fun handleMessage(msg: Message) {
  166. super.handleMessage(msg)
  167. //计算进度
  168. vm.time.value = "请在 " + formatTime(sumSecond) + "内支付"
  169. addProgress()
  170. }
  171. }
  172. /**
  173. * 将秒转化为 HH:mm:io.agora.rtc.ss 的格式
  174. *
  175. * @param time 秒
  176. * @return
  177. */
  178. /**
  179. * 将秒转化为 HH:mm:io.agora.rtc.ss 的格式
  180. *
  181. * @param time 秒
  182. * @return
  183. */
  184. var decimalFormat: DecimalFormat? = null
  185. private fun formatTime(time: Int): String? {
  186. if (decimalFormat == null) {
  187. decimalFormat = DecimalFormat("00")
  188. }
  189. val hh: String = decimalFormat!!.format(time / 3600)
  190. val mm: String = decimalFormat!!.format(time % 3600 / 60)
  191. val ss: String = decimalFormat!!.format(time % 60)
  192. // return "$hh:$mm:$io.agora.rtc.ss"
  193. return "$mm:$ss"
  194. }
  195. @Subscribe(tags = [Tag(ConfigRx.CHOSE_PAY_TYPE)])
  196. fun setChosePay(type: String) {
  197. lifecycleScope.launch {
  198. //todo:测试 0.01
  199. val it = vm.repository().lreq { NetEngine.service.amountAdd("0.01",type) }
  200. if (it.ok(false)) {
  201. if (type == "1") {//支付宝
  202. val orderInfo = it.data!!.alipay
  203. CpAlipay.pay(vm.repository().context!!, orderInfo)
  204. } else {//微信
  205. if (WeChatUtil.isWeixinAvilible(context())) {
  206. WeChatUtil.toWXPay(context(), it.data!!)
  207. }
  208. }
  209. }
  210. }
  211. if(type == "1"){//支付宝
  212. }else{//微信
  213. }
  214. }
  215. @Subscribe(tags = [Tag(ConfigRx.PAY_COMPLETE)])
  216. fun setPayComplete(money: String) {//充值了保证金后刷新
  217. //刷新 todo:
  218. toast("支付完成")
  219. }
  220. }