diff --git a/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultFragment.kt b/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultFragment.kt index 54af711c..6dd0d883 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultFragment.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultFragment.kt @@ -1,12 +1,13 @@ package com.navinfo.omqs.ui.fragment.evaluationresult +import android.app.Activity +import android.content.Intent import android.os.Build import android.os.Bundle +import android.provider.MediaStore import android.util.Log -import android.view.LayoutInflater -import android.view.MotionEvent -import android.view.View -import android.view.ViewGroup +import android.view.* +import androidx.activity.result.contract.ActivityResultContracts import androidx.databinding.DataBindingUtil import androidx.navigation.NavOptions import androidx.navigation.findNavController @@ -21,7 +22,6 @@ import com.navinfo.omqs.ui.dialog.FirstDialog import com.navinfo.omqs.ui.fragment.BaseFragment import com.navinfo.omqs.ui.other.shareViewModels import dagger.hilt.android.AndroidEntryPoint -import org.videolan.vlc.Util @AndroidEntryPoint @@ -106,15 +106,26 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener { val list = mutableListOf("1", "2", "3") pictureAdapter.refreshData(list) + //照片左右选择键点击监听 binding.evaluationPictureLeft.setOnClickListener(this) binding.evaluationPictureRight.setOnClickListener(this) + binding.evaluationCamera.setOnClickListener(this) + //设置照片偏移量 + val viewPager = binding.evaluationPictureViewpager + val vto = viewPager.viewTreeObserver + vto.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + val width = viewPager.width + // 处理View宽度 + // 在回调完成后,需要将监听器从View树中移除,以避免重复调用 + viewPager.viewTreeObserver.removeOnGlobalLayoutListener(this) + val recyclerView = viewPager.getChildAt(0) as RecyclerView - val recyclerView = binding.evaluationPictureViewpager.getChildAt(0) as RecyclerView - - recyclerView.setPadding(0, 0, Util.convertDpToPx(requireContext(), 50), 0) - recyclerView.clipToPadding = false - + recyclerView.setPadding(0, 0, width / 2, 0) + recyclerView.clipToPadding = false + } + }) binding.evaluationVoice.setOnTouchListener { _, event -> Log.e("qj", event?.action.toString()) @@ -123,11 +134,7 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener { voiceOnTouchStart()//Do Something } - MotionEvent.ACTION_UP -> { - voiceOnTouchStop()//Do Something - } - - MotionEvent.ACTION_CANCEL -> { + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_OUTSIDE -> { voiceOnTouchStop()//Do Something } } @@ -338,7 +345,9 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener { } } - + R.id.evaluation_camera -> { + takePhoto() + } else -> {} } } @@ -362,4 +371,24 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener { return true } + private fun takePhoto() { + try { + val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + + val someActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val data: Intent? = result.data + // 处理返回的结果 + } + } + + someActivityResultLauncher.launch(intent) + + } catch (e: Exception) { + Log.d("TTTT", e.toString()) + } + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultViewModel.kt b/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultViewModel.kt index e5f47088..aa679ccb 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultViewModel.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/fragment/evaluationresult/EvaluationResultViewModel.kt @@ -201,7 +201,8 @@ class EvaluationResultViewModel @Inject constructor( var classCode = list[0].elementCode liveDataLeftTypeList.postValue(it) if (bean != null) { - val classType2 = roomAppDatabase.getScProblemTypeDao().findClassTypeByCode(bean.renderEntity.code) + val classType2 = roomAppDatabase.getScProblemTypeDao() + .findClassTypeByCode(bean.renderEntity.code) if (classType2 != null) { classType = classType2 } @@ -364,13 +365,19 @@ class EvaluationResultViewModel @Inject constructor( Realm.getDefaultInstance().use { realm -> realm.executeTransactionAsync { bgRealm -> // find the item - val objects = bgRealm.where(QsRecordBean::class.java).equalTo("id", id).findFirst() + val objects = + bgRealm.where(QsRecordBean::class.java).equalTo("id", id).findFirst() if (objects != null) { oldBean = bgRealm.copyFromRealm(objects) oldBean?.let { liveDataQsRecordBean.postValue(it.copy()) val p = GeometryTools.createGeoPoint(it.geometry) - mapController.markerHandle.addMarker(GeoPoint(p.latitude, p.longitude), markerTitle) + mapController.markerHandle.addMarker( + GeoPoint( + p.latitude, + p.longitude + ), markerTitle + ) //获取linkid if (it.linkId.isNotEmpty()) { @@ -381,7 +388,8 @@ class EvaluationResultViewModel @Inject constructor( } } } - liveDataQsRecordBean.value?.attachmentBeanList = it.attachmentBeanList + liveDataQsRecordBean.value?.attachmentBeanList = + it.attachmentBeanList // 显示语音数据到界面 getChatMsgEntityList() } @@ -508,9 +516,13 @@ class EvaluationResultViewModel @Inject constructor( fun stopSoundMeter() { //先重置标识,防止按钮抬起时触发语音结束 Constant.IS_VIDEO_SPEED = false - if (mSoundMeter != null && mSoundMeter!!.isStartSound()) { + if (mSoundMeter != null && mSoundMeter!!.isStartSound) { mSoundMeter!!.stop() } - if (pop != null && pop!!.isShowing) pop!!.dismiss() + pop?.let { + if(it.isShowing){ + it.dismiss() + } + } } } \ No newline at end of file