|
@@ -7,6 +7,10 @@ import android.os.Environment
|
|
|
import android.text.TextUtils
|
|
import android.text.TextUtils
|
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
|
|
+import android.widget.ImageView
|
|
|
|
|
+import android.widget.LinearLayout
|
|
|
|
|
+import android.widget.ProgressBar
|
|
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
@@ -14,13 +18,17 @@ import com.donkingliang.imageselector.utils.ImageSelector
|
|
|
import com.yingyang.healthconsultation.R
|
|
import com.yingyang.healthconsultation.R
|
|
|
import com.yingyang.healthconsultation.adapter.SickTimeAdapter
|
|
import com.yingyang.healthconsultation.adapter.SickTimeAdapter
|
|
|
import com.yingyang.healthconsultation.databinding.ActivityConsultationSheetBinding
|
|
import com.yingyang.healthconsultation.databinding.ActivityConsultationSheetBinding
|
|
|
|
|
+import com.yingyang.healthconsultation.dialog.SelectPicDialog
|
|
|
|
|
+import com.yingyang.healthconsultation.entity.UploadImgBean
|
|
|
import com.yingyang.healthconsultation.utils.CommonUtils
|
|
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.adapter.XBaseAdapter
|
|
|
|
|
+import com.yingyangfly.baselib.ext.*
|
|
|
import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
|
|
+import com.yingyangfly.baselib.utils.FileMultipartBuilder
|
|
|
|
|
+import com.yingyangfly.baselib.utils.GlideImgUtil
|
|
|
import com.yingyangfly.baselib.utils.LogUtil
|
|
import com.yingyangfly.baselib.utils.LogUtil
|
|
|
|
|
+import okhttp3.internal.notify
|
|
|
import top.zibin.luban.Luban
|
|
import top.zibin.luban.Luban
|
|
|
import top.zibin.luban.OnCompressListener
|
|
import top.zibin.luban.OnCompressListener
|
|
|
import java.io.File
|
|
import java.io.File
|
|
@@ -35,6 +43,10 @@ class ConsultationSheetActivity :
|
|
|
|
|
|
|
|
private val REQUEST_MEDICALRECORDS_CAMERA = 1
|
|
private val REQUEST_MEDICALRECORDS_CAMERA = 1
|
|
|
private val REQUEST_MEDICALRECORDS_IMG = 2
|
|
private val REQUEST_MEDICALRECORDS_IMG = 2
|
|
|
|
|
+ var imageList = mutableListOf<UploadImgBean>()
|
|
|
|
|
+ private lateinit var emptyUploadImgBean: UploadImgBean
|
|
|
|
|
+ private lateinit var imageAdapter: XBaseAdapter<UploadImgBean>
|
|
|
|
|
+
|
|
|
private val sickTimes = mutableListOf<String>()
|
|
private val sickTimes = mutableListOf<String>()
|
|
|
private val sickTimeAdapter by lazy { SickTimeAdapter() }
|
|
private val sickTimeAdapter by lazy { SickTimeAdapter() }
|
|
|
|
|
|
|
@@ -50,6 +62,91 @@ class ConsultationSheetActivity :
|
|
|
rvSickTime.adapter = sickTimeAdapter
|
|
rvSickTime.adapter = sickTimeAdapter
|
|
|
sickTimeAdapter.setData(sickTimes)
|
|
sickTimeAdapter.setData(sickTimes)
|
|
|
}
|
|
}
|
|
|
|
|
+ initImageRv()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化问诊单图片
|
|
|
|
|
+ */
|
|
|
|
|
+ private fun initImageRv() {
|
|
|
|
|
+ emptyUploadImgBean = UploadImgBean()
|
|
|
|
|
+ imageList.add(emptyUploadImgBean)
|
|
|
|
|
+ binding.rvPic.layoutManager = object : GridLayoutManager(mContext, 4) {
|
|
|
|
|
+ override fun canScrollVertically(): Boolean {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ imageAdapter = XBaseAdapter(
|
|
|
|
|
+ R.layout.item_image,
|
|
|
|
|
+ imageList
|
|
|
|
|
+ ) { view: View, bean: UploadImgBean, i: Int ->
|
|
|
|
|
+ val img = view.findViewById<ImageView>(R.id.img)
|
|
|
|
|
+ val ivAdd = view.findViewById<ImageView>(R.id.iv_add)
|
|
|
|
|
+ val imgDelete = view.findViewById<ImageView>(R.id.img_delete)
|
|
|
|
|
+ img.show(bean.isEmpty().not())
|
|
|
|
|
+ ivAdd.show(bean.isEmpty())
|
|
|
|
|
+ imgDelete.show(bean.isEmpty().not())
|
|
|
|
|
+ if (bean.isEmpty().not()) {
|
|
|
|
|
+ val params = img.layoutParams
|
|
|
|
|
+ params.height = params.width
|
|
|
|
|
+
|
|
|
|
|
+ if (!bean.uploadFlag) {
|
|
|
|
|
+ GlideImgUtil.loadImage(mContext, R.mipmap.icon_add_pic, img)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bean.remotePath.isEmpty()) {
|
|
|
|
|
+ upLoadImg(i, img)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ GlideImgUtil.loadRoundImg(
|
|
|
|
|
+ mContext,
|
|
|
|
|
+ if (bean.localPaht.isEmpty()) bean.remotePath else bean.localPaht,
|
|
|
|
|
+ img
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ivAdd.setOnSingleClickListener {
|
|
|
|
|
+ if (bean.isEmpty()) {
|
|
|
|
|
+ selectPic()
|
|
|
|
|
+ } else if (!bean.uploadFlag) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ binding.rvPic.adapter = imageAdapter
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 图片选择弹框
|
|
|
|
|
+ */
|
|
|
|
|
+ private fun selectPic() {
|
|
|
|
|
+ val dialog = SelectPicDialog()
|
|
|
|
|
+ dialog.onDialogClickListener = {
|
|
|
|
|
+ if (TextUtils.equals("album", it)) {
|
|
|
|
|
+ ImageSelector.builder()
|
|
|
|
|
+ .useCamera(false) // 设置是否使用拍照
|
|
|
|
|
+ .setSingle(false) //设置是否单选
|
|
|
|
|
+ .canPreview(true) //是否点击放大图片查看,,默认为true
|
|
|
|
|
+ .setMaxSelectCount(if (getImgLocalPaths().size > 0) 9 - getImgLocalPaths().size else 9) // 图片的最大选择数量,小于等于0时,不限数量
|
|
|
|
|
+ .start(this, REQUEST_MEDICALRECORDS_IMG) // 打开相册
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ImageSelector.builder()
|
|
|
|
|
+ .useCamera(true)
|
|
|
|
|
+ .onlyTakePhoto(true)
|
|
|
|
|
+ .setCrop(false)
|
|
|
|
|
+ .setSelected(getImgLocalPaths())
|
|
|
|
|
+ .start(this, REQUEST_MEDICALRECORDS_CAMERA)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ dialog.show(supportFragmentManager, "SelectPicDialog")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun getImgLocalPaths(): ArrayList<String> {
|
|
|
|
|
+ val localList = arrayListOf<String>()
|
|
|
|
|
+ imageList.forEach {
|
|
|
|
|
+ if (it.localPaht.isNullOrEmpty().not())
|
|
|
|
|
+ localList.add(it.localPaht)
|
|
|
|
|
+ }
|
|
|
|
|
+ return localList
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
@@ -79,14 +176,7 @@ class ConsultationSheetActivity :
|
|
|
finish()
|
|
finish()
|
|
|
}
|
|
}
|
|
|
R.id.btnSubmit -> {
|
|
R.id.btnSubmit -> {
|
|
|
- ImageSelector.builder()
|
|
|
|
|
- .useCamera(true) // 设置是否使用拍照
|
|
|
|
|
- .setSingle(false) //设置是否单选
|
|
|
|
|
- .canPreview(true) //是否点击放大图片查看,,默认为true
|
|
|
|
|
- .setMaxSelectCount(
|
|
|
|
|
- 9
|
|
|
|
|
- ) // 图片的最大选择数量,小于等于0时,不限数量。
|
|
|
|
|
- .start(this, REQUEST_MEDICALRECORDS_CAMERA) // 打开相册
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -115,9 +205,16 @@ class ConsultationSheetActivity :
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
- val images = data?.getStringArrayListExtra(ImageSelector.SELECT_RESULT)
|
|
|
|
|
- images?.let {
|
|
|
|
|
- withLs(it, "medicalrecords")
|
|
|
|
|
|
|
+ if (requestCode == REQUEST_MEDICALRECORDS_CAMERA) {//拍照
|
|
|
|
|
+ val images = data?.getStringArrayListExtra(ImageSelector.SELECT_RESULT)
|
|
|
|
|
+ images?.let {
|
|
|
|
|
+ withLs(it)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (requestCode == REQUEST_MEDICALRECORDS_IMG) {//选择图片
|
|
|
|
|
+ val images = data?.getStringArrayListExtra(ImageSelector.SELECT_RESULT)
|
|
|
|
|
+ images?.let {
|
|
|
|
|
+ withLs(it)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -125,7 +222,7 @@ class ConsultationSheetActivity :
|
|
|
/**
|
|
/**
|
|
|
* 开启luban图片压缩
|
|
* 开启luban图片压缩
|
|
|
*/
|
|
*/
|
|
|
- private fun withLs(photos: List<String>, selectType: String) {
|
|
|
|
|
|
|
+ private fun withLs(photos: List<String>) {
|
|
|
Luban.with(this)
|
|
Luban.with(this)
|
|
|
.load(photos)
|
|
.load(photos)
|
|
|
.ignoreBy(100)
|
|
.ignoreBy(100)
|
|
@@ -141,7 +238,7 @@ class ConsultationSheetActivity :
|
|
|
override fun onSuccess(file: File) {
|
|
override fun onSuccess(file: File) {
|
|
|
val data = mutableListOf<String>()
|
|
val data = mutableListOf<String>()
|
|
|
data.add(file.path)
|
|
data.add(file.path)
|
|
|
-
|
|
|
|
|
|
|
+ addImages(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onError(e: Throwable) {
|
|
override fun onError(e: Throwable) {
|
|
@@ -150,8 +247,24 @@ class ConsultationSheetActivity :
|
|
|
}).launch()
|
|
}).launch()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
+ fun addImages(data: List<String>) {
|
|
|
|
|
+ data.forEach {
|
|
|
|
|
+ val upload = UploadImgBean()
|
|
|
|
|
+ upload.localPaht = it
|
|
|
|
|
+ imageList.add(upload)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (imageList.isEmpty().not() && imageList.contains(emptyUploadImgBean)) {
|
|
|
|
|
+ imageList.remove(emptyUploadImgBean)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (imageList.size < 9) {
|
|
|
|
|
+ imageList.add(0, emptyUploadImgBean)
|
|
|
|
|
+ }
|
|
|
|
|
+ imageAdapter.notifyDataSetChanged()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private fun getPath(): String {
|
|
private fun getPath(): String {
|
|
|
- val path = Environment.getExternalStorageDirectory().path + "/xioaliu/image/"
|
|
|
|
|
|
|
+ val path = Environment.getExternalStorageDirectory().path + "/hcp/image/"
|
|
|
val file = File(path)
|
|
val file = File(path)
|
|
|
return if (file.mkdirs()) {
|
|
return if (file.mkdirs()) {
|
|
|
path
|
|
path
|
|
@@ -165,4 +278,22 @@ class ConsultationSheetActivity :
|
|
|
}
|
|
}
|
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 图片上传
|
|
|
|
|
+ */
|
|
|
|
|
+ private fun upLoadImg(position: Int, imgView: ImageView) {
|
|
|
|
|
+ if (imageList.isEmpty().not()) {
|
|
|
|
|
+ val uploadBean = imageList[position]
|
|
|
|
|
+ if (uploadBean.isEmpty().not()) {
|
|
|
|
|
+ val listFile = mutableListOf<File>()
|
|
|
|
|
+ listFile.add(File(uploadBean.localPaht))
|
|
|
|
|
+ viewModel.uploadFile(listFile, position, fail = {
|
|
|
|
|
+ it.toast()
|
|
|
|
|
+ }, success = {
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|