feat: 数据新增和修改接口调试

This commit is contained in:
xiaoyan 2023-01-04 17:37:28 +08:00
parent 47dc0c92b1
commit 88a54890c3
9 changed files with 59 additions and 32 deletions

3
.idea/gradle.xml generated
View File

@ -7,8 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$USER_HOME$/.gradle/wrapper/dists/gradle-7.2-all/260hg96vuh6ex27h9vo47iv4d/gradle-7.2" />
<option name="gradleJvm" value="JDK" />
<option name="gradleJvm" value="11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -4,10 +4,12 @@
<!-- 拍照 -->
<uses-permission
android:name="android.permission.CAMERA"
android:required="false" /> <!-- 网络请求 -->
android:required="false" />
<!-- 网络请求 -->
<uses-permission
android:name="android.permission.INTERNET"
android:required="false" /> <!-- 录音 -->
android:required="false" />
<!-- 录音 -->
<uses-permission
android:name="android.permission.RECORD_AUDIO"
android:required="false" /> <!-- 读写文件 -->
@ -53,5 +55,4 @@
android:value="" />
<meta-data android:name="ScopedStorage" android:value="true" />
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

View File

@ -2,6 +2,6 @@ package com.navinfo.volvo.http
class DefaultResponse<T> {
var code: Int = 0
var message: String = ""
var msg: String = ""
var data: T? = null
}

View File

