fix: 修改message详情界面

This commit is contained in:
xiaoyan 2023-01-04 15:40:43 +08:00
parent 7f3560aa5c
commit 31d7918560
3 changed files with 196 additions and 18 deletions

View File

@ -11,9 +11,9 @@ import java.io.File
interface NavinfoVolvoService {
@POST("/navi/cardDelivery/insertCardByApp")
fun insertCardByApp(@Body insertData: MutableMap<String, String>)
suspend fun insertCardByApp(@Body insertData: Map<String, String>):DefaultResponse<String>
@POST("/navi/cardDelivery/updateCardByApp")
fun updateCardByApp(@Body updateData: MutableMap<String, String>)
suspend fun updateCardByApp(@Body updateData: Map<String, String>):DefaultResponse<String>
@POST("/navi/cardDelivery/queryCardListByApp")
fun queryCardListByApp(@Body queryData: MutableMap<String, String>)
@POST("/navi/cardDelivery/deleteCardByApp")
@ -22,5 +22,5 @@ interface NavinfoVolvoService {
@Multipart
suspend fun uploadAttachment(@Part attachmentFile: MultipartBody.Part):DefaultResponse<MutableMap<String, String>>
@POST("/img/download")
fun downLoadAttachment(@Body downloadData: MutableMap<String, String>):Call<DefaultResponse<MutableMap<String, String>>>
suspend fun downLoadAttachment(@Body downloadData: Map<String, String>):DefaultResponse<String>
}

View File

@ -28,8 +28,10 @@ import com.hjq.permissions.XXPermissions
import com.navinfo.volvo.R
import com.navinfo.volvo.RecorderLifecycleObserver
import com.navinfo.volvo.databinding.FragmentObtainMessageBinding
import com.navinfo.volvo.db.dao.entity.Attachment
import com.navinfo.volvo.db.dao.entity.AttachmentType
import com.navinfo.volvo.db.dao.entity.Message
import com.navinfo.volvo.http.NavinfoVolvoCall
import com.navinfo.volvo.ui.markRequiredInRed
import com.navinfo.volvo.utils.EasyMediaFile
import com.navinfo.volvo.utils.SystemConstant
@ -86,22 +88,37 @@ class ObtainMessageFragment: Fragment() {
.load(attachment.pathUrl)
.into(binding.imgMessageAttachment)
// 显示名称
binding.tvPhotoName.text = attachment.pathUrl.replace("\\", "/").substringAfterLast("/")
hasPhoto = true
// 如果当前attachment文件是本地文件开始尝试网络上传
if (!attachment.pathUrl.startsWith("http")) {
obtainMessageViewModel.uploadAttachment(File(attachment.pathUrl))
val str = attachment.pathUrl.replace("\\", "/")
if (!str.startsWith("http")) {
obtainMessageViewModel.uploadAttachment(File(attachment.pathUrl), attachment.attachmentType)
binding.tvPhotoName.text = str.substringAfterLast("/", "picture.jpg")
} else {
binding.tvPhotoName.text = str.substring(str.lastIndexOf("/"), str.indexOf("?"))
}
}
if (attachment.attachmentType == AttachmentType.AUDIO) {
binding.tvAudioName.text = attachment.pathUrl.replace("\\", "/").substringAfterLast("/")
hasAudio = true
// 如果当前attachment文件是本地文件开始尝试网络上传
val str = attachment.pathUrl.replace("\\", "/")
if (!str.startsWith("http")) {
obtainMessageViewModel.uploadAttachment(File(attachment.pathUrl), attachment.attachmentType)
binding.tvAudioName.text = str.substringAfterLast("/", "audio.m4a")
} else {
val str = attachment.pathUrl.replace("\\", "/")
binding.tvAudioName.text = str.substring(str.lastIndexOf("/"), str.indexOf("?"))
}
}
}
// 如果当前attachment不为空可以显示预览按钮
}
binding.layerPhotoResult.visibility = if (hasPhoto) VISIBLE else GONE
binding.layerGetPhoto.visibility = if (hasPhoto) GONE else VISIBLE
binding.imgMessageAttachment.visibility = if (hasPhoto) VISIBLE else GONE
binding.layerAudioResult.visibility = if (hasAudio) VISIBLE else GONE
binding.layerGetAudio.visibility = if (hasAudio) GONE else VISIBLE
}
@ -118,6 +135,10 @@ class ObtainMessageFragment: Fragment() {
obtainMessageViewModel.updateMessageTitle(it.toString())
}
binding.edtSendFrom.addTextChangedListener {
obtainMessageViewModel.updateMessageSendFrom(it.toString())
}
binding.imgPhotoDelete.setOnClickListener {
obtainMessageViewModel.updateMessagePic(null)
}
@ -285,6 +306,7 @@ class ObtainMessageFragment: Fragment() {
}
binding.btnObtainMessageConfirm.setOnClickListener {
var checkResult = true
// 检查当前输入数据
val messageData = obtainMessageViewModel.getMessageLiveData().value
if (messageData?.title?.isEmpty() == true) {
@ -292,10 +314,11 @@ class ObtainMessageFragment: Fragment() {
binding.ttTitle
val toolTip = ToolTip()
.withText("请输入问候信息")
.withColor(com.navinfo.volvo.R.color.purple_200)
.withShadow()
.withColor(R.color.white)
.withTextColor(R.color.black)
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.tiLayoutTitle)
checkResult = false
}
var hasPic = false
var hasAudio = false
@ -312,20 +335,22 @@ class ObtainMessageFragment: Fragment() {
binding.ttPic
val toolTip = ToolTip()
.withText("需要提供照片文件")
.withColor(com.navinfo.volvo.R.color.purple_200)
.withShadow()
.withColor(R.color.white)
.withTextColor(R.color.black)
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.tvUploadPic)
checkResult = false
}
if (!hasAudio) {
val toolTipRelativeLayout =
binding.ttAudio
val toolTip = ToolTip()
.withText("需要提供音频文件")
.withColor(com.navinfo.volvo.R.color.purple_200)
.withShadow()
.withColor(R.color.white)
.withTextColor(R.color.black)
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.tvUploadPic)
checkResult = false
}
if (messageData?.fromId?.isEmpty()==true) {
@ -333,20 +358,55 @@ class ObtainMessageFragment: Fragment() {
binding.ttSendFrom
val toolTip = ToolTip()
.withText("请输入您的名称")
.withColor(com.navinfo.volvo.R.color.purple_200)
.withShadow()
.withColor(R.color.white)
.withTextColor(R.color.black)
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.edtSendFrom)
checkResult = false
}
if (messageData?.toId?.isEmpty()==true) {
val toolTipRelativeLayout =
binding.ttSendTo
val toolTip = ToolTip()
.withText("请选择要发送的车辆")
.withColor(com.navinfo.volvo.R.color.purple_200)
.withShadow()
.withColor(R.color.white)
.withTextColor(R.color.black)
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.edtSendTo)
checkResult = false
}
if (checkResult) { // 检查通过
// 检查attachment是否为本地数据如果是本地则弹出对话框尝试上传
val localAttachmentList = mutableListOf<Attachment>()
for (attachment in messageData?.attachment!!) {
if (!attachment.pathUrl.startsWith("http")) {
localAttachmentList.add(attachment)
}
}
if (localAttachmentList.isNotEmpty()) {
MaterialAlertDialogBuilder(context!!)
.setTitle("提示")
.setMessage("当前照片及音频内容需首先上传,是否尝试上传?")
.setPositiveButton("确定", DialogInterface.OnClickListener { dialogInterface, i ->
dialogInterface.dismiss()
for (attachment in localAttachmentList) {
obtainMessageViewModel.uploadAttachment(File(attachment.pathUrl), attachment.attachmentType)
}
})
.show()
return@setOnClickListener
}
// 检查发送时间
// 开始网络提交数据
if (obtainMessageViewModel.getMessageLiveData().value?.netId!!.isEmpty()) { // 如果网络id为空则调用更新操作
obtainMessageViewModel.insertCardByApp()
} else {
obtainMessageViewModel.updateCardByApp()
}
}
}
}

