package com.sixin.module_p.ui.goods.transport.list

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
import android.widget.Toast
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.ktx.getLifecycleOwner
import com.lukouguoji.module_base.ktx.logw
import com.sixin.module_p.R
import com.sixin.module_p.base.BasePdaActivity
import com.sixin.module_p.databinding.ActivityPdaGoodsTransportListBinding


class PdaGoodsTransportListActivity :
    BasePdaActivity<ActivityPdaGoodsTransportListBinding, PdaGoodsTransportListViewModel>() {
    override fun layoutId(): Int {
        return R.layout.activity_pda_goods_transport_list
    }

    override fun viewModelClass(): Class<PdaGoodsTransportListViewModel> {
        return PdaGoodsTransportListViewModel::class.java
    }

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("货物转运")
        binding.viewModel = viewModel
        binding.etCarNo.setOnFocusChangeListener { v, hasFocus ->
            if(!hasFocus){
                val carNo = binding.etCarNo.text.toString()
                Log.i("TEST","initOnCreate  setOnFocusChangeListener  $carNo")
                viewModel.findMatchInputCarNo(carNo)
            }
        }
        binding.etCarNo.imeOptions = EditorInfo.IME_ACTION_DONE
        binding.etCarNo.setOnKeyListener { v, keyCode, event ->
            if (event.action === KeyEvent.ACTION_DOWN && keyCode === KeyEvent.KEYCODE_ENTER) {
                viewModel.refresh()
                return@setOnKeyListener true
            }
            return@setOnKeyListener false
        }
        viewModel.pageModel.bindSmartRefreshLayout(
            binding.srl,
            binding.rv,
            viewModel,
            getLifecycleOwner()
        )
        binding.rv.addOnItemClickListener(viewModel)
        viewModel.initOnCreated()
        viewModel.refresh()
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, PdaGoodsTransportListActivity::class.java)
            context.startActivity(starter)
        }
    }

}