fix: 增加图片预览
This commit is contained in:
@@ -2,6 +2,7 @@ package com.navinfo.volvo.ui.fragments.message
|
|||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -21,9 +22,11 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
import com.crazylegend.audiopicker.pickers.SingleAudioPicker
|
||||||
import com.easytools.tools.DateUtils
|
import com.easytools.tools.DateUtils
|
||||||
import com.easytools.tools.DeviceUtils
|
import com.easytools.tools.DeviceUtils
|
||||||
import com.easytools.tools.DisplayUtils
|
import com.easytools.tools.DisplayUtils
|
||||||
|
import com.easytools.tools.FileIOUtils
|
||||||
import com.easytools.tools.FileUtils
|
import com.easytools.tools.FileUtils
|
||||||
import com.easytools.tools.ResourceUtils
|
import com.easytools.tools.ResourceUtils
|
||||||
import com.easytools.tools.ToastUtils
|
import com.easytools.tools.ToastUtils
|
||||||
@@ -45,11 +48,14 @@ import com.navinfo.volvo.util.PhotoLoader
|
|||||||
import com.navinfo.volvo.utils.EasyMediaFile
|
import com.navinfo.volvo.utils.EasyMediaFile
|
||||||
import com.navinfo.volvo.utils.SystemConstant
|
import com.navinfo.volvo.utils.SystemConstant
|
||||||
import com.nhaarman.supertooltips.ToolTip
|
import com.nhaarman.supertooltips.ToolTip
|
||||||
|
import com.robertlevonyan.components.picker.*
|
||||||
import indi.liyi.viewer.Utils
|
import indi.liyi.viewer.Utils
|
||||||
import indi.liyi.viewer.ViewData
|
import indi.liyi.viewer.ViewData
|
||||||
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
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@@ -145,7 +151,7 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
|
|
||||||
binding.layerAudioResult.visibility = if (hasAudio) VISIBLE else GONE
|
binding.layerAudioResult.visibility = if (hasAudio) VISIBLE else GONE
|
||||||
binding.layerGetAudio.visibility = if (hasAudio) GONE else VISIBLE
|
binding.layerGetAudio.visibility = if (hasAudio) GONE else VISIBLE
|
||||||
binding.llAudioPlay.visibility = if (hasAudio) VISIBLE else GONE
|
// binding.llAudioPlay.visibility = if (hasAudio) VISIBLE else GONE
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
lifecycle.addObserver(recorderLifecycleObserver)
|
lifecycle.addObserver(recorderLifecycleObserver)
|
||||||
@@ -240,6 +246,17 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
// 用户选择录音文件
|
// 用户选择录音文件
|
||||||
binding.btnSelectSound.setOnClickListener {
|
binding.btnSelectSound.setOnClickListener {
|
||||||
photoHelper.setCrop(false).selectAudio(activity!!)
|
photoHelper.setCrop(false).selectAudio(activity!!)
|
||||||
|
// SingleAudioPicker.showPicker(context!!) {
|
||||||
|
// val audioFile = File(it.contentUri.path)
|
||||||
|
// ToastUtils.showToast(audioFile.absolutePath)
|
||||||
|
// if (!audioFile.parentFile.parentFile.absolutePath.equals(SystemConstant.SoundFolder)) {
|
||||||
|
// val copyResult = FileIOUtils.writeFileFromIS(File(SystemConstant.SoundFolder, audioFile.name), FileInputStream(audioFile))
|
||||||
|
// XLog.e("拷贝结果:"+copyResult)
|
||||||
|
// obtainMessageViewModel.updateMessageAudio(File(SystemConstant.SoundFolder, audioFile.name).absolutePath)
|
||||||
|
// } else {
|
||||||
|
// obtainMessageViewModel.updateMessageAudio(audioFile.absolutePath)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnStartRecord.setOnTouchListener { view, motionEvent ->
|
binding.btnStartRecord.setOnTouchListener { view, motionEvent ->
|
||||||
@@ -315,7 +332,8 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
}
|
}
|
||||||
// 如果当前文件不在camera缓存文件夹下,则移动该文件
|
// 如果当前文件不在camera缓存文件夹下,则移动该文件
|
||||||
if (!file!!.parentFile.absolutePath.equals(SystemConstant.CameraFolder)) {
|
if (!file!!.parentFile.absolutePath.equals(SystemConstant.CameraFolder)) {
|
||||||
FileUtils.renameFile(file.absolutePath, File(SystemConstant.CameraFolder, fileName).absolutePath)
|
val copyResult = FileIOUtils.writeFileFromIS(File(SystemConstant.CameraFolder, fileName), FileInputStream(file))
|
||||||
|
XLog.e("拷贝结果:"+copyResult)
|
||||||
// 跳转回原Fragment,展示拍摄的照片
|
// 跳转回原Fragment,展示拍摄的照片
|
||||||
ViewModelProvider(requireActivity()).get(ObtainMessageViewModel::class.java).updateMessagePic(File(SystemConstant.CameraFolder, fileName).absolutePath)
|
ViewModelProvider(requireActivity()).get(ObtainMessageViewModel::class.java).updateMessagePic(File(SystemConstant.CameraFolder, fileName).absolutePath)
|
||||||
} else {
|
} else {
|
||||||
@@ -331,7 +349,8 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
} else if (fileName.endsWith(".mp3")||fileName.endsWith(".wav")||fileName.endsWith(".amr")||fileName.endsWith(".m4a")) {
|
} else if (fileName.endsWith(".mp3")||fileName.endsWith(".wav")||fileName.endsWith(".amr")||fileName.endsWith(".m4a")) {
|
||||||
ToastUtils.showToast(it.absolutePath)
|
ToastUtils.showToast(it.absolutePath)
|
||||||
if (!it.parentFile.parentFile.absolutePath.equals(SystemConstant.SoundFolder)) {
|
if (!it.parentFile.parentFile.absolutePath.equals(SystemConstant.SoundFolder)) {
|
||||||
FileUtils.renameFile(it.absolutePath, File(SystemConstant.SoundFolder, fileName).absolutePath)
|
val copyResult = FileIOUtils.writeFileFromIS(File(SystemConstant.SoundFolder, fileName), FileInputStream(it))
|
||||||
|
XLog.e("拷贝结果:"+copyResult)
|
||||||
obtainMessageViewModel.updateMessageAudio(File(SystemConstant.SoundFolder, fileName).absolutePath)
|
obtainMessageViewModel.updateMessageAudio(File(SystemConstant.SoundFolder, fileName).absolutePath)
|
||||||
} else {
|
} else {
|
||||||
obtainMessageViewModel.updateMessageAudio(it.absolutePath)
|
obtainMessageViewModel.updateMessageAudio(it.absolutePath)
|
||||||
@@ -344,7 +363,8 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
ToastUtils.showToast(it.message)
|
ToastUtils.showToast(it.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.voicePlayerView.setOnClickListener {
|
binding.tvAudioName.setOnClickListener {
|
||||||
|
binding.llAudioPlay.visibility = if (binding.llAudioPlay.visibility == VISIBLE) GONE else VISIBLE
|
||||||
// 判断当前播放的文件是否在缓存文件夹内,如果不在首先下载该文件
|
// 判断当前播放的文件是否在缓存文件夹内,如果不在首先下载该文件
|
||||||
val fileUrl = obtainMessageViewModel.getMessageLiveData().value!!.mediaUrl!!
|
val fileUrl = obtainMessageViewModel.getMessageLiveData().value!!.mediaUrl!!
|
||||||
val localFile = obtainMessageViewModel.getLocalFileFromNetUrl(fileUrl, AttachmentType.AUDIO)
|
val localFile = obtainMessageViewModel.getLocalFileFromNetUrl(fileUrl, AttachmentType.AUDIO)
|
||||||
@@ -511,10 +531,6 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
.showIndex(true) // 是否显示图片索引,默认为true
|
.showIndex(true) // 是否显示图片索引,默认为true
|
||||||
.watch(0) // 开启浏览
|
.watch(0) // 开启浏览
|
||||||
|
|
||||||
}
|
|
||||||
// 点击音频名称
|
|
||||||
binding.tvAudioName.setOnClickListener {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,4 +579,6 @@ class ObtainMessageFragment: Fragment() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
lifecycle.removeObserver(recorderLifecycleObserver)
|
lifecycle.removeObserver(recorderLifecycleObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.navinfo.volvo.ui.fragments.message
|
package com.navinfo.volvo.ui.fragments.message
|
||||||
|
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
|
import com.easytools.tools.FileIOUtils
|
||||||
import com.easytools.tools.FileUtils
|
import com.easytools.tools.FileUtils
|
||||||
import com.easytools.tools.ToastUtils
|
import com.easytools.tools.ToastUtils
|
||||||
import com.elvishew.xlog.XLog
|
import com.elvishew.xlog.XLog
|
||||||
@@ -19,6 +20,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@@ -140,13 +142,15 @@ class ObtainMessageViewModel: ViewModel() {
|
|||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
FileUtils.deleteFile(destFile)
|
FileUtils.deleteFile(destFile)
|
||||||
}
|
}
|
||||||
FileUtils.renameFile(attachmentFile.absolutePath, destFile.absolutePath)
|
val copyResult = FileIOUtils.writeFileFromIS(destFile, FileInputStream(attachmentFile))
|
||||||
|
XLog.e("拷贝结果:"+copyResult)
|
||||||
} else {
|
} else {
|
||||||
val destFile = File(SystemConstant.SoundFolder, newFileName)
|
val destFile = File(SystemConstant.SoundFolder, newFileName)
|
||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
FileUtils.deleteFile(destFile)
|
FileUtils.deleteFile(destFile)
|
||||||
}
|
}
|
||||||
FileUtils.renameFile(attachmentFile.absolutePath, destFile.absolutePath)
|
val copyResult = FileIOUtils.writeFileFromIS(destFile, FileInputStream(attachmentFile))
|
||||||
|
XLog.e("拷贝结果:"+copyResult)
|
||||||
}
|
}
|
||||||
if (fileKey!=null) {
|
if (fileKey!=null) {
|
||||||
downloadAttachment(fileKey, attachmentType)
|
downloadAttachment(fileKey, attachmentType)
|
||||||
@@ -234,6 +238,7 @@ class ObtainMessageViewModel: ViewModel() {
|
|||||||
// 获取上传后的结果
|
// 获取上传后的结果
|
||||||
val netId = result.data
|
val netId = result.data
|
||||||
message?.id = netId!!.toLong()
|
message?.id = netId!!.toLong()
|
||||||
|
ToastUtils.showToast("保存成功")
|
||||||
// TODO 尝试更新本地数据
|
// TODO 尝试更新本地数据
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -262,9 +267,8 @@ class ObtainMessageViewModel: ViewModel() {
|
|||||||
val result = NavinfoVolvoCall.getApi().updateCardByApp(updateData as Map<String, String>)
|
val result = NavinfoVolvoCall.getApi().updateCardByApp(updateData as Map<String, String>)
|
||||||
XLog.d("updateCardByApp:${result.code}")
|
XLog.d("updateCardByApp:${result.code}")
|
||||||
if (result.code == 200) { // 请求成功
|
if (result.code == 200) { // 请求成功
|
||||||
// 获取上传后的结果
|
// 数据更新成功
|
||||||
val netId = result.data
|
ToastUtils.showToast("更新成功")
|
||||||
message?.id = netId!!.toLong()
|
|
||||||
// 尝试保存数据到本地
|
// 尝试保存数据到本地
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToast(result.msg)
|
ToastUtils.showToast(result.msg)
|
||||||
@@ -280,15 +284,19 @@ class ObtainMessageViewModel: ViewModel() {
|
|||||||
* 根据网络地址获取本地的缓存文件路径
|
* 根据网络地址获取本地的缓存文件路径
|
||||||
* */
|
* */
|
||||||
fun getLocalFileFromNetUrl(url: String, attachmentType: AttachmentType):File {
|
fun getLocalFileFromNetUrl(url: String, attachmentType: AttachmentType):File {
|
||||||
val folder = when(attachmentType) {
|
if (url.startsWith("http")) {
|
||||||
AttachmentType.PIC-> SystemConstant.CameraFolder
|
val folder = when(attachmentType) {
|
||||||
else -> SystemConstant.SoundFolder
|
AttachmentType.PIC-> SystemConstant.CameraFolder
|
||||||
}
|
else -> SystemConstant.SoundFolder
|
||||||
var name = if (url.contains("?")) {
|
}
|
||||||
url.substring(url.lastIndexOf("/")+1, url.indexOf("?"))
|
var name = if (url.contains("?")) {
|
||||||
|
url.substring(url.lastIndexOf("/")+1, url.indexOf("?"))
|
||||||
|
} else {
|
||||||
|
url.substringAfterLast("/")
|
||||||
|
}
|
||||||
|
return File(folder, name)
|
||||||
} else {
|
} else {
|
||||||
url.substringAfterLast("/")
|
return File(url)
|
||||||
}
|
}
|
||||||
return File(folder, name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ class EasyMediaFile {
|
|||||||
fun selectAudio(activity: Activity) {
|
fun selectAudio(activity: Activity) {
|
||||||
isCrop = false
|
isCrop = false
|
||||||
val intent = Intent(Intent.ACTION_PICK, null).apply {
|
val intent = Intent(Intent.ACTION_PICK, null).apply {
|
||||||
setDataAndType(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "audio/*")
|
setDataAndType(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "*/*")
|
||||||
}
|
}
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
selectFileInternal(intent, activity, 1)
|
selectFileInternal(intent, activity, 1)
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/tv_photo_name"
|
android:id="@+id/tv_photo_name"
|
||||||
android:textColor="@android:color/holo_blue_dark"
|
android:textColor="@android:color/holo_blue_dark"
|
||||||
|
android:padding="@dimen/default_widget_padding"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"></com.google.android.material.textview.MaterialTextView>
|
android:layout_weight="1"></com.google.android.material.textview.MaterialTextView>
|
||||||
@@ -208,6 +209,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@android:color/holo_blue_dark"
|
android:textColor="@android:color/holo_blue_dark"
|
||||||
|
android:padding="@dimen/default_widget_padding"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text=""></com.google.android.material.textview.MaterialTextView>
|
android:text=""></com.google.android.material.textview.MaterialTextView>
|
||||||
<Space
|
<Space
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
maven { url "https://maven.aliyun.com/repository/google" }
|
maven { url "https://maven.aliyun.com/repository/google" }
|
||||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
|
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/public' }
|
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||||
@@ -8,12 +9,12 @@ pluginManagement {
|
|||||||
jcenter()
|
jcenter()
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
maven { url "https://maven.aliyun.com/repository/google" }
|
maven { url "https://maven.aliyun.com/repository/google" }
|
||||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
|
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/public' }
|
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||||
@@ -21,7 +22,6 @@ dependencyResolutionManagement {
|
|||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
jcenter()
|
jcenter()
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootProject.name = "NavinfoVolvo"
|
rootProject.name = "NavinfoVolvo"
|
||||||
|
|||||||
Reference in New Issue
Block a user