| | |
| | | package com.sinata.xqmuse.ui.home |
| | | |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.network.HttpManager |
| | | import com.sinata.xqmuse.network.request |
| | | import com.sinata.xqmuse.ui.TransparentStatusBarActivity |
| | | import com.sinata.xqmuse.ui.course.CourseSearchResultActivity |
| | | import com.sinata.xqmuse.ui.home.adapter.HotAdapter |
| | | import com.sinata.xqmuse.utils.Const |
| | | import kotlinx.android.synthetic.main.activity_search.* |
| | |
| | | private val hisList = arrayListOf<String>() |
| | | private val hotList = arrayListOf<String>() |
| | | private val hotAdapter = HotAdapter(hotList) |
| | | |
| | | private val isCourse by lazy { intent.getBooleanExtra("isCourse",false) } //true:搜索课程 |
| | | private val hisKey by lazy { if (isCourse) Const.User.SEARCH_HIS_COURSE else Const.User.SEARCH_HIS_HOME } |
| | | |
| | | override fun initClick() { |
| | | hotAdapter.setOnItemClickListener { view, position -> |
| | | et_search.setText(hotList[position]) |
| | | et_search.setSelection(hotList[position].length) |
| | | tv_search.callOnClick() |
| | | } |
| | | |
| | |
| | | hisList.remove(key) |
| | | hisList.add(0,key) |
| | | saveHis() |
| | | startActivity<SearchResultActivity>("key" to key) |
| | | if (isCourse) |
| | | startActivity<CourseSearchResultActivity>("key" to key) |
| | | else |
| | | startActivity<SearchResultActivity>("key" to key) |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun initView() { |
| | | rv_hot.layoutManager = LinearLayoutManager(this) |
| | | rv_hot.adapter = hotAdapter |
| | | if (isCourse){ |
| | | rv_hot.gone() |
| | | tv_2.gone() |
| | | et_search.hint = "搜索你喜欢的课程~" |
| | | }else{ |
| | | rv_hot.layoutManager = LinearLayoutManager(this) |
| | | rv_hot.adapter = hotAdapter |
| | | getHotWordList() |
| | | } |
| | | getHis() |
| | | getHotWordList() |
| | | } |
| | | |
| | | private fun getHotWordList(){ |
| | |
| | | private fun getHis(){ |
| | | hisList.clear() |
| | | fl_his.removeAllViews() |
| | | val his = SPUtils.instance().getString(Const.User.SEARCH_HIS) |
| | | val his = SPUtils.instance().getString(hisKey) |
| | | hisList.addAll(his.split(SPLIT).filter { it.isNotEmpty() }.take(10)) |
| | | hisList.forEach { |
| | | val inflate = layoutInflater.inflate(R.layout.item_search_his, fl_his, false) |
| | |
| | | inflate.tv_name.text = it |
| | | inflate.tv_name.setOnClickListener { _-> |
| | | et_search.setText(it) |
| | | et_search.setSelection(it.length) |
| | | tv_search.callOnClick() |
| | | } |
| | | inflate.iv_del.setOnClickListener { _-> |
| | |
| | | } |
| | | |
| | | private fun saveHis() { |
| | | SPUtils.instance().put(Const.User.SEARCH_HIS,hisList.joinToString(SPLIT) { it }).apply() |
| | | SPUtils.instance().put(hisKey,hisList.joinToString(SPLIT) { it }).apply() |
| | | getHis() |
| | | } |
| | | } |