|
@@ -1,151 +0,0 @@
|
|
|
-package com.hdl.xl.ui.activitys
|
|
|
-
|
|
|
-import android.annotation.SuppressLint
|
|
|
-import android.os.Bundle
|
|
|
-import android.os.Handler
|
|
|
-import android.os.Message
|
|
|
-import android.util.Log
|
|
|
-import android.view.View
|
|
|
-import androidx.databinding.DataBindingUtil
|
|
|
-import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
-import com.laike.basekt.BaseActivity
|
|
|
-import com.laike.basekt.coremodel.datemodel.client.HttpRetrofitRequest
|
|
|
-import com.laike.basekt.coremodel.datemodel.client.RxSchedulers
|
|
|
-import com.laike.basekt.extension.startKtActivityOrForResult
|
|
|
-import com.laike.basekt.utils.StatusBarCommon
|
|
|
-import com.hdl.xl.R
|
|
|
-import com.hdl.xl.bean.CommodityBean
|
|
|
-import com.hdl.xl.databinding.ActivityLimitedTimePurchaseBinding
|
|
|
-import com.hdl.xl.service.HttpApi_xie
|
|
|
-import com.hdl.xl.ui.adapter.LimitedTimeAdapter
|
|
|
-import com.scwang.smartrefresh.layout.SmartRefreshLayout
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description:限时购
|
|
|
- * @Author: wuxing
|
|
|
- * @Date: 2021/1/26 16:42
|
|
|
- */
|
|
|
-class ActivityLimitedTimePurchase : BaseActivity(), View.OnClickListener {
|
|
|
- var mBinding: ActivityLimitedTimePurchaseBinding? = null
|
|
|
- var commodityBean: MutableList<CommodityBean> = arrayListOf()
|
|
|
- var mAdapter = LimitedTimeAdapter()
|
|
|
- var curPage=0
|
|
|
- var leftTime=0L
|
|
|
- var handler = Handler()
|
|
|
- override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
- super.onCreate(savedInstanceState)
|
|
|
- leftTime=intent.getLongExtra("limit_time",0L)
|
|
|
- mBinding =
|
|
|
- DataBindingUtil.setContentView(mActivity, R.layout.activity_limited_time_purchase)
|
|
|
- mBinding?.run {
|
|
|
- clickListener = this@ActivityLimitedTimePurchase
|
|
|
- layoutTitle.setPadding(0, StatusBarCommon.findStatusBarHeight(mActivity), 0, 0)
|
|
|
-
|
|
|
- handler.postDelayed(update_thread, 1000)
|
|
|
-
|
|
|
- recycleView.layoutManager = LinearLayoutManager(mActivity)
|
|
|
- recycleView.adapter = mAdapter
|
|
|
-
|
|
|
- smartRefreshLayout.setOnRefreshListener {
|
|
|
- curPage=0
|
|
|
- mAdapter.getData().clear()
|
|
|
- mAdapter.notifyDataSetChanged()
|
|
|
- searchLimitBuy(smartRefreshLayout)
|
|
|
- }
|
|
|
- smartRefreshLayout.setOnLoadMoreListener {
|
|
|
- searchLimitBuy(smartRefreshLayout)
|
|
|
- }
|
|
|
- smartRefreshLayout.autoRefresh()
|
|
|
-
|
|
|
- mAdapter.addOnItemClickListener { view, entity, position ->
|
|
|
- var bundle = Bundle()
|
|
|
- bundle.putInt("type", 1)
|
|
|
- startKtActivityOrForResult<ActivityDetailsFirst>(bundle = bundle)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var update_thread: Runnable = object : Runnable {
|
|
|
- override fun run() {
|
|
|
- leftTime--
|
|
|
- Log.e("", "leftTime=$leftTime")
|
|
|
- if (leftTime > 0) {
|
|
|
- //倒计时效果展示
|
|
|
- val formatLongToTimeStr = formatLongToTimeStr(leftTime)
|
|
|
- mBinding?.limitedTime?.text = formatLongToTimeStr
|
|
|
- //每一秒执行一次
|
|
|
- handler.postDelayed(this, 1000)
|
|
|
- } else { //倒计时结束
|
|
|
- //处理业务流程
|
|
|
-
|
|
|
- //发送消息,结束倒计时
|
|
|
- val message = Message()
|
|
|
- message.what = 1
|
|
|
- handlerStop.sendMessage(message)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- val handlerStop: Handler = object : Handler() {
|
|
|
- override fun handleMessage(msg: Message) {
|
|
|
- when (msg.what) {
|
|
|
- 1 -> {
|
|
|
- leftTime = 0
|
|
|
- handler.removeCallbacks(update_thread)
|
|
|
- }
|
|
|
- }
|
|
|
- super.handleMessage(msg)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun formatLongToTimeStr(l: Long): String {
|
|
|
- var hour = 0
|
|
|
- var minute = 0
|
|
|
- var second = 0
|
|
|
- second = l.toInt()
|
|
|
- if (second > 60) {
|
|
|
- minute = second / 60 //取整
|
|
|
- second %= 60 //取余
|
|
|
- }
|
|
|
- if (minute > 60) {
|
|
|
- hour = minute / 60
|
|
|
- minute %= 60
|
|
|
- }
|
|
|
- return ""+hour + "时" + minute + "分" + second + "秒"
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDestroy() {
|
|
|
- super.onDestroy()
|
|
|
- leftTime = 0
|
|
|
- handler.removeCallbacks(update_thread)
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint("CheckResult")
|
|
|
- fun searchLimitBuy(smartRefreshLayout: SmartRefreshLayout) {
|
|
|
- curPage++
|
|
|
- HttpRetrofitRequest.retrofit(HttpApi_xie::class.java)
|
|
|
- .searchMiaoSha(curPage,10)
|
|
|
- .compose(RxSchedulers.applySchedulers())
|
|
|
- .subscribe({
|
|
|
- smartRefreshLayout.finishRefresh()
|
|
|
- smartRefreshLayout.finishLoadMore()
|
|
|
- if (it.code==200){
|
|
|
- it.data?.let { it1 -> mAdapter.addDataAll(it1) }
|
|
|
- mAdapter.notifyDataSetChanged()
|
|
|
- }
|
|
|
- },{
|
|
|
- smartRefreshLayout.finishRefresh()
|
|
|
- smartRefreshLayout.finishLoadMore()
|
|
|
- Log.e("searchLimitBuy",it.message.toString())
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- override fun onClick(v: View?) {
|
|
|
- when (v?.id) {
|
|
|
- R.id.go_back -> {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|