fix(home): 修复健康资讯搜索功能及咨询栏目加载逻辑
搜索框从 TextView 改为 EditText 以支持键盘输入和搜索键触发, 搜索回调携带关键字参数透传到 H5 搜索页。健康咨询栏目从硬编码 categoryId=2 改为从栏目列表动态读取第二个栏目 ID。新增新疆项目 H5 基础地址方法修正生产环境 URL,健康知识 H5 路径回归使用 getHealthNewsH5BaseUrl 避免丢失 healthnewsweb 路径层级。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
bb23c00e9c
commit
c33c76f732
@@ -522,7 +522,7 @@ class HomeFragment :
|
||||
|
||||
// 健康知识 - 搜索
|
||||
mBinding.healthKnowledgeView.setOnSearchClickListener {
|
||||
navigateToHealthKnowledgeSearch()
|
||||
navigateToHealthKnowledgeSearch(it)
|
||||
}
|
||||
|
||||
|
||||
@@ -545,7 +545,6 @@ class HomeFragment :
|
||||
onSuccess = { token ->
|
||||
mHealthToken = token
|
||||
loadCategories(token)
|
||||
loadConsultationArticles(token)
|
||||
},
|
||||
onFailure = { /* Token 获取失败,静默处理 */ }
|
||||
)
|
||||
@@ -566,6 +565,9 @@ class HomeFragment :
|
||||
if (mKnowledgeCategories.isNotEmpty()) {
|
||||
loadKnowledgeArticles(mKnowledgeCategories[0].categoryId)
|
||||
}
|
||||
if (categories.isNotEmpty() && categories.size >= 2) {
|
||||
loadConsultationArticles(categories[1].categoryId)
|
||||
}
|
||||
},
|
||||
onFailure = { /* 栏目加载失败,静默处理 */ }
|
||||
)
|
||||
@@ -584,15 +586,17 @@ class HomeFragment :
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载健康咨询文章列表(categoryId=2) */
|
||||
private fun loadConsultationArticles(token: String) {
|
||||
mHealthInfoRequest?.fetchArticleList(
|
||||
token, 2,
|
||||
onSuccess = { articles->
|
||||
mBinding.healthConsultationView.setArticles(articles)
|
||||
},
|
||||
onFailure = { /* 文章加载失败,静默处理 */ }
|
||||
)
|
||||
/** 加载健康咨询文章列表(categoryId) */
|
||||
private fun loadConsultationArticles(categoryId: Int) {
|
||||
mHealthToken?.let { token ->
|
||||
mHealthInfoRequest?.fetchArticleList(
|
||||
token, categoryId,
|
||||
onSuccess = { articles ->
|
||||
mBinding.healthConsultationView.setArticles(articles)
|
||||
},
|
||||
onFailure = { /* 文章加载失败,静默处理 */ }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳转文章详情 H5 */
|
||||
@@ -618,14 +622,14 @@ class HomeFragment :
|
||||
requireContext().startWebActivity(url, isFull = true, myTitle = "健康知识", hideStatus = true)
|
||||
}
|
||||
/** 跳转健康知识 搜索 */
|
||||
private fun navigateToHealthKnowledgeSearch() {
|
||||
private fun navigateToHealthKnowledgeSearch(key: String) {
|
||||
val param = mViewModel.enCryptInfoUrl.value
|
||||
if (param.isNullOrEmpty()) {
|
||||
mViewModel.getSysEnCryptInfo(UrlConfig.getHomeBankH5Url())
|
||||
showToast("网络错误")
|
||||
return
|
||||
}
|
||||
val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param"
|
||||
val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param&searchVal=$key"
|
||||
requireContext().startWebActivity(url, isFull = true, myTitle = "搜索", hideStatus = true)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ object UrlConfig {
|
||||
//手机银行
|
||||
const val SECRET_KEY = "XJp3EHpcnwReXc1A"
|
||||
private const val TEST_HOME_BANK_IP = "https://gstest.superwx.cn/"
|
||||
private const val PRODUCT_HOME_BANK_IP = "https://api-jkglpt.iosp.ydpt.tech/"
|
||||
|
||||
|
||||
val baseUrlType: BaseUrlType = BaseUrlType.PRODUCT
|
||||
@@ -82,7 +81,7 @@ object UrlConfig {
|
||||
}
|
||||
|
||||
BaseUrlType.PRODUCT -> {
|
||||
PRODUCT_HOME_BANK_IP
|
||||
PRODUCT_DEFAULT_IP_ADDRESS_REMOTE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,6 +102,18 @@ object UrlConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fun getH5BaseXjUrl(baseUrlType: BaseUrlType = BaseUrlType.PRODUCT): String {
|
||||
return when (baseUrlType) {
|
||||
BaseUrlType.DEBUG, BaseUrlType.TEST -> {
|
||||
TEST_HOME_BANK_IP
|
||||
}
|
||||
|
||||
BaseUrlType.PRODUCT -> {
|
||||
"$PRODUCT_H5_ADDRESS_REMOTE/hb/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBankH5Url(baseUrlType: BaseUrlType = BaseUrlType.PRODUCT): String {
|
||||
return when (baseUrlType) {
|
||||
BaseUrlType.DEBUG, BaseUrlType.TEST-> {
|
||||
@@ -129,7 +140,7 @@ object UrlConfig {
|
||||
* 健康资讯 H5 页面基础地址
|
||||
*/
|
||||
fun getHealthNewsH5BaseUrl(): String {
|
||||
return getDefaultBankBaseUrl() + "healthnewsweb/"
|
||||
return getH5BaseXjUrl() + "healthnewsweb/"
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,10 +2,14 @@ package com.xjjk.healthyclients.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.sw.healthyclients.view.CustomToast
|
||||
import com.xjjk.healthyclients.R
|
||||
import com.xjjk.healthyclients.adapter.HealthKnowledgeAdapter
|
||||
import com.xjjk.healthyclients.bean.home.ArticleBean
|
||||
@@ -31,7 +35,7 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
|
||||
private var mOnTabSelectedListener: ((CategoryBean) -> Unit)? = null
|
||||
private var mOnItemClickListener: ((ArticleBean) -> Unit)? = null
|
||||
private var mOnMoreClickListener: (() -> Unit)? = null
|
||||
private var mOnSearchClickListener: (() -> Unit)? = null
|
||||
private var mOnSearchClickListener: ((String) -> Unit)? = null
|
||||
|
||||
init {
|
||||
mBinding.rvList.layoutManager = LinearLayoutManager(mContext)
|
||||
@@ -48,8 +52,33 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
|
||||
}
|
||||
|
||||
// 健康知识 - 搜索
|
||||
mBinding.searchView.root.setOnClickListener {
|
||||
mOnSearchClickListener?.invoke()
|
||||
mBinding.searchView.customSearchTv.setOnClickListener {
|
||||
val toString = mBinding.searchView.customSearchEt.text.toString()
|
||||
if (toString.isEmpty()) {
|
||||
CustomToast.makeText(context, "请输入搜索内容", CustomToast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
mOnSearchClickListener?.invoke(toString)
|
||||
}
|
||||
|
||||
// 键盘搜索键监听
|
||||
mBinding.searchView.customSearchEt.setOnEditorActionListener { _, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH
|
||||
|| (event != null && event.keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN)
|
||||
) {
|
||||
val keyword = mBinding.searchView.customSearchEt.text.toString()
|
||||
if (keyword.isEmpty()) {
|
||||
CustomToast.makeText(context, "请输入搜索内容", CustomToast.LENGTH_SHORT).show()
|
||||
return@setOnEditorActionListener true
|
||||
}
|
||||
// 隐藏键盘
|
||||
val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
imm?.hideSoftInputFromWindow(mBinding.searchView.customSearchEt.windowToken, 0)
|
||||
mOnSearchClickListener?.invoke(keyword)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +89,14 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
|
||||
fun setupTabs(categories: MutableList<CategoryBean>) {
|
||||
mCategoryList.clear()
|
||||
mCategoryList.addAll(categories)
|
||||
if (categories.isEmpty()) {
|
||||
mBinding.tabLayout.visibility = GONE
|
||||
mBinding.tvEmpty.visibility = VISIBLE
|
||||
return
|
||||
}
|
||||
|
||||
mBinding.tabLayout.visibility = VISIBLE
|
||||
mBinding.tvEmpty.visibility = GONE
|
||||
|
||||
mBinding.tabLayout.removeAllTabs()
|
||||
val array = Array<String>(categories.size) {
|
||||
@@ -103,7 +140,7 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
|
||||
mOnMoreClickListener = listener
|
||||
}
|
||||
|
||||
fun setOnSearchClickListener(listener: () -> Unit) {
|
||||
fun setOnSearchClickListener(listener: (keyword: String) -> Unit) {
|
||||
mOnSearchClickListener = listener
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,19 +25,25 @@
|
||||
android:layout_marginLeft="@dimen/dp_17"
|
||||
android:src="@mipmap/ic_search" />
|
||||
|
||||
<TextView
|
||||
|
||||
<EditText
|
||||
android:id="@+id/custom_search_et"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/dp_38"
|
||||
android:gravity="center_vertical"
|
||||
android:text="请输入关键字进行搜索"
|
||||
android:background="@null"
|
||||
android:longClickable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/search_hint"
|
||||
android:maxLines="1"
|
||||
android:textColor="#B6B6B6"
|
||||
android:imeOptions="actionSearch"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/text_black_33"
|
||||
android:textColorHint="#B6B6B6"
|
||||
android:textSize="@dimen/txt13" />
|
||||
|
||||
|
||||
<com.allen.library.shape.ShapeTextView
|
||||
android:id="@+id/custom_search_tv"
|
||||
android:layout_width="55dp"
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:text="健康咨询"
|
||||
android:text="健康资讯"
|
||||
android:textColor="@color/text_black_33"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
Reference in New Issue
Block a user