Commit 903c3a2e by fengquan

feat: 测评搜索

parent b6d32c3b
......@@ -18,6 +18,9 @@
android:screenOrientation="portrait"
android:theme="@style/tests_NoTitleTheme"
/>
<activity android:name=".search.TestSearchKeyActivity"
android:screenOrientation="portrait"
android:theme="@style/tests_NoTitleTheme"/>
<!--测评首页-->
<activity
android:name=".home.NewTestHomeActivity"
......
......@@ -14,4 +14,6 @@ class TestListCommand : BaseCommand() {
var tab: String? = null
@JvmField
var keyword: String? = null
@JvmField
var type: Int = 0
}
\ No newline at end of file
......@@ -33,8 +33,9 @@ import de.greenrobot.event.EventBus
import kotlinx.android.synthetic.main.tests_activity_test_search.*
import kotlinx.android.synthetic.main.tests_item_hot_search.view.*
@Route(path ="/tests/search")
class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(), TestSearchView, View.OnClickListener {
@Route(path = "/tests/search")
class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(), TestSearchView,
View.OnClickListener {
private var isFirstLoad = true
override fun getStatusViewOptions(): StatusBarOptions {
......@@ -76,7 +77,8 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
}
fun initData() {
var lastCouponMoney = SharedPreferencesEditor.getString(TestHomeUtils.TEST_MAX_COUPON_MONEY_SP_KEY)
var lastCouponMoney =
SharedPreferencesEditor.getString(TestHomeUtils.TEST_MAX_COUPON_MONEY_SP_KEY)
if (!TextUtils.isEmpty(lastCouponMoney)) {
searchAdapter?.couponMoney = lastCouponMoney
hotSearchAdapter?.couponMoney = lastCouponMoney
......@@ -95,8 +97,16 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
private fun initRecyclerView() {
swipe_refresh_layout.isEnabled = false
searchAdapter = TestListRecyclerAdapter(this, searchedTestList, TestListRecyclerAdapter.PAGE_TYPE_SEARCH)
hotSearchAdapter = TestListRecyclerAdapter(this, hotSearchedTestList, TestListRecyclerAdapter.PAGE_TYPE_SEARCH)
searchAdapter = TestListRecyclerAdapter(
this,
searchedTestList,
TestListRecyclerAdapter.PAGE_TYPE_SEARCH
)
hotSearchAdapter = TestListRecyclerAdapter(
this,
hotSearchedTestList,
TestListRecyclerAdapter.PAGE_TYPE_SEARCH
)
searchAdapter?.onItemClickListener = MyBaseAdapter.OnItemClickListener { _, _, data ->
TestsIn.getTestsImpl().testDetailH5(data.id.toString())
......@@ -106,7 +116,8 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
TestsIn.getTestsImpl().testDetailH5(data.id.toString())
}
headerHotSearch = View.inflate(this, R.layout.tests_header_hot_search, null) as LinearLayout?;
headerHotSearch =
View.inflate(this, R.layout.tests_header_hot_search, null) as LinearLayout?;
searchHeader = View.inflate(this, R.layout.tests_header_search_list, null);
tvSearchHint = searchHeader?.findViewById(R.id.tv_search_hint);
......@@ -135,13 +146,13 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
onScrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
override fun onLoadMore(page: Int, totalItemsCount: Int, view: RecyclerView?) {
if (isSearch) {
mPresenter.searchTests(keyword, searchListCurrentPage)
mPresenter.searchTests(keyword, searchListCurrentPage, 0)
}
}
}
rv_hot_list.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!isFirstLoad && dx!=0 && dx!=0) {
if (!isFirstLoad && dx != 0 && dx != 0) {
hideSoftInput()
}
}
......@@ -168,7 +179,14 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
})
etSearch.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
doSearch()
keyword = etSearch.text.toString()
if (TextUtils.isEmpty(keyword)) {
ToastUtil.toastShort(getString(R.string.tests_no_search_keyword_hint))
} else {
val intent = Intent(this, TestSearchKeyActivity::class.java)
intent.putExtra("keyword", keyword)
startActivity(intent)
}
}
true
}
......@@ -193,7 +211,7 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
isSearch = true
searchListCurrentPage = 1
onScrollListener.resetState()
mPresenter.searchTests(keyword, searchListCurrentPage)
mPresenter.searchTests(keyword, searchListCurrentPage, 0)
}
fun hideSoftInput() {
......@@ -241,11 +259,13 @@ class TestSearchActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(
headerHotSearch?.visibility = View.VISIBLE
flHotSearch?.removeAllViews()
for (index in keywordData.indices) {
val view = LayoutInflater.from(this).inflate(R.layout.tests_item_recommend_hot_search, flHotSearch, false)
val view = LayoutInflater.from(this)
.inflate(R.layout.tests_item_recommend_hot_search, flHotSearch, false)
view.tvHotSearch.text = keywordData[index].keyWord
view.setOnClickListener {
etSearch.setText(keywordData[index].keyWord)
doSearch()
val intent = Intent(this, TestSearchKeyActivity::class.java)
intent.putExtra("keyword", keywordData[index].keyWord)
startActivity(intent)
}
flHotSearch?.addView(view)
......
package com.yidianling.tests.search
import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.tabs.TabLayout
import com.ydl.ydlcommon.adapter.MyBaseAdapter
import com.ydl.ydlcommon.base.BaseMvpActivity
import com.ydl.ydlcommon.bean.StatusBarOptions
import com.ydl.ydlcommon.utils.SharedPreferencesEditor
import com.ydl.ydlcommon.view.listener.EndlessRecyclerViewScrollListener
import com.yidianling.common.tools.ToastUtil
import com.yidianling.tests.R
import com.yidianling.tests.home.event.UpdateCouponMoneyEvent
import com.yidianling.tests.home.utils.TestHomeUtils
import com.yidianling.tests.list.model.bean.RecommendSearchItemBean
import com.yidianling.tests.list.model.bean.Test
import com.yidianling.tests.list.view.adapter.TestListRecyclerAdapter
import com.yidianling.tests.router.TestsIn
import de.greenrobot.event.EventBus
import kotlinx.android.synthetic.main.tests_activity_test_key_search.*
class TestSearchKeyActivity : BaseMvpActivity<TestSearchView, TestSearchPresenter>(),
TestSearchView, View.OnClickListener {
private var keyWord: String? = ""
private var searchListCurrentAllPage = 1
private var searchListCurrentPastPage = 1
private var searchListCurrentFreePage = 1
private val TYPE_ALL = "all"
private val TYPE_PAST = "past"
private val TYPE_FREE = "free"
private lateinit var onScrollListener: EndlessRecyclerViewScrollListener
private var currentSelectedPage = TYPE_ALL
var title = arrayOf("全部", "付费", "免费")
private var searchAdapter: TestListRecyclerAdapter? = null
private val searchedTestList: MutableList<Test> = ArrayList()
override fun createPresenter(): TestSearchPresenter = TestSearchPresenter()
override fun layoutResId(): Int {
return R.layout.tests_activity_test_key_search
}
override fun getStatusViewOptions(): StatusBarOptions {
return StatusBarOptions(true, statusBarDarkMode = true)
}
override fun initDataAndEvent() {
EventBus.getDefault().register(this)
this.keyWord = intent.getStringExtra("keyword")
setupListeners()
initView()
initRecyclerView()
tv_search_key_empty?.text = String.format("为您找到以下跟“%s”有关的内容", keyWord)
etKeySearch?.setText(keyWord)
initData()
}
private fun initData() {
var lastCouponMoney =
SharedPreferencesEditor.getString(TestHomeUtils.TEST_MAX_COUPON_MONEY_SP_KEY)
if (!TextUtils.isEmpty(lastCouponMoney)) {
searchAdapter?.couponMoney = lastCouponMoney
}
}
private fun initView() {
for (i in title) {
val tab = tabLayout.newTab().setText(i);
tabLayout.addTab(tab)
}
}
private fun initRecyclerView() {
swipe_refresh_layout_key.isEnabled = false
searchAdapter = TestListRecyclerAdapter(
this,
searchedTestList,
TestListRecyclerAdapter.PAGE_TYPE_SEARCH
)
searchAdapter?.onItemClickListener = MyBaseAdapter.OnItemClickListener { _, _, data ->
TestsIn.getTestsImpl().testDetailH5(data.id.toString())
}
rv_search_key_list.adapter = searchAdapter
val layoutManager = LinearLayoutManager(
this,
LinearLayoutManager.VERTICAL,
false
)
rv_search_key_list.layoutManager = layoutManager
onScrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
override fun onLoadMore(page: Int, totalItemsCount: Int, view: RecyclerView?) {
when (currentSelectedPage) {
TYPE_ALL -> {
mPresenter.searchTests(keyWord, searchListCurrentAllPage, 0)
}
TYPE_PAST -> {
mPresenter.searchTests(keyWord, searchListCurrentPastPage, 1)
}
TYPE_FREE -> {
mPresenter.searchTests(keyWord, searchListCurrentFreePage, 2)
}
}
}
}
rv_search_key_list.addOnScrollListener(onScrollListener)
}
private fun setupListeners() {
tvKeyBack.setOnClickListener(this)
etKeySearch.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (TextUtils.isEmpty(s.toString())) {
}
}
})
etKeySearch.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
this.keyWord = etKeySearch.text.toString()
tv_search_key_empty?.text = String.format("为您找到以下跟“%s”有关的内容", keyWord)
if (TextUtils.isEmpty(keyWord)) {
ToastUtil.toastShort(getString(R.string.tests_no_search_keyword_hint))
} else {
doSearch(keyWord)
}
}
true
}
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
when (tab?.text.toString()) {
"全部" -> {
currentSelectedPage = TYPE_ALL
searchListCurrentAllPage = 1
mPresenter.searchTests(keyWord, searchListCurrentAllPage, 0)
}
"付费" -> {
currentSelectedPage = TYPE_PAST
searchListCurrentPastPage = 1
mPresenter.searchTests(keyWord, searchListCurrentPastPage, 1)
}
"免费" -> {
currentSelectedPage = TYPE_FREE
searchListCurrentFreePage = 1
mPresenter.searchTests(keyWord, searchListCurrentFreePage, 2)
}
}
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
}
fun doSearch(keyword: String?) {
currentSelectedPage = TYPE_ALL
searchListCurrentAllPage = 1
mPresenter.searchTests(keyword, searchListCurrentAllPage, 0)
tabLayout.getTabAt(0)?.select()
}
override fun showLoadingView() {
swipe_refresh_layout_key.isRefreshing = true
}
override fun hideLoadingView() {
swipe_refresh_layout_key.isRefreshing = false
}
override fun showError(msg: String) {
ToastUtil.toastShort(msg)
}
override fun showNoResultView() {
llKeyEmpty.visibility = View.VISIBLE
iv_Key_empty.visibility = View.VISIBLE
}
override fun hideNoResultView() {
llKeyEmpty.visibility = View.GONE
}
override fun showSearchResultView(testList: List<Test>?, page: Int) {
hideSoftInput()
if (page == 1) {
rv_search_key_list.adapter = searchAdapter
onScrollListener.resetState()
searchedTestList.clear()
}
if (testList != null && testList.isNotEmpty()) {
searchedTestList.addAll(testList)
searchAdapter?.notifyDataSetChanged()
} else {
searchAdapter?.hasMore = false
searchAdapter?.notifyDataSetChanged()
}
when (currentSelectedPage) {
TYPE_ALL -> {
searchListCurrentAllPage++
}
TYPE_PAST -> {
searchListCurrentPastPage++
}
TYPE_FREE -> {
searchListCurrentFreePage++
}
}
}
fun hideSoftInput() {
val view = this.currentFocus
if (view != null) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
override fun onRecommendSearchListResponse(testList: List<RecommendSearchItemBean>) {
}
override fun onHotRecommendResponse(datalist: List<Test>) {
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.tvKeyBack -> {
finish()
}
}
}
override fun onResume() {
super.onResume()
//每次可见,更新优惠券信息
TestHomeUtils.updateCouponMoney()
}
fun onEvent(updateCouponMoneyEvent: UpdateCouponMoneyEvent) {
searchAdapter?.couponMoney = updateCouponMoneyEvent.money
searchAdapter?.notifyDataSetChanged()
}
override fun onDestroy() {
super.onDestroy()
EventBus.getDefault().unregister(this)
}
}
......@@ -79,7 +79,7 @@ class TestSearchPresenter : SimplePresenter<TestSearchView>() {
})
}
fun searchTests(keyword: String?, page: Int) {
fun searchTests(keyword: String?, page: Int, type: Int) {
if (page == 1) {
mView.showLoadingView()
}
......@@ -88,6 +88,7 @@ class TestSearchPresenter : SimplePresenter<TestSearchView>() {
cmd.tab = "search"
cmd.page = page
cmd.keyword = keyword
cmd.type = type
TestRetrofitApi.getTestRetrofitApi()
.fetchTestList(NetworkParamsUtils.getMaps(cmd))
.subscribeOn(Schedulers.io())
......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
tools:context=".search.TestSearchActivity">
<LinearLayout
android:id="@+id/ll_title"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center_vertical"
app:layout_constraintTop_toTopOf="parent">
<com.ydl.ydlcommon.view.DeleteEditTextView
android:id="@+id/etKeySearch"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/tests_bg_test_search_input"
android:drawableStart="@drawable/tests_search_gray"
android:drawableLeft="@drawable/tests_search_gray"
android:drawablePadding="8dp"
android:ems="10"
android:hint="输入标题与内容"
android:imeOptions="actionSearch"
android:inputType="text|textPersonName"
android:lines="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textCursorDrawable="@color/platform_color_42C1FF"
android:textSize="14sp" />
<TextView
android:id="@+id/tvKeyBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dp"
android:padding="10dp"
android:text="@string/platform_cancel"
android:textColor="@color/platform_color_999999" />
</LinearLayout>
<TextView
android:id="@+id/tv_search_key_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="44dp"
app:tabIndicatorColor="@color/blue"
app:tabIndicatorFullWidth="false"
app:tabIndicatorHeight="3dp" />
<View style="@style/platform_viewline" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_key"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_search_key_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/llKeyEmpty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/iv_Key_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:src="@drawable/platform_ico_img_zixun_empty"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment