Explorar o código

1.添加医生搜索功能

王鹏鹏 hai 1 ano
pai
achega
9a713e09e1

+ 1 - 2
config.gradle

@@ -123,7 +123,6 @@ ext {
             "navigation_ui_ktx"        : 'androidx.navigation:navigation-ui-ktx:2.3.5',
             "Luban"                    : 'top.zibin:Luban:1.1.8',
             // 动态申请权限 https://github.com/getActivity/XXPermissions
-            "xxPermission"             : "com.github.getActivity:XXPermissions:18.3",
-            "imageSelector"            : "com.github.donkingliang:ImageSelector:2.2.1"
+            "xxPermission"             : "com.github.getActivity:XXPermissions:18.3"
     ]
 }

+ 1 - 1
healthconsultation/src/main/AndroidManifest.xml

@@ -68,7 +68,7 @@
 
         <activity
             android:name="com.yingyang.healthconsultation.search.SearchDoctorActivity"
-            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:configChanges="orientation|screenSize"
             android:screenOrientation="landscape"
             android:windowSoftInputMode="adjustResize|adjustPan" />
     </application>

+ 37 - 13
healthconsultation/src/main/java/com/yingyang/healthconsultation/search/SearchDoctorActivity.kt

@@ -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!!)

+ 1 - 1
healthconsultation/src/main/manifest/AndroidManifest.xml

@@ -68,7 +68,7 @@
 
         <activity
             android:name="com.yingyang.healthconsultation.search.SearchDoctorActivity"
-            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:configChanges="orientation|screenSize"
             android:screenOrientation="landscape"
             android:windowSoftInputMode="adjustResize|adjustPan" />
     </application>

+ 15 - 18
healthconsultation/src/main/res/layout/activity_search_doctor.xml

@@ -42,10 +42,11 @@
             android:layout_height="@dimen/divider_60px"
             android:layout_marginStart="@dimen/divider_42px"
             android:layout_marginTop="@dimen/divider_32px"
+            android:layout_marginEnd="@dimen/divider_22px"
             android:background="@drawable/bg_home_page_search"
             android:gravity="center_vertical"
             android:orientation="horizontal"
-            app:layout_constraintEnd_toStartOf="@+id/btnSearch"
+            app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toEndOf="@+id/backLayout"
             app:layout_constraintTop_toTopOf="parent">
 
@@ -59,32 +60,28 @@
 
             <androidx.appcompat.widget.AppCompatEditText
                 android:id="@+id/editDoctor"
-                android:layout_width="match_parent"
+                android:layout_width="0dp"
                 android:layout_height="match_parent"
                 android:layout_marginStart="@dimen/divider_9px"
+                android:layout_weight="1"
                 android:background="@null"
+                android:focusable="true"
+                android:focusableInTouchMode="true"
                 android:gravity="center_vertical"
                 android:hint="@string/please_input_doctors_name"
                 android:textColor="@color/color_FF333333"
                 android:textColorHint="@color/color_FF767575"
                 android:textSize="@dimen/divider_28px" />
-        </LinearLayout>
 
-        <androidx.appcompat.widget.AppCompatButton
-            android:id="@+id/btnSearch"
-            android:layout_width="@dimen/divider_120px"
-            android:layout_height="@dimen/divider_60px"
-            android:layout_marginStart="@dimen/divider_20px"
-            android:layout_marginTop="@dimen/divider_32px"
-            android:layout_marginEnd="@dimen/divider_20px"
-            android:background="@drawable/bg_home_page_search"
-            android:gravity="center"
-            android:text="@string/search"
-            android:textColor="@color/color_FF333333"
-            android:textSize="@dimen/divider_28px"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toEndOf="@+id/searchLayout"
-            app:layout_constraintTop_toTopOf="parent" />
+            <androidx.appcompat.widget.AppCompatImageView
+                android:id="@+id/imageClear"
+                android:layout_width="@dimen/divider_26px"
+                android:layout_height="@dimen/divider_26px"
+                android:layout_marginStart="@dimen/divider_26px"
+                android:layout_marginEnd="@dimen/divider_26px"
+                android:background="@mipmap/icon__close_btn"
+                android:visibility="gone" />
+        </LinearLayout>
 
         <com.google.android.material.card.MaterialCardView
             android:layout_width="match_parent"

BIN=BIN
healthconsultation/src/main/res/mipmap-xxhdpi/icon__close_btn.png


+ 1 - 0
healthconsultation/src/main/res/values/dimens.xml

@@ -59,6 +59,7 @@
     <dimen name="divider_253px" tools:ignore="ResourceName">253px</dimen>
     <dimen name="divider_250px" tools:ignore="ResourceName">250px</dimen>
     <dimen name="divider_249px" tools:ignore="ResourceName">249px</dimen>
+    <dimen name="divider_248px" tools:ignore="ResourceName">248px</dimen>
     <dimen name="divider_245px" tools:ignore="ResourceName">245px</dimen>
     <dimen name="divider_240px" tools:ignore="ResourceName">240px</dimen>
     <dimen name="divider_237px" tools:ignore="ResourceName">237px</dimen>