package cn.flightfeather.thirdappmodule.module.common
|
|
import android.arch.lifecycle.ViewModelProviders
|
import android.content.Intent
|
import android.os.Bundle
|
import android.text.Editable
|
import android.text.TextWatcher
|
import android.view.View
|
import android.view.inputmethod.EditorInfo
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
|
import cn.flightfeather.thirdappmodule.module.base.BaseActivity
|
import cn.flightfeather.thirdappmodule.module.inspection.InspectionDetailActivity
|
import cn.flightfeather.thirdappmodule.util.Constant
|
import cn.flightfeather.thirdappmodule.util.DateUtil
|
import cn.flightfeather.thirdappmodule.util.Domain
|
import cn.flightfeather.thirdappmodule.view.recyclerview.BaseCustomViewHolder
|
import cn.flightfeather.thirdappmodule.view.recyclerview.MySection
|
import cn.flightfeather.thirdappmodule.view.recyclerview.RecyclerViewPanel
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
import com.chad.library.adapter.base.BaseViewHolder
|
import kotlinx.android.synthetic.main.activity_search.*
|
import kotlinx.android.synthetic.main.layout_search_title.*
|
|
/**
|
* @author riku
|
* Date: 2022/2/17
|
*/
|
class SearchActivity : BaseActivity() {
|
|
private lateinit var searViewModel: SearchViewModel
|
private lateinit var recyclerViewPanel: RecyclerViewPanel<Subtask>
|
|
override fun getLayoutId(): Int = R.layout.activity_search
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
searViewModel = ViewModelProviders.of(this).get(SearchViewModel::class.java)
|
|
initClickListener()
|
initRecyclerView()
|
}
|
|
private fun initClickListener() {
|
// 回退键
|
img_cancel.setOnClickListener { onBackPressed() }
|
// 搜索清空文本按钮
|
btn_clear.visibility = View.GONE
|
btn_clear.setOnClickListener { edt_search.setText("") }
|
// 搜索框
|
autoShowKeyboard(edt_search)
|
edt_search.apply {
|
// “搜索”按钮监听事件
|
setOnEditorActionListener { v, actionId, _ ->
|
if (actionId == EditorInfo.IME_ACTION_SEARCH && !v.text.isNullOrBlank()) {
|
searViewModel.keyword = v.text.toString()
|
recyclerViewPanel.startRefresh()
|
hideKeyboard()
|
}
|
true
|
}
|
// 清空文字按钮的显示逻辑
|
addTextChangedListener(object : TextWatcher {
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
|
override fun afterTextChanged(s: Editable?) {
|
btn_clear.visibility=if (s.isNullOrBlank()) View.GONE else View.VISIBLE
|
}
|
})
|
}
|
|
}
|
|
private fun initRecyclerView() {
|
recyclerViewPanel = object : RecyclerViewPanel<Subtask>(searViewModel.subtaskResult, recycler_view, this) {
|
override fun getItemLayoutId(): Int? = R.layout.item_task_list_2
|
|
override fun onBindView(holder: BaseCustomViewHolder, item: MySection<Subtask>?) {
|
item?.t?.let {s ->
|
val planStartTime = DateUtil.getYearMonthDayStr(s.planstarttime, true)
|
|
val names = s.executorrealtimes?.replace(Constant.CONNECTOR.toRegex(), Constant.CONNECTOR_FOR_VIEW)
|
holder.setText(R.id.tv_item_task_list_name, s.name)
|
.setText(R.id.tv_item_task_list_address, s.scenseaddress)
|
.setText(R.id.tv_item_task_list_time, planStartTime)
|
.setText(R.id.tv_task_staff, names)
|
when (s.status) {
|
Domain.TASK_STATUS_RUNNING -> holder.setImageResource(R.id.img_task_status, R.mipmap.ic_task_executing)
|
Domain.TASK_STATUS_FINISHED -> holder.setImageResource(R.id.img_task_status, R.mipmap.ic_task_complete)
|
else -> holder.setImageResource(R.id.img_task_status, R.mipmap.ic_task_ready_to_start)
|
}
|
}
|
}
|
|
override fun onItemClick(adapter: BaseQuickAdapter<Any?, BaseViewHolder>, view: View, position: Int, dataList: List<Subtask>) {
|
super.onItemClick(adapter, view, position, dataList)
|
val intent = Intent(this@SearchActivity, InspectionDetailActivity::class.java)
|
intent.putExtra("subTask", dataList[position])
|
startActivity(intent)
|
}
|
}.also {
|
it.init()
|
it.startRefresh()
|
}
|
}
|
}
|