项目列表搜索

main
chenglifeng 1 month ago
parent 1d80f1be86
commit 1e5c2e5a2e
  1. 17
      app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt
  2. 2
      app/src/main/java/com/project/survey/network/Api.kt
  3. 8
      app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt
  4. 24
      app/src/main/java/com/project/survey/util/CommonUtils.java

@ -23,6 +23,7 @@ import com.project.survey.model.MeasureWorkStatusResult
import com.project.survey.model.PointEntry import com.project.survey.model.PointEntry
import com.project.survey.model.ProjectBean import com.project.survey.model.ProjectBean
import com.project.survey.network.RetrofitClient import com.project.survey.network.RetrofitClient
import com.project.survey.util.CommonUtils
import com.project.survey.util.SPUtils import com.project.survey.util.SPUtils
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -61,12 +62,15 @@ class ProjectViewModel : BaseViewModel() {
// fun fetchProjectList(name: String? = null, code: String? = null) { // fun fetchProjectList(name: String? = null, code: String? = null) {
fun fetchProjectList(searchContent: String? = null) { fun fetchProjectList(searchContent: String? = null) {
launch { launch {
var name: String? = null
var code: String? = null
if (CommonUtils.containsChinese(searchContent)) {
name = searchContent
} else {
code = searchContent
}
val res = val res =
api.fetchProjectListByProperty( api.fetchProjectListByProperty(SPUtils.getString(SPConstants.PERSON_ID), name, code)
SPUtils.getString(SPConstants.PERSON_ID),
searchContent,
searchContent
)
if (res.success) { if (res.success) {
_projectListResponse.postValue(res.data.records.map { it.values }) _projectListResponse.postValue(res.data.records.map { it.values })
} else { } else {
@ -340,8 +344,7 @@ class ProjectViewModel : BaseViewModel() {
) { ) {
launch { launch {
val res = api.downloadCoordinateSystem() val res = api.downloadCoordinateSystem()
if (res.success) { if (res.success && res.data.isNotEmpty()) {
if (res.data.isNotEmpty())
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
onSuccess(res.data[0].values) onSuccess(res.data[0].values)
} }

@ -83,7 +83,7 @@ interface Api {
/** /**
* 获取项目的信息 * 获取项目的信息
*/ */
@GET("je/project/getProjectInfoByProperty") @GET("je/project/getProjectInfoByPropertyMobile")
suspend fun fetchProjectListByProperty( suspend fun fetchProjectListByProperty(
@Query("personId") personId: String, @Query("personId") personId: String,
@Query("name") name: String?, @Query("name") name: String?,

@ -80,9 +80,8 @@ class ProjectListActivity : BaseBindingActivity<ActivityProjectListBinding>(), O
} }
viewModel.projectListResponse.observe(this) { viewModel.projectListResponse.observe(this) {
mBinding.smartRefreshLayout.smartDismiss() mBinding.smartRefreshLayout.smartDismiss()
if (it.isNotEmpty()) {
adapter.submitList(it) adapter.submitList(it)
} else { if (it.isEmpty()) {
adapter.setStateViewLayout(this, R.layout.layout_no_data) adapter.setStateViewLayout(this, R.layout.layout_no_data)
} }
} }
@ -98,6 +97,11 @@ class ProjectListActivity : BaseBindingActivity<ActivityProjectListBinding>(), O
} }
override fun initListener() { override fun initListener() {
// 搜索
mBinding.searchWidget.setOnEditorSearchListener {
searchContent = it
fetchData()
}
adapter.setOnItemClickListener { adapter, _, position -> adapter.setOnItemClickListener { adapter, _, position ->
adapter.getItem(position)?.let { bean -> adapter.getItem(position)?.let { bean ->
// 进入项目,设置当前项目 // 进入项目,设置当前项目

@ -54,6 +54,30 @@ import lecho.hellocharts.view.LineChartView;
public class CommonUtils { public class CommonUtils {
public static boolean containsChinese(String str){
if (str == null || str.isEmpty()){
return false;
}
for (int i = 0; i < str.length(); i++){
char c = str.charAt(i);
if (isChineseCharacter(c)){
return true;
}
}
return false;
}
public static boolean isChineseCharacter(char c){
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT;
}
/** /**
* 隐藏软键盘 * 隐藏软键盘
*/ */

Loading…
Cancel
Save