|
@@ -1,19 +1,29 @@
|
|
|
package com.yingyang.healthconsultation.consultationsheet
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.app.Activity
|
|
|
+import android.content.Intent
|
|
|
+import android.os.Environment
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
+import com.donkingliang.imageselector.utils.ImageSelector
|
|
|
import com.yingyang.healthconsultation.R
|
|
|
import com.yingyang.healthconsultation.adapter.SickTimeAdapter
|
|
|
import com.yingyang.healthconsultation.databinding.ActivityConsultationSheetBinding
|
|
|
+import com.yingyang.healthconsultation.utils.CommonUtils
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
+import com.yingyangfly.baselib.utils.LogUtil
|
|
|
+import top.zibin.luban.Luban
|
|
|
+import top.zibin.luban.OnCompressListener
|
|
|
+import java.io.File
|
|
|
|
|
|
/**
|
|
|
* 问诊单
|
|
@@ -23,6 +33,8 @@ class ConsultationSheetActivity :
|
|
|
BaseMVVMActivity<ActivityConsultationSheetBinding, ConsultationSheetViewModel>(),
|
|
|
View.OnTouchListener {
|
|
|
|
|
|
+ private val REQUEST_MEDICALRECORDS_CAMERA = 1
|
|
|
+ private val REQUEST_MEDICALRECORDS_IMG = 2
|
|
|
private val sickTimes = mutableListOf<String>()
|
|
|
private val sickTimeAdapter by lazy { SickTimeAdapter() }
|
|
|
|
|
@@ -44,6 +56,7 @@ class ConsultationSheetActivity :
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
backLayout.setOnTouchListener(this@ConsultationSheetActivity)
|
|
|
+ btnSubmit.setOnTouchListener(this@ConsultationSheetActivity)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -55,7 +68,7 @@ class ConsultationSheetActivity :
|
|
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
when (event.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
|
- if (v.id == R.id.backLayout) {
|
|
|
+ if (v.id == R.id.backLayout || v.id == R.id.btnSubmit) {
|
|
|
v.startAnimation(getScaleAnimation())
|
|
|
}
|
|
|
}
|
|
@@ -65,10 +78,20 @@ class ConsultationSheetActivity :
|
|
|
R.id.backLayout -> {
|
|
|
finish()
|
|
|
}
|
|
|
+ R.id.btnSubmit -> {
|
|
|
+ ImageSelector.builder()
|
|
|
+ .useCamera(true) // 设置是否使用拍照
|
|
|
+ .setSingle(false) //设置是否单选
|
|
|
+ .canPreview(true) //是否点击放大图片查看,,默认为true
|
|
|
+ .setMaxSelectCount(
|
|
|
+ 9
|
|
|
+ ) // 图片的最大选择数量,小于等于0时,不限数量。
|
|
|
+ .start(this, REQUEST_MEDICALRECORDS_CAMERA) // 打开相册
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
MotionEvent.ACTION_CANCEL -> {
|
|
|
- if (v.id == R.id.backLayout) {
|
|
|
+ if (v.id == R.id.backLayout || v.id == R.id.btnSubmit) {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
}
|
|
|
}
|
|
@@ -88,4 +111,58 @@ class ConsultationSheetActivity :
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data)
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ val images = data?.getStringArrayListExtra(ImageSelector.SELECT_RESULT)
|
|
|
+ images?.let {
|
|
|
+ withLs(it, "medicalrecords")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开启luban图片压缩
|
|
|
+ */
|
|
|
+ private fun withLs(photos: List<String>, selectType: String) {
|
|
|
+ Luban.with(this)
|
|
|
+ .load(photos)
|
|
|
+ .ignoreBy(100)
|
|
|
+ .setTargetDir(getPath())
|
|
|
+ .setFocusAlpha(false)
|
|
|
+ .filter { path -> !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")) }
|
|
|
+ .setCompressListener(
|
|
|
+ object : OnCompressListener {
|
|
|
+ override fun onStart() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onSuccess(file: File) {
|
|
|
+ val data = mutableListOf<String>()
|
|
|
+ data.add(file.path)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(e: Throwable) {
|
|
|
+ LogUtil.e("图片压缩失败:$e")
|
|
|
+ }
|
|
|
+ }).launch()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getPath(): String {
|
|
|
+ val path = Environment.getExternalStorageDirectory().path + "/xioaliu/image/"
|
|
|
+ val file = File(path)
|
|
|
+ return if (file.mkdirs()) {
|
|
|
+ path
|
|
|
+ } else path
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onDestroy() {
|
|
|
+ val path = getPath()
|
|
|
+ if (path.isNullOrEmpty().not()) {
|
|
|
+ CommonUtils.deleteDirectory(path)
|
|
|
+ }
|
|
|
+ super.onDestroy()
|
|
|
+ }
|
|
|
}
|