@ -1,10 +1,7 @@
package com.navinfo.volvo.http
import com.navinfo.volvo.db.dao.entity.Attachment
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.io.File
class NavinfoVolvoCall {
companion object {

View File

@ -1,7 +1,5 @@
package com.navinfo.volvo.ui
import android.content.DialogInterface
import android.content.Intent
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
@ -11,10 +9,26 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.easytools.tools.FileUtils
import com.elvishew.xlog.LogConfiguration
import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.XLog
import com.elvishew.xlog.interceptor.BlacklistTagsFilterInterceptor
import com.elvishew.xlog.printer.AndroidPrinter
import com.elvishew.xlog.printer.ConsolePrinter
import com.elvishew.xlog.printer.Printer
import com.elvishew.xlog.printer.file.FilePrinter
import com.elvishew.xlog.printer.file.backup.NeverBackupStrategy
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.navinfo.volvo.BuildConfig
import com.navinfo.volvo.R
import com.navinfo.volvo.databinding.ActivityMainBinding
import com.navinfo.volvo.utils.SystemConstant
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint

View File

@ -13,7 +13,7 @@ import com.easytools.tools.DateUtils
import com.easytools.tools.FileUtils
import com.elvishew.xlog.XLog
import com.navinfo.volvo.databinding.FragmentCameraBinding
import com.navinfo.volvo.ui.message.ObtainMessageViewModel
import com.navinfo.volvo.ui.fragments.message.ObtainMessageViewModel
import com.navinfo.volvo.utils.SystemConstant
import com.otaliastudios.cameraview.CameraListener
import com.otaliastudios.cameraview.CameraView

View File

@ -17,6 +17,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.Navigation
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.easytools.tools.DateUtils
import com.easytools.tools.ToastUtils
import com.elvishew.xlog.XLog
@ -28,10 +29,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.model.Attachment
import com.navinfo.volvo.model.AttachmentType
import com.navinfo.volvo.model.Message
import com.navinfo.volvo.ui.markRequiredInRed
import com.navinfo.volvo.utils.EasyMediaFile
import com.navinfo.volvo.utils.SystemConstant
@ -75,7 +76,13 @@ class ObtainMessageFragment: Fragment() {
if(it.title?.isNotEmpty() == true)
binding.tvMessageTitle?.setText(it.title)
if (it.sendDate?.isNotEmpty() == true) {
binding.btnSendTime.text = it.sendDate
// 获取当前发送时间,如果早于当前时间,则显示现在
val sendDate = DateUtils.str2Date(it.sendDate, "yyyy-MM-dd HH:mm:ss")
if (sendDate<=Date()) {
binding.btnSendTime.text = "现在"
} else {
binding.btnSendTime.text = it.sendDate
}
}
var hasPhoto = false
var hasAudio = false
@ -86,6 +93,7 @@ class ObtainMessageFragment: Fragment() {
Glide.with(context!!)
.asBitmap().fitCenter()
.load(attachment.pathUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(binding.imgMessageAttachment)
// 显示名称
hasPhoto = true
@ -130,14 +138,20 @@ class ObtainMessageFragment: Fragment() {
fun initView() {
// 设置问候信息提示的红色星号
binding.tiLayoutTitle.markRequiredInRed()
binding.tvMessageTitle.addTextChangedListener {
obtainMessageViewModel.updateMessageTitle(it.toString())
// binding.tiLayoutTitle.markRequiredInRed()
// binding.tvMessageTitle.addTextChangedListener(afterTextChanged = {
// obtainMessageViewModel.updateMessageTitle(it.toString())
// })
binding.tvMessageTitle.setOnFocusChangeListener { view, b ->
if (!b) {
obtainMessageViewModel.updateMessageTitle(binding.tvMessageTitle.text.toString())
}
}
binding.edtSendFrom.addTextChangedListener {
binding.edtSendFrom.addTextChangedListener (afterTextChanged = {
obtainMessageViewModel.updateMessageSendFrom(it.toString())
}
})
binding.imgPhotoDelete.setOnClickListener {
obtainMessageViewModel.updateMessagePic(null)
@ -167,9 +181,9 @@ class ObtainMessageFragment: Fragment() {
override fun onClickListener(selectTime: String) {
val sendDate = DateUtils.str2Date(selectTime, "yyyy-MM-dd HH:mm")
if (sendDate <= Date()) {
obtainMessageViewModel.updateMessageSendTime("现在")
obtainMessageViewModel.updateMessageSendTime(DateUtils.date2Str(Date(), "yyyy-MM-dd HH:mm:ss"))
} else {
obtainMessageViewModel.updateMessageSendTime(selectTime)
obtainMessageViewModel.updateMessageSendTime(DateUtils.date2Str(sendDate, "yyyy-MM-dd HH:mm:ss"))
}
}

View File

@ -3,12 +3,13 @@ package com.navinfo.volvo.ui.fragments.message
import androidx.lifecycle.*
import com.easytools.tools.ToastUtils
import com.elvishew.xlog.XLog
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.model.Attachment
import com.navinfo.volvo.model.AttachmentType
import com.navinfo.volvo.model.Message
import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
@ -122,7 +123,7 @@ class ObtainMessageViewModel: ViewModel() {
viewModelScope.launch {
try {
val requestFile: RequestBody =
RequestBody.create(MediaType.parse("multipart/form-data"), attachmentFile)
RequestBody.create("multipart/form-data".toMediaTypeOrNull(), attachmentFile)
val body = MultipartBody.Part.createFormData("picture", attachmentFile.getName(), requestFile)
val result = NavinfoVolvoCall.getApi().uploadAttachment(body)
XLog.d(result.code)
@ -133,7 +134,7 @@ class ObtainMessageViewModel: ViewModel() {
downloadAttachment(fileKey, attachmentType)
}
} else {
ToastUtils.showToast(result.message)
ToastUtils.showToast(result.msg)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
@ -163,7 +164,7 @@ class ObtainMessageViewModel: ViewModel() {
}
}
} else {
ToastUtils.showToast(result.message)
ToastUtils.showToast(result.msg)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
@ -192,7 +193,7 @@ class ObtainMessageViewModel: ViewModel() {
message.netId = netId!!
// 尝试保存数据到本地
} else {
ToastUtils.showToast(result.message)
ToastUtils.showToast(result.msg)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)
@ -206,6 +207,7 @@ class ObtainMessageViewModel: ViewModel() {
try {
val message = msgLiveData.value
val insertData = mapOf(
"id" to message?.netId,
"name" to message?.title,
"imageUrl" to getImageAttachment(message?.attachment!!)?.pathUrl,
"mediaUrl" to getAudioAttachment(message?.attachment!!)?.pathUrl,
@ -221,7 +223,7 @@ class ObtainMessageViewModel: ViewModel() {
message.netId = netId!!
// 尝试保存数据到本地
} else {
ToastUtils.showToast(result.message)
ToastUtils.showToast(result.msg)
}
} catch (e: Exception) {
ToastUtils.showToast(e.message)

View File

@ -27,7 +27,7 @@
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
android:hint="请输入问候信息"
android:hint="问候信息"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"