package com.kuanzhai.user.ui.menu
|
|
import android.view.inputmethod.EditorInfo
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.clickDelay
|
import cn.sinata.xldutils.utils.myToast
|
import cn.sinata.xldutils.view.SwipeRefreshRecyclerLayout
|
import com.kuanzhai.user.R
|
import com.kuanzhai.user.network.HttpManager
|
import com.kuanzhai.user.network.entity.RentBean
|
import com.kuanzhai.user.network.entity.SaleBean
|
import com.kuanzhai.user.network.entity.WantedBean
|
import com.kuanzhai.user.network.request
|
import com.kuanzhai.user.ui.TransparentStatusBarActivity
|
import com.kuanzhai.user.ui.menu.adapter.RentAdapter
|
import com.kuanzhai.user.ui.menu.adapter.SaleAdapter
|
import com.kuanzhai.user.ui.menu.adapter.WantedAdapter
|
import kotlinx.android.synthetic.main.activity_seach_car.*
|
import org.jetbrains.anko.startActivity
|
|
class SearchCarActivity:TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_seach_car
|
|
private val type by lazy { intent.getIntExtra("type", TYPE_SALE) }
|
private val list = arrayListOf<SaleBean>()
|
private val rentList = arrayListOf<RentBean>()
|
private val jobList = arrayListOf<WantedBean>()
|
private val adapter by lazy {
|
when(type){
|
TYPE_RENT-> RentAdapter(rentList)
|
TYPE_SALE-> SaleAdapter(list)
|
else-> WantedAdapter(jobList)
|
}
|
}
|
private var page = 1
|
|
private var key = ""
|
|
override fun initClick() {
|
tv_cancel.clickDelay { finish() }
|
adapter.setOnItemClickListener { view, position ->
|
when(type){
|
TYPE_RENT-> startActivity<RentCarDetailActivity>("id" to list[position].id)
|
TYPE_SALE-> startActivity<CarDetailActivity>("id" to list[position].id)
|
TYPE_JOB-> startActivity<JobDetailActivity>("id" to list[position].id)
|
}
|
}
|
}
|
|
override fun initView() {
|
title = "搜索"
|
if (type == TYPE_JOB)
|
et_search.hint = "搜索招聘信息"
|
swipeRefreshLayout.setLayoutManager(LinearLayoutManager(this))
|
swipeRefreshLayout.setAdapter(adapter)
|
swipeRefreshLayout.setMode(SwipeRefreshRecyclerLayout.Mode.None)
|
// swipeRefreshLayout.setOnRefreshListener(object : SwipeRefreshRecyclerLayout.OnRefreshListener{
|
// override fun onRefresh() {
|
// }
|
//
|
// override fun onLoadMore() {
|
// page++
|
// getData()
|
// }
|
// })
|
swipeRefreshLayout.setLoadMoreText("")
|
|
et_search.setOnEditorActionListener { v, actionId, event ->
|
if (actionId == EditorInfo.IME_ACTION_SEARCH){
|
key = et_search.text.toString()
|
if (key.isEmpty()){
|
myToast("请输入搜索内容")
|
return@setOnEditorActionListener true
|
} else{
|
hideInputMethod()
|
swipeRefreshLayout.isRefreshing = true
|
page = 1
|
getData()
|
}
|
}
|
return@setOnEditorActionListener false
|
}
|
}
|
|
private fun getData(){
|
if (key.isNotEmpty())
|
when(type){
|
TYPE_RENT->
|
HttpManager.getCarRentalList(null,key,null,null,null,
|
null,null,null,page,1000).request(this,success = {_,data->
|
swipeRefreshLayout.isRefreshing = false
|
if (page == 1)
|
rentList.clear()
|
rentList.addAll(data?: emptyList())
|
adapter.notifyDataSetChanged()
|
}){_,_->
|
swipeRefreshLayout.isRefreshing = false
|
}
|
TYPE_SALE->
|
HttpManager.getSellingCarList(null,key,null,null,null,
|
null,null,null,null,null,null,null,
|
null,null,page,1000).request(this,success = {_,data->
|
swipeRefreshLayout.isRefreshing = false
|
if (page == 1)
|
list.clear()
|
list.addAll(data?: emptyList())
|
adapter.notifyDataSetChanged()
|
}){_,_->
|
swipeRefreshLayout.isRefreshing = false
|
}
|
else->
|
HttpManager.getRecruitList(null,key,null,null,null,page,
|
1000).request(this,success = {_,data->
|
swipeRefreshLayout.isRefreshing = false
|
if (page == 1)
|
jobList.clear()
|
jobList.addAll(data?: emptyList())
|
adapter.notifyDataSetChanged()
|
}){_,_->
|
swipeRefreshLayout.isRefreshing = false
|
}
|
}
|
}
|
|
companion object{
|
const val TYPE_RENT = 1
|
const val TYPE_SALE = 2
|
const val TYPE_JOB = 3
|
}
|
}
|