|
@@ -1,6 +1,8 @@
|
|
|
package com.yingyang.healthconsultation.search
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.text.Editable
|
|
|
+import android.text.TextWatcher
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
@@ -11,7 +13,7 @@ import com.yingyangfly.baselib.base.BaseActivity
|
|
|
import com.yingyangfly.baselib.db.DoctorBean
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
-import com.yingyangfly.baselib.ext.toast
|
|
|
+import com.yingyangfly.baselib.ext.show
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
|
|
|
/**
|
|
@@ -26,6 +28,7 @@ class SearchDoctorActivity : BaseActivity<ActivitySearchDoctorBinding>(),
|
|
|
|
|
|
override fun initViews() {
|
|
|
binding {
|
|
|
+ showInput(editDoctor)
|
|
|
rvDoctors.adapter = adapter
|
|
|
}
|
|
|
}
|
|
@@ -34,7 +37,33 @@ class SearchDoctorActivity : BaseActivity<ActivitySearchDoctorBinding>(),
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
backLayout.setOnTouchListener(this@SearchDoctorActivity)
|
|
|
- btnSearch.setOnTouchListener(this@SearchDoctorActivity)
|
|
|
+ imageClear.setOnTouchListener(this@SearchDoctorActivity)
|
|
|
+ editDoctor.addTextChangedListener(object : TextWatcher {
|
|
|
+ override fun beforeTextChanged(
|
|
|
+ s: CharSequence?,
|
|
|
+ start: Int,
|
|
|
+ count: Int,
|
|
|
+ after: Int
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun afterTextChanged(s: Editable?) {
|
|
|
+ if (s.toString().isEmpty().not()) {
|
|
|
+ imageClear.show(true)
|
|
|
+ loadData(s.toString())
|
|
|
+ } else {
|
|
|
+ doctorList.clear()
|
|
|
+ adapter.setData(doctorList)
|
|
|
+ imageClear.show(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -46,7 +75,7 @@ class SearchDoctorActivity : BaseActivity<ActivitySearchDoctorBinding>(),
|
|
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
when (event.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
|
- if (v.id == R.id.backLayout || v.id == R.id.btnSearch) {
|
|
|
+ if (v.id == R.id.backLayout || v.id == R.id.imageClear) {
|
|
|
v.startAnimation(getScaleAnimation())
|
|
|
}
|
|
|
}
|
|
@@ -57,17 +86,13 @@ class SearchDoctorActivity : BaseActivity<ActivitySearchDoctorBinding>(),
|
|
|
//返回首页
|
|
|
finish()
|
|
|
}
|
|
|
- R.id.btnSearch -> {
|
|
|
- if (binding.editDoctor.text.toString().trim().isNotEmpty()) {
|
|
|
- loadData()
|
|
|
- } else {
|
|
|
- "请输入医生姓名".toast()
|
|
|
- }
|
|
|
+ R.id.imageClear -> {
|
|
|
+ binding.editDoctor.setText("")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
MotionEvent.ACTION_CANCEL -> {
|
|
|
- if (v.id == R.id.backLayout || v.id == R.id.btnSearch) {
|
|
|
+ if (v.id == R.id.backLayout || v.id == R.id.imageClear) {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
}
|
|
|
}
|
|
@@ -78,10 +103,9 @@ class SearchDoctorActivity : BaseActivity<ActivitySearchDoctorBinding>(),
|
|
|
/**
|
|
|
* 搜索医生列表
|
|
|
*/
|
|
|
- private fun loadData() {
|
|
|
+ private fun loadData(str: String) {
|
|
|
if (doctorDao != null) {
|
|
|
- val doctors =
|
|
|
- doctorDao?.getAllDoctorBeanByName(binding.editDoctor.text.toString().trim())
|
|
|
+ val doctors = doctorDao?.getAllDoctorBeanByName(str)
|
|
|
if (doctors.isNullOrEmpty().not()) {
|
|
|
doctorList.clear()
|
|
|
doctorList.addAll(doctors!!)
|