|
|
@@ -8,6 +8,7 @@ import android.text.TextUtils
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import android.widget.ImageView
|
|
|
+import android.widget.LinearLayout
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
@@ -25,6 +26,7 @@ import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.GlideImgUtil
|
|
|
import com.yingyangfly.baselib.utils.LogUtil
|
|
|
+import com.yingyangfly.baselib.utils.img.ImgUtil
|
|
|
import top.zibin.luban.Luban
|
|
|
import top.zibin.luban.OnCompressListener
|
|
|
import java.io.File
|
|
|
@@ -67,7 +69,7 @@ class ConsultationSheetActivity :
|
|
|
private fun initImageRv() {
|
|
|
emptyUploadImgBean = UploadImgBean()
|
|
|
imageList.add(emptyUploadImgBean)
|
|
|
- binding.rvPic.layoutManager = object : GridLayoutManager(mContext, 4) {
|
|
|
+ binding.rvPic.layoutManager = object : GridLayoutManager(mContext, 5) {
|
|
|
override fun canScrollVertically(): Boolean {
|
|
|
return false
|
|
|
}
|
|
|
@@ -79,28 +81,36 @@ class ConsultationSheetActivity :
|
|
|
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()) {
|
|
|
+ if (bean.isEmpty()) {
|
|
|
+ ivAdd.visibility = View.VISIBLE
|
|
|
+ img.visibility = View.GONE
|
|
|
+ imgDelete.visibility = View.GONE
|
|
|
+ } else {
|
|
|
if (!bean.uploadFlag) {
|
|
|
- GlideImgUtil.loadImage(mContext, R.mipmap.icon_add_pic, img)
|
|
|
+ ImgUtil.loadImage(mContext, R.mipmap.icon_add_pic, img)
|
|
|
}
|
|
|
- if (bean.remotePath.isEmpty()) {
|
|
|
+ ivAdd.visibility = View.GONE
|
|
|
+ img.visibility = View.VISIBLE
|
|
|
+ imgDelete.visibility = View.VISIBLE
|
|
|
+ val params = img.layoutParams
|
|
|
+ params.height = params.width
|
|
|
+ if (bean.remotePath.isNullOrEmpty()) {
|
|
|
upLoadImg(i, img)
|
|
|
} else {
|
|
|
- GlideImgUtil.loadRoundImg(
|
|
|
- mContext,
|
|
|
- if (bean.localPaht.isEmpty()) bean.remotePath else bean.localPaht,
|
|
|
- img
|
|
|
- )
|
|
|
+ if (bean.localPaht.isEmpty()) {
|
|
|
+ ImgUtil.loadRoundImg(mContext, bean.remotePath, img)
|
|
|
+ } else {
|
|
|
+ ImgUtil.loadRoundImg(mContext, bean.localPaht, img)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
ivAdd.setOnSingleClickListener {
|
|
|
if (bean.isEmpty()) {
|
|
|
selectPic()
|
|
|
} else if (!bean.uploadFlag) {
|
|
|
-
|
|
|
+ ImgUtil.loadImage(mContext, R.mipmap.icon_add_pic, img)
|
|
|
+ upLoadImg(i, img)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -283,8 +293,30 @@ class ConsultationSheetActivity :
|
|
|
listFile.add(File(uploadBean.localPaht))
|
|
|
viewModel.uploadFile(listFile, position, fail = {
|
|
|
it.toast()
|
|
|
+ imageList[position].uploadFlag = false
|
|
|
+ ImgUtil.loadImg(
|
|
|
+ mContext,
|
|
|
+ "",
|
|
|
+ imgView,
|
|
|
+ R.mipmap.icon_add_pic,
|
|
|
+ R.mipmap.icon_imgreload
|
|
|
+ )
|
|
|
}, success = {
|
|
|
-
|
|
|
+ if (it.isNullOrEmpty().not()) {
|
|
|
+ uploadBean.remotePath = it!!
|
|
|
+ uploadBean.uploadFlag = true
|
|
|
+ imageList[position] = uploadBean
|
|
|
+ ImgUtil.loadRoundImg(mContext, uploadBean.localPaht, imgView)
|
|
|
+ } else {
|
|
|
+ imageList[position].uploadFlag = false
|
|
|
+ ImgUtil.loadImg(
|
|
|
+ mContext,
|
|
|
+ "",
|
|
|
+ imgView,
|
|
|
+ R.mipmap.icon_add_pic,
|
|
|
+ R.mipmap.icon_imgreload
|
|
|
+ )
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|