View File

@ -91,7 +91,33 @@ class ObtainMessageViewModel: ViewModel() {
this.msgLiveData.postValue(this.msgLiveData.value)
}
fun uploadAttachment(attachmentFile: File) {
// 获取照片url
fun getImageAttachment(attachementList: List<Attachment>): Attachment? {
for (attachment in attachementList) {
if (attachment.attachmentType == AttachmentType.PIC) {
return attachment
}
}
return null
}
// 获取音频url
fun getAudioAttachment(attachementList: List<Attachment>): Attachment? {
for (attachment in attachementList) {
if (attachment.attachmentType == AttachmentType.AUDIO) {
return attachment
}
}
return null
}
// 获取发送时间
fun getSendDate(){
}
// 上传附件文件
fun uploadAttachment(attachmentFile: File, attachmentType: AttachmentType) {
// 启用协程调用网络请求
viewModelScope.launch {
try {
@ -102,6 +128,98 @@ class ObtainMessageViewModel: ViewModel() {
XLog.d(result.code)
if (result.code == 200) { // 请求成功
// 获取上传后的结果
val fileKey = result.data?.get("fileKey")
if (fileKey!=null) {
downloadAttachment(fileKey, attachmentType)
}
} else {
ToastUtils.showToast(result.message)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
XLog.d(e.message)
}
}
}
// 下载附件文件
fun downloadAttachment(fileKey: String, attachmentType: AttachmentType) {
// 启用协程调用网络请求
viewModelScope.launch {
try {
val downloadParam = mapOf("fileKey" to fileKey)
val result = NavinfoVolvoCall.getApi().downLoadAttachment(downloadParam)
XLog.d(result.code)
if (result.code == 200) { // 请求成功
// 获取上传后的结果
val imageUrl = result.data
if (imageUrl!=null) {
XLog.d("downloadAttachment-imageUrl:${imageUrl}")
// 获取到图片的网络地址
if (attachmentType == AttachmentType.PIC) {
updateMessagePic(imageUrl)
} else {
updateMessageAudio(imageUrl)
}
}
} else {
ToastUtils.showToast(result.message)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
XLog.d(e.message)
}
}
}
fun insertCardByApp() {
viewModelScope.launch {
try {
val message = msgLiveData.value
val insertData = mapOf(
"name" to message?.title,
"imageUrl" to getImageAttachment(message?.attachment!!)?.pathUrl,
"mediaUrl" to getAudioAttachment(message?.attachment!!)?.pathUrl,
"who" to message?.fromId,
"toWho" to message?.toId,
"sendDate" to message?.sendDate
)
val result = NavinfoVolvoCall.getApi().insertCardByApp(insertData as Map<String, String>)
XLog.d("insertCardByApp:${result.code}")
if (result.code == 200) { // 请求成功
// 获取上传后的结果
val netId = result.data
message.netId = netId!!
// 尝试保存数据到本地
} else {
ToastUtils.showToast(result.message)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
XLog.d(e.message)
}
}
}
fun updateCardByApp() {
viewModelScope.launch {
try {
val message = msgLiveData.value
val insertData = mapOf(
"name" to message?.title,
"imageUrl" to getImageAttachment(message?.attachment!!)?.pathUrl,
"mediaUrl" to getAudioAttachment(message?.attachment!!)?.pathUrl,
"who" to message?.fromId,
"toWho" to message?.toId,
"sendDate" to message?.sendDate
)
val result = NavinfoVolvoCall.getApi().updateCardByApp(insertData as Map<String, String>)
XLog.d("updateCardByApp:${result.code}")
if (result.code == 200) { // 请求成功
// 获取上传后的结果
val netId = result.data
message.netId = netId!!
// 尝试保存数据到本地
} else {
ToastUtils.showToast(result.message)
}