项目列表搜索

main
chenglifeng 1 month ago
parent 1d80f1be86
commit 1e5c2e5a2e
  1. 23
      app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt
  2. 2
      app/src/main/java/com/project/survey/network/Api.kt
  3. 10
      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.ProjectBean
import com.project.survey.network.RetrofitClient
import com.project.survey.util.CommonUtils
import com.project.survey.util.SPUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -61,12 +62,15 @@ class ProjectViewModel : BaseViewModel() {
// fun fetchProjectList(name: String? = null, code: String? = null) {
fun fetchProjectList(searchContent: String? = null) {
launch {
var name: String? = null
var code: String? = null
if (CommonUtils.containsChinese(searchContent)) {
name = searchContent
} else {
code = searchContent
}
val res =
api.fetchProjectListByProperty(
SPUtils.getString(SPConstants.PERSON_ID),
searchContent,
searchContent
)
api.fetchProjectListByProperty(SPUtils.getString(SPConstants.PERSON_ID), name, code)
if (res.success) {
_projectListResponse.postValue(res.data.records.map { it.values })
} else {
@ -340,11 +344,10 @@ class ProjectViewModel : BaseViewModel() {
) {
launch {
val res = api.downloadCoordinateSystem()
if (res.success) {
if (res.data.isNotEmpty())
withContext(Dispatchers.Main) {
onSuccess(res.data[0].values)
}
if (res.success && res.data.isNotEmpty()) {
withContext(Dispatchers.Main) {
onSuccess(res.data[0].values)
}
} else {
withContext(Dispatchers.Main) {
onFailure(res.message)

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

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

@ -54,6 +54,30 @@ import lecho.hellocharts.view.LineChartView;
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