Commit 09db41a9 by fengquan

feat: 倾诉列表添加搜索框

parent 9014f2e8
......@@ -410,6 +410,7 @@ class ConfideHomeActivity :
initParam()
hideError()
cacheList?.addAll(0, list)
cacheList?.add(0, ConfideHomeDataBean(IConfideHomeConfig.TYPE_SEARCH,null,null,null, -1))
updateAdapter()
setSuspendListener()
v_filterView.refreshView()
......@@ -419,7 +420,7 @@ class ConfideHomeActivity :
* 设置筛选模块悬浮顶部监听数据
*/
private fun setSuspendListener() {
listSuspendListener?.setFilterView(v_filterView, vFilterLine)
listSuspendListener?.setFilterView(v_filterView,rl_search_head, vFilterLine)
listSuspendListener?.setSectionAdapter(mConfideAdapter!!)
}
......
package com.ydl.confide.home.adapter
import android.app.Activity
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
......@@ -12,6 +21,8 @@ import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.*
import com.ydl.ydlcommon.utils.DisplayUtils
import com.ydl.ydlcommon.utils.KeyboardChangeListener
import com.yidianling.common.tools.RxKeyboardTool
/**
* @author yuanwai
......@@ -20,9 +31,11 @@ import com.ydl.ydlcommon.utils.DisplayUtils
* @Company 壹点灵
* @date 2018/12/14
*/
class ConfideHomeAdapter(private val mContext: Context,
private var confideHomeEvent: IConfideHomeEvent,
private var confideHomeView: IConfideHomeContract.View) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ConfideHomeAdapter(
private val mContext: Context,
private var confideHomeEvent: IConfideHomeEvent,
private var confideHomeView: IConfideHomeContract.View
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mListData: List<ConfideHomeDataBean>? = null
private var mFilterViewHolder: FilterViewHolder? = null
......@@ -101,7 +114,13 @@ class ConfideHomeAdapter(private val mContext: Context,
}
//为你推荐
IConfideHomeConfig.TYPE_RECOMMEND -> {
return RecommendViewHolder(ConfideHomeRecommendView(confideHomeView, parent.context, confideHomeEvent))
return RecommendViewHolder(
ConfideHomeRecommendView(
confideHomeView,
parent.context,
confideHomeEvent
)
)
}
IConfideHomeConfig.TYPE_VIDEO_SHOW -> {
val recyclerView = RecyclerView(parent.context)
......@@ -114,6 +133,15 @@ class ConfideHomeAdapter(private val mContext: Context,
}
return VideoShowHolder(recyclerView)
}
//顶部搜索
IConfideHomeConfig.TYPE_SEARCH -> {
return SearchViewHolder(
LayoutInflater.from(mContext)
.inflate(R.layout.confide_home_search_header, parent, false)
)
}
// //听声寻人
// IConfideHomeConfig.TYPE_SOUND -> {
//// return ConfideHomeListenAndFoundViewHolder(ConfideHomeListenAndFoundView(parent.context, confideHomeEvent))
......@@ -125,40 +153,82 @@ class ConfideHomeAdapter(private val mContext: Context,
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) =
/*if (holder is BannerViewHolder && null != holder.bannerView) {
//banner
holder.bannerView!!.initData(mListData!![position])
} else if (holder is CategoryViewHolder && null != holder.categoryView) {
//分类
holder.categoryView!!.initData(mListData!![position])
} else */if (holder is FilterViewHolder && null != holder.filterView) {
mFilterViewHolder = holder
//筛选模块
holder.filterView.initData(mListData!![position])
} else if (holder is ConfideHomeListenAndFoundViewHolder) {
//听声寻人
/*if (holder is BannerViewHolder && null != holder.bannerView) {
//banner
holder.bannerView!!.initData(mListData!![position])
} else if (holder is CategoryViewHolder && null != holder.categoryView) {
//分类
holder.categoryView!!.initData(mListData!![position])
} else */if (holder is FilterViewHolder && null != holder.filterView) {
mFilterViewHolder = holder
//筛选模块
holder.filterView.initData(mListData!![position])
} else if (holder is ConfideHomeListenAndFoundViewHolder) {
//听声寻人
// holder.confideHomeListenAndFoundView!!.initData(mListData!![position])
} else if (holder is RecentConfideHolder) {
} else if (holder is RecentConfideHolder) {
//最近倾诉
holder.rv.layoutManager =
LinearLayoutManager(holder.itemView.context, RecyclerView.HORIZONTAL, false)
val recentBody = mListData!![position].body
val data = recentBody?.map { ItemVideoShowViewModel().mapOf(it) } ?: emptyList()
holder.rv.adapter = RecentConfideAdapter(data, confideHomeEvent)
holder.rv.layoutManager =
LinearLayoutManager(holder.itemView.context, RecyclerView.HORIZONTAL, false)
val recentBody = mListData!![position].body
val data = recentBody?.map { ItemVideoShowViewModel().mapOf(it) } ?: emptyList()
holder.rv.adapter = RecentConfideAdapter(data, confideHomeEvent)
// holder.consultView!!.initData(mListData!![position])
} else if (holder is RecommendViewHolder && null != mListData!![position] && null != mListData!![position].body && !mListData!![position].body!!.isEmpty()) {
//为你推荐
holder.confideHomeRecommendView.initData(mListData!![position].body!![0], position, mListData!![position].recommendId)
} else if (holder is VideoShowHolder) {
holder.rv.layoutManager =
LinearLayoutManager(holder.itemView.context, RecyclerView.HORIZONTAL, false)
val recentBody = mListData!![position].body
holder.rv.adapter = VideoShowAdapter(recentBody, confideHomeEvent)
} else if (holder is EmptyViewHolder) {
} else {
} else if (holder is RecommendViewHolder && null != mListData!![position] && null != mListData!![position].body && !mListData!![position].body!!.isEmpty()) {
//为你推荐
holder.confideHomeRecommendView.initData(
mListData!![position].body!![0],
position,
mListData!![position].recommendId
)
} else if (holder is VideoShowHolder) {
holder.rv.layoutManager =
LinearLayoutManager(holder.itemView.context, RecyclerView.HORIZONTAL, false)
val recentBody = mListData!![position].body
holder.rv.adapter = VideoShowAdapter(recentBody, confideHomeEvent)
} else if (holder is SearchViewHolder) {
holder.searchView.findViewById<EditText>(R.id.etSearch)
.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Log.e("fqLog", "点击了");
RxKeyboardTool.hideSoftInput(mContext as Activity?)
}
true
}
val keyboardChangeListener = KeyboardChangeListener(mContext as Activity?)
keyboardChangeListener.setKeyBoardListener { isShow, i ->
if (!isShow){
holder.searchView.findViewById<EditText>(R.id.etSearch).clearFocus()
}
}
holder.searchView.findViewById<EditText>(R.id.etSearch).addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
if (TextUtils.isEmpty(p0)) {
holder.searchView.findViewById<ImageView>(R.id.iv_delete_icon).visibility = View.INVISIBLE
} else {
holder.searchView.findViewById<ImageView>(R.id.iv_delete_icon).visibility = View.VISIBLE
}
}
override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(char: CharSequence, p1: Int, p2: Int, p3: Int) {
}
})
holder.searchView.findViewById<ImageView>(R.id.iv_delete_icon).setOnClickListener {
holder.searchView.findViewById<EditText>(R.id.etSearch).setText("")
}
} else if (holder is EmptyViewHolder) {
} else {
}
override fun getItemCount(): Int {
return mListData!!.size
......@@ -167,7 +237,8 @@ class ConfideHomeAdapter(private val mContext: Context,
/**
* banner viewHolder
*/
inner class BannerViewHolder(itemView: ConfideHomeBannerView) : RecyclerView.ViewHolder(itemView) {
inner class BannerViewHolder(itemView: ConfideHomeBannerView) :
RecyclerView.ViewHolder(itemView) {
var bannerView: ConfideHomeBannerView? = null
init {
......@@ -178,7 +249,8 @@ class ConfideHomeAdapter(private val mContext: Context,
/**
* 分类测评 viewHolder
*/
inner class CategoryViewHolder(itemView: ConfideHomeCategoryView) : RecyclerView.ViewHolder(itemView) {
inner class CategoryViewHolder(itemView: ConfideHomeCategoryView) :
RecyclerView.ViewHolder(itemView) {
var categoryView: ConfideHomeCategoryView? = null
init {
......@@ -189,22 +261,31 @@ class ConfideHomeAdapter(private val mContext: Context,
/**
* 筛选模块 viewHolder
*/
inner class FilterViewHolder(var filterView: ConfideHomeFilterView) : RecyclerView.ViewHolder(filterView)
inner class FilterViewHolder(var filterView: ConfideHomeFilterView) :
RecyclerView.ViewHolder(filterView)
/**
* 搜索模块 viewHolder
*/
inner class SearchViewHolder(var searchView: View) : RecyclerView.ViewHolder(searchView)
/**
* 听声寻人 viewHolder
*/
inner class ConfideHomeListenAndFoundViewHolder(var confideHomeListenAndFoundView: ConfideHomeListenAndFoundView) : RecyclerView.ViewHolder(confideHomeListenAndFoundView)
inner class ConfideHomeListenAndFoundViewHolder(var confideHomeListenAndFoundView: ConfideHomeListenAndFoundView) :
RecyclerView.ViewHolder(confideHomeListenAndFoundView)
/**
* 最近倾诉 viewHolder
*/
inner class ConsultViewHolder(var consultView: ConfideHomeRecentView) : RecyclerView.ViewHolder(consultView)
inner class ConsultViewHolder(var consultView: ConfideHomeRecentView) :
RecyclerView.ViewHolder(consultView)
/**
* 为你推荐 viewHolder
*/
inner class RecommendViewHolder(var confideHomeRecommendView: ConfideHomeRecommendView) : RecyclerView.ViewHolder(confideHomeRecommendView)
inner class RecommendViewHolder(var confideHomeRecommendView: ConfideHomeRecommendView) :
RecyclerView.ViewHolder(confideHomeRecommendView)
/**
* 空ViewHolder
......@@ -216,6 +297,7 @@ class ConfideHomeAdapter(private val mContext: Context,
view = itemView
}
}
class VideoShowHolder(val rv: RecyclerView) : RecyclerView.ViewHolder(rv)
class RecentConfideHolder(val rv: RecyclerView) : RecyclerView.ViewHolder(rv)
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ interface IConfideHomeConfig{
const val TYPE_RECOMMEND = 5
const val TYPE_SOUND = 6
const val TYPE_VIDEO_SHOW = 7
const val TYPE_SEARCH = 8
const val TYPE_FOOTER = 999
/**
* section id. 与上面相对应
......@@ -31,6 +32,7 @@ interface IConfideHomeConfig{
const val SECTION_RECOMMEND = 10005
const val SECTION_SOUND = 10006
const val SECTION_CONSULTANT = 10007
const val SECTION_SEARCH = 10008
const val SECTION_FOOTER = 19999
......
package com.ydl.confide.home.listener
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.adapter.ConfideHomeAdapter
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.widget.ConfideHomeFilterView
import com.ydl.ydlcommon.base.BaseActivityMgr
import com.ydl.ydlcommon.utils.KeyboardChangeListener
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxImageTool
/**
* @author yuanwai
......@@ -22,9 +32,14 @@ class ConfideHomeRecyleSuspendListener : RecyclerView.OnScrollListener() {
private var mSuspensionHeight: Int = RxImageTool.dip2px(48f)
private var mSearchViewHeight: Int = RxImageTool.dip2px(48f)
private var filterView: ConfideHomeFilterView? = null
private var searchView: RelativeLayout? = null
private var divView: View? = null
private var searchText = ""
private var adapter: ConfideHomeAdapter? = null
fun setFilterView(filterView: ConfideHomeFilterView, divView: View) {
......@@ -32,6 +47,49 @@ class ConfideHomeRecyleSuspendListener : RecyclerView.OnScrollListener() {
this.divView = divView
}
fun setFilterView(
filterView: ConfideHomeFilterView,
searchView: RelativeLayout,
divView: View
) {
this.filterView = filterView
this.divView = divView
this.searchView = searchView
val keyboardChangeListener = KeyboardChangeListener(BaseActivityMgr.INST.topActivity)
keyboardChangeListener.setKeyBoardListener { isShow, i ->
if (!isShow) {
searchView.findViewById<EditText>(R.id.etSearch).clearFocus()
}
}
searchView.findViewById<EditText>(R.id.etSearch).addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
if (TextUtils.isEmpty(p0)) {
searchView.findViewById<ImageView>(R.id.iv_delete_icon).visibility = View.INVISIBLE
} else {
searchView.findViewById<ImageView>(R.id.iv_delete_icon).visibility = View.VISIBLE
}
}
override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(char: CharSequence, p1: Int, p2: Int, p3: Int) {
if (char != null){
searchText = char.toString()
}
}
})
searchView.findViewById<ImageView>(R.id.iv_delete_icon).setOnClickListener {
searchView.findViewById<EditText>(R.id.etSearch).setText("")
}
}
fun setSectionAdapter(adapter: ConfideHomeAdapter) {
this.adapter = adapter
}
......@@ -41,6 +99,20 @@ class ConfideHomeRecyleSuspendListener : RecyclerView.OnScrollListener() {
if (null != filterView) {
mSuspensionHeight = filterView!!.height
}
if (searchView != null) {
mSearchViewHeight = searchView!!.height
}
searchView!!.findViewById<EditText>(R.id.etSearch).clearFocus()
val viewHolder = recyclerView.findViewHolderForAdapterPosition(1)
if (viewHolder != null && viewHolder is ConfideHomeAdapter.SearchViewHolder) {
viewHolder.itemView.findViewById<EditText>(R.id.etSearch).clearFocus()
if (newState == 1){
searchView!!.findViewById<EditText>(R.id.etSearch).setText(viewHolder.itemView.findViewById<EditText>(R.id.etSearch).text)
}
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
......@@ -49,26 +121,52 @@ class ConfideHomeRecyleSuspendListener : RecyclerView.OnScrollListener() {
return
}
val manager = recyclerView!!.layoutManager as LinearLayoutManager
val findFirstCompletelyVisibleItemPosition =
manager.findFirstCompletelyVisibleItemPosition();
if (findFirstCompletelyVisibleItemPosition != 0 && findFirstCompletelyVisibleItemPosition != 1) {
searchView?.visibility = View.VISIBLE
} else {
searchView?.visibility = View.INVISIBLE
}
if (mCurrentPosition != manager.findFirstVisibleItemPosition()) {
mCurrentPosition = manager.findFirstVisibleItemPosition()
}
LogUtil.e("http----------------type="+adapter!!.getItemViewType(mCurrentPosition))
if (adapter!!.getItemViewType(mCurrentPosition) == IConfideHomeConfig.TYPE_RECOMMEND) {
LogUtil.e("http----------------type=" + adapter!!.getItemViewType(mCurrentPosition))
if (adapter!!.getItemViewType(mCurrentPosition + 1) == IConfideHomeConfig.TYPE_RECOMMEND) {
var view = manager.findViewByPosition(mCurrentPosition + 1)
if (view != null) {
if (view.top <= mSuspensionHeight) {
filterView!!.visibility = View.VISIBLE
divView?.visibility = View.VISIBLE
} else {
if (view is ConfideHomeFilterView) {
if (view.top <= mSuspensionHeight) {
filterView!!.visibility = View.VISIBLE
divView?.visibility = View.VISIBLE
} else {
// filterView!!.visibility = View.INVISIBLE
filterView!!.visibility = View.INVISIBLE
divView?.visibility = View.INVISIBLE
}
}
}
}else if (adapter!!.getItemViewType(mCurrentPosition) == IConfideHomeConfig.TYPE_RECOMMEND || adapter!!.getItemViewType(mCurrentPosition) == IConfideHomeConfig.TYPE_SOUND){
} else if (adapter!!.getItemViewType(mCurrentPosition + 1) == IConfideHomeConfig.TYPE_RECOMMEND || adapter!!.getItemViewType(
mCurrentPosition + 1
) == IConfideHomeConfig.TYPE_SOUND
) {
filterView!!.visibility = View.VISIBLE
divView?.visibility = View.VISIBLE
}else {
} else {
filterView!!.visibility = View.INVISIBLE
divView?.visibility = View.INVISIBLE
}
if (searchView?.visibility != View.VISIBLE){
val viewHolder = recyclerView.findViewHolderForAdapterPosition(1)
if (viewHolder != null && viewHolder is ConfideHomeAdapter.SearchViewHolder) {
viewHolder.itemView.findViewById<EditText>(R.id.etSearch).setText(searchText)
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="40dp"/>
<solid android:color="#F7F7F7" />
<stroke android:width="1px" android:color="#E6E6E6"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="1dp" />
<span style="font-family: Arial, Helvetica, sans-serif;"/>
<solid android:color="@color/platform_main_theme" />
</shape>
\ No newline at end of file
......@@ -16,7 +16,8 @@
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/quick_consult_card"
......@@ -137,11 +138,75 @@
android:background="#80000000"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/rl_search_head"
android:layout_width="match_parent"
android:layout_height="@dimen/platform_dp_48"
android:background="@color/white"
android:visibility="gone"
tools:visibility="gone">
<View
android:id="@+id/view_search_input_bg"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/confide_dp_15"
android:layout_marginRight="@dimen/confide_dp_15"
android:background="@drawable/confide_bg_hot_search_input"
android:tag="tag_search_input_bg" />
<ImageView
android:id="@+id/iv_search_icon"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/platform_dp_25"
android:layout_marginRight="10dp"
android:scaleType="centerCrop"
android:src="@drawable/confide_icon_input_search"
android:tag="tag_search_input_img" />
<EditText
android:id="@+id/etSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/iv_delete_icon"
android:layout_toRightOf="@id/iv_search_icon"
android:background="@null"
android:cursorVisible="true"
android:hint="请输入倾诉师姓名"
android:imeOptions="actionSearch"
android:maxLength="100"
android:singleLine="true"
android:tag="tag_search_input_edit"
android:textColor="#242424"
android:textColorHint="#b3b3b3"
android:textCursorDrawable="@drawable/confide_edit_cursor_drawable"
android:textSize="13sp" />
<ImageView
android:id="@+id/iv_delete_icon"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignRight="@+id/view_search_input_bg"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:scaleType="centerCrop"
android:src="@drawable/platform_delete"
android:visibility="invisible" />
</RelativeLayout>
<com.ydl.confide.home.widget.ConfideHomeFilterView
android:id="@+id/v_filterView"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/white"
android:layout_below="@+id/rl_search_head"
android:visibility="gone"
tools:visibility="gone"/>
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_search"
android:layout_width="match_parent"
android:layout_height="@dimen/platform_dp_48"
android:focusable="true"
android:focusableInTouchMode="true"
>
<View
android:id="@+id/view_search_input_bg"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/confide_dp_15"
android:layout_marginRight="@dimen/confide_dp_15"
android:background="@drawable/confide_bg_hot_search_input"
android:tag="tag_search_input_bg" />
<ImageView
android:id="@+id/iv_search_icon"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/platform_dp_25"
android:layout_marginRight="10dp"
android:scaleType="centerCrop"
android:src="@drawable/confide_icon_input_search"
android:tag="tag_search_input_img" />
<EditText
android:id="@+id/etSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/iv_delete_icon"
android:layout_toRightOf="@id/iv_search_icon"
android:background="@null"
android:cursorVisible="true"
android:hint="请输入倾诉师姓名"
android:imeOptions="actionSearch"
android:maxLength="100"
android:singleLine="true"
android:tag="tag_search_input_edit"
android:textColor="#242424"
android:textColorHint="#b3b3b3"
android:textCursorDrawable="@drawable/confide_edit_cursor_drawable"
android:textSize="13sp" />
<ImageView
android:id="@+id/iv_delete_icon"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignRight="@+id/view_search_input_bg"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:scaleType="centerCrop"
android:src="@drawable/platform_delete"
android:visibility="invisible" />
</RelativeLayout>
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