|
|
@@ -3,28 +3,41 @@ package com.adealink.weparty.setting.report.viewmodel
|
|
|
import androidx.lifecycle.LiveData
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import com.adealink.frame.base.Rlt
|
|
|
+import com.adealink.frame.base.fastLazy
|
|
|
import com.adealink.frame.mvvm.livedata.OnceMutableLiveData
|
|
|
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
|
|
|
+import com.adealink.weparty.App
|
|
|
+import com.adealink.weparty.image.EVIDENCE_IMAGE_MAX_HEIGHT
|
|
|
+import com.adealink.weparty.image.EVIDENCE_IMAGE_MAX_SIZE_KB
|
|
|
+import com.adealink.weparty.image.EVIDENCE_IMAGE_MAX_WIDTH
|
|
|
+import com.adealink.weparty.image.EVIDENCE_IMAGE_MIN_QUALITY
|
|
|
+import com.adealink.weparty.module.image.data.PhotoData
|
|
|
+import com.adealink.weparty.setting.datasource.remote.SettingHttpService
|
|
|
import com.adealink.weparty.setting.helpcenter.data.AddPictureItemData
|
|
|
import com.adealink.weparty.setting.helpcenter.data.BasePictureItemData
|
|
|
-import com.adealink.weparty.setting.helpcenter.data.PictureData
|
|
|
import com.adealink.weparty.setting.helpcenter.data.PictureItemData
|
|
|
+import com.adealink.weparty.setting.report.ReportReq
|
|
|
+import com.adealink.weparty.util.uploadPhotos
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
class ReportViewModel : BaseViewModel() {
|
|
|
|
|
|
- val pictureList = mutableListOf<PictureData>()
|
|
|
+ private val reportHttpService by fastLazy {
|
|
|
+ App.instance.networkService.getHttpService(SettingHttpService::class.java)
|
|
|
+ }
|
|
|
+
|
|
|
+ val pictureList = mutableListOf<PhotoData>()
|
|
|
|
|
|
val pictureItemListLD = MutableLiveData<List<BasePictureItemData>>()
|
|
|
|
|
|
fun addPicture(path: String?, uri: String?) {
|
|
|
viewModelScope.launch {
|
|
|
- pictureList.add(PictureData(path, uri))
|
|
|
+ pictureList.add(PhotoData(null, path, uri))
|
|
|
onPictureListChanged()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun removePicture(data: PictureData) {
|
|
|
+ fun removePicture(data: PhotoData) {
|
|
|
viewModelScope.launch {
|
|
|
pictureList.remove(data)
|
|
|
onPictureListChanged()
|
|
|
@@ -38,17 +51,52 @@ class ReportViewModel : BaseViewModel() {
|
|
|
PictureItemData(it)
|
|
|
}
|
|
|
)
|
|
|
- //小于9张图片,可以继续添加图片
|
|
|
- if (pictureList.size < 9) {
|
|
|
+ //小于6张图片,可以继续添加图片
|
|
|
+ if (pictureList.size < 6) {
|
|
|
itemList.add(AddPictureItemData)
|
|
|
}
|
|
|
pictureItemListLD.send(itemList)
|
|
|
}
|
|
|
|
|
|
- fun submit(): LiveData<Rlt<Any>> {
|
|
|
+ fun submit(
|
|
|
+ uid: String,
|
|
|
+ content: String?
|
|
|
+ ): LiveData<Rlt<Any>> {
|
|
|
val liveData = OnceMutableLiveData<Rlt<Any>>()
|
|
|
viewModelScope.launch {
|
|
|
- liveData.send(Rlt.Success(Any()))
|
|
|
+
|
|
|
+ val uploadImages = mutableListOf<PhotoData>()
|
|
|
+ pictureList.forEach { picture ->
|
|
|
+ if (picture.isLocal()) {
|
|
|
+ uploadImages.add(picture)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //上传证据
|
|
|
+ val uploadRlt = uploadPhotos(
|
|
|
+ uploadImages,
|
|
|
+ EVIDENCE_IMAGE_MAX_WIDTH,
|
|
|
+ EVIDENCE_IMAGE_MAX_HEIGHT,
|
|
|
+ EVIDENCE_IMAGE_MAX_SIZE_KB,
|
|
|
+ EVIDENCE_IMAGE_MIN_QUALITY
|
|
|
+ )
|
|
|
+ when (uploadRlt) {
|
|
|
+ is Rlt.Failed -> {
|
|
|
+ liveData.send(uploadRlt)
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
+
|
|
|
+ is Rlt.Success<List<PhotoData>> -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val rlt = reportHttpService.report(
|
|
|
+ ReportReq(
|
|
|
+ uid,
|
|
|
+ content ?: "",
|
|
|
+ pictureList.mapNotNull { it.url }
|
|
|
+ )
|
|
|
+ )
|
|
|
+ liveData.send(rlt)
|
|
|
}
|
|
|
return liveData
|
|
|
}
|