修改离线地图下载的按钮状态

修改详细信息面板快捷进入新增数据界面
This commit is contained in:
squallzhjch
2023-07-27 17:15:51 +08:00
parent b9e3e4766e
commit 485c2b4b79
13 changed files with 243 additions and 162 deletions

View File

@@ -79,7 +79,6 @@ class OfflineMapDownloadManager(
} }
launchNext(id) launchNext(id)
} }
} }
/** /**

View File

@@ -34,7 +34,7 @@ class OfflineMapDownloadScope(
/** /**
* 管理观察者,同时只有一个就行了 * 管理观察者,同时只有一个就行了
*/ */
private val observer = Observer<Any> {} // private val observer = Observer<Any> {}
// private var lifecycleOwner: LifecycleOwner? = null // private var lifecycleOwner: LifecycleOwner? = null
/** /**
@@ -58,7 +58,13 @@ class OfflineMapDownloadScope(
*/ */
fun pause() { fun pause() {
downloadJob?.cancel("pause") downloadJob?.cancel("pause")
change(FileDownloadStatus.PAUSE) launch {
if (cityBean.fileSize == 0L) {
change(FileDownloadStatus.NONE)
} else {
change(FileDownloadStatus.PAUSE)
}
}
} }
/** /**
@@ -99,7 +105,6 @@ class OfflineMapDownloadScope(
* 添加下载任务观察者 * 添加下载任务观察者
*/ */
fun observer(owner: LifecycleOwner, ob: Observer<OfflineMapCityBean>) { fun observer(owner: LifecycleOwner, ob: Observer<OfflineMapCityBean>) {
removeObserver()
// this.lifecycleOwner = owner // this.lifecycleOwner = owner
downloadData.observe(owner, ob) downloadData.observe(owner, ob)
} }
@@ -167,11 +172,15 @@ class OfflineMapDownloadScope(
} }
} }
fun removeObserver() { fun removeObserver() {
downloadData.observeForever(observer) // downloadData.observeForever(observer)
// lifecycleOwner?.let { //// lifecycleOwner?.let {
downloadData.removeObserver(observer) // downloadData.removeObserver(observer)
// null //// null
//// }
// if (lifecycleOwner != null) {
// downloadData.removeObservers(lifecycleOwner!!)
// } // }
} }
} }

View File

@@ -248,10 +248,6 @@ class TaskDownloadScope(
//// null //// null
//// } //// }
if (lifecycleOwner != null) { if (lifecycleOwner != null) {
Log.e(
"jingo",
"移除的上一个监听者 ${lifecycleOwner.hashCode()} ${(lifecycleOwner as BaseViewHolder).tag}"
)
downloadData.removeObservers(lifecycleOwner!!) downloadData.removeObservers(lifecycleOwner!!)
} }
} }

View File

@@ -362,6 +362,7 @@ class LoginViewModel @Inject constructor(
.directory(userFolder) .directory(userFolder)
.name("OMQS.realm") .name("OMQS.realm")
.encryptionKey(password) .encryptionKey(password)
.allowQueriesOnUiThread(true)
// .modules(Realm.getDefaultModule(), MyRealmModule()) // .modules(Realm.getDefaultModule(), MyRealmModule())
.schemaVersion(2) .schemaVersion(2)
.build() .build()

View File

@@ -174,7 +174,7 @@ class MainViewModel @Inject constructor(
*/ */
private var bSelectPauseTrace = false private var bSelectPauseTrace = false
private var linkIdCache = "" var linkIdCache = ""
private var lastNiLocaion: NiLocation? = null private var lastNiLocaion: NiLocation? = null

View File

@@ -444,10 +444,11 @@ class EvaluationResultViewModel @Inject constructor(
*/ */
fun initData(id: String) { fun initData(id: String) {
Log.e("jingo", "捕捉到的要素 id = $id")
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.Main) {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val objects = realm.where(QsRecordBean::class.java).equalTo("id", id).findFirst() val objects = realm.where(QsRecordBean::class.java).equalTo("id", id).findFirst()
Log.e("jingo", "查询数据 id= $id") Log.e("jingo", "查询数据 id= $id")
if (objects != null) { if (objects != null) {
@@ -487,163 +488,163 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.value?.attachmentBeanList = it.attachmentBeanList liveDataQsRecordBean.value?.attachmentBeanList = it.attachmentBeanList
// 显示语音数据到界面 // 显示语音数据到界面
getChatMsgEntityList() getChatMsgEntityList()
} }
} else { } else {
liveDataToastMessage.postValue("数据读取失败") liveDataToastMessage.postValue("数据读取失败")
}
}
} }
}
}
/** /**
* 查询问题类型列表 * 查询问题类型列表
*/ */
private suspend fun getChatMsgEntityList() { private suspend fun getChatMsgEntityList() {
val chatMsgEntityList: MutableList<ChatMsgEntity> = ArrayList() val chatMsgEntityList: MutableList<ChatMsgEntity> = ArrayList()
liveDataQsRecordBean.value?.attachmentBeanList?.forEach { liveDataQsRecordBean.value?.attachmentBeanList?.forEach {
//1 录音 //1 录音
if (it.type == 1) { if (it.type == 1) {
val chatMsgEntity = ChatMsgEntity() val chatMsgEntity = ChatMsgEntity()
chatMsgEntity.name = it.name chatMsgEntity.name = it.name
chatMsgEntity.voiceUri = Constant.USER_DATA_ATTACHEMNT_PATH chatMsgEntity.voiceUri = Constant.USER_DATA_ATTACHEMNT_PATH
chatMsgEntityList.add(chatMsgEntity) chatMsgEntityList.add(chatMsgEntity)
}
} }
}
listDataChatMsgEntityList.postValue(chatMsgEntityList)
}
fun addChatMsgEntity(filePath: String) {
if (filePath.isNotEmpty()) {
var chatMsgEntityList: MutableList<ChatMsgEntity> = ArrayList()
if (listDataChatMsgEntityList.value?.isEmpty() == false) {
chatMsgEntityList = listDataChatMsgEntityList.value!!
}
val chatMsgEntity = ChatMsgEntity()
chatMsgEntity.name = filePath.replace(Constant.USER_DATA_ATTACHEMNT_PATH, "").toString()
chatMsgEntity.voiceUri = Constant.USER_DATA_ATTACHEMNT_PATH
chatMsgEntityList.add(chatMsgEntity)
var attachmentList: RealmList<AttachmentBean> = RealmList()
//赋值处理
if (liveDataQsRecordBean.value?.attachmentBeanList?.isEmpty() == false) {
attachmentList = liveDataQsRecordBean.value?.attachmentBeanList!!
}
val attachmentBean = AttachmentBean()
attachmentBean.name = chatMsgEntity.name!!
attachmentBean.type = 1
attachmentList.add(attachmentBean)
liveDataQsRecordBean.value?.attachmentBeanList = attachmentList
listDataChatMsgEntityList.postValue(chatMsgEntityList) listDataChatMsgEntityList.postValue(chatMsgEntityList)
} }
}
fun startSoundMetter(activity: Activity, v: View) { fun addChatMsgEntity(filePath: String) {
if (mSpeakMode == null) { if (filePath.isNotEmpty()) {
mSpeakMode = SpeakMode(activity) var chatMsgEntityList: MutableList<ChatMsgEntity> = ArrayList()
} if (listDataChatMsgEntityList.value?.isEmpty() == false) {
chatMsgEntityList = listDataChatMsgEntityList.value!!
}
val chatMsgEntity = ChatMsgEntity()
chatMsgEntity.name = filePath.replace(Constant.USER_DATA_ATTACHEMNT_PATH, "").toString()
chatMsgEntity.voiceUri = Constant.USER_DATA_ATTACHEMNT_PATH
chatMsgEntityList.add(chatMsgEntity)
//语音识别动画
if (pop == null) {
pop = PopupWindow()
pop!!.width = ViewGroup.LayoutParams.MATCH_PARENT
pop!!.height = ViewGroup.LayoutParams.WRAP_CONTENT
pop!!.setBackgroundDrawable(BitmapDrawable())
val view =
View.inflate(activity as Context, R.layout.cv_card_voice_rcd_hint_window, null)
pop!!.contentView = view
volume = view.findViewById(R.id.volume)
}
pop!!.update() var attachmentList: RealmList<AttachmentBean> = RealmList()
Constant.IS_VIDEO_SPEED = true //赋值处理
//录音动画 if (liveDataQsRecordBean.value?.attachmentBeanList?.isEmpty() == false) {
if (pop != null) { attachmentList = liveDataQsRecordBean.value?.attachmentBeanList!!
pop!!.showAtLocation(v, Gravity.CENTER, 0, 0)
}
volume!!.setBackgroundResource(R.drawable.pop_voice_img)
val animation = volume!!.background as AnimationDrawable
animation.start()
val name: String = DateTimeUtil.getTimeSSS().toString() + ".m4a"
if (mSoundMeter == null) {
mSoundMeter = SoundMeter()
}
mSoundMeter!!.setmListener(object : SoundMeter.OnSoundMeterListener {
@RequiresApi(Build.VERSION_CODES.Q)
override fun onSuccess(filePath: String?) {
if (!TextUtils.isEmpty(filePath) && File(filePath).exists()) {
if (File(filePath) == null || File(filePath).length() < 1600) {
ToastUtils.showLong("语音时间太短,无效!")
mSpeakMode!!.speakText("语音时间太短,无效")
stopSoundMeter()
return
}
} }
mSpeakMode!!.speakText("结束录音") val attachmentBean = AttachmentBean()
attachmentBean.name = chatMsgEntity.name!!
attachmentBean.type = 1
attachmentList.add(attachmentBean)
liveDataQsRecordBean.value?.attachmentBeanList = attachmentList
addChatMsgEntity(filePath!!) listDataChatMsgEntityList.postValue(chatMsgEntityList)
} }
}
@RequiresApi(api = Build.VERSION_CODES.Q)
override fun onfaild(message: String?) { fun startSoundMetter(activity: Activity, v: View) {
ToastUtils.showLong("录制失败!")
mSpeakMode!!.speakText("录制失败") if (mSpeakMode == null) {
stopSoundMeter() mSpeakMode = SpeakMode(activity)
} }
})
//语音识别动画
mSoundMeter!!.start(Constant.USER_DATA_ATTACHEMNT_PATH + name) if (pop == null) {
ToastUtils.showLong("开始录音") pop = PopupWindow()
mSpeakMode!!.speakText("开始录音") pop!!.width = ViewGroup.LayoutParams.MATCH_PARENT
} pop!!.height = ViewGroup.LayoutParams.WRAP_CONTENT
pop!!.setBackgroundDrawable(BitmapDrawable())
//停止语音录制 val view =
@RequiresApi(api = Build.VERSION_CODES.Q) View.inflate(activity as Context, R.layout.cv_card_voice_rcd_hint_window, null)
fun stopSoundMeter() { pop!!.contentView = view
//先重置标识,防止按钮抬起时触发语音结束 volume = view.findViewById(R.id.volume)
Constant.IS_VIDEO_SPEED = false }
if (mSoundMeter != null && mSoundMeter!!.isStartSound) {
mSoundMeter!!.stop() pop!!.update()
}
pop?.let { Constant.IS_VIDEO_SPEED = true
if (it.isShowing) { //录音动画
it.dismiss() if (pop != null) {
pop!!.showAtLocation(v, Gravity.CENTER, 0, 0)
}
volume!!.setBackgroundResource(R.drawable.pop_voice_img)
val animation = volume!!.background as AnimationDrawable
animation.start()
val name: String = DateTimeUtil.getTimeSSS().toString() + ".m4a"
if (mSoundMeter == null) {
mSoundMeter = SoundMeter()
}
mSoundMeter!!.setmListener(object : SoundMeter.OnSoundMeterListener {
@RequiresApi(Build.VERSION_CODES.Q)
override fun onSuccess(filePath: String?) {
if (!TextUtils.isEmpty(filePath) && File(filePath).exists()) {
if (File(filePath) == null || File(filePath).length() < 1600) {
ToastUtils.showLong("语音时间太短,无效!")
mSpeakMode!!.speakText("语音时间太短,无效")
stopSoundMeter()
return
}
}
mSpeakMode!!.speakText("结束录音")
addChatMsgEntity(filePath!!)
}
@RequiresApi(api = Build.VERSION_CODES.Q)
override fun onfaild(message: String?) {
ToastUtils.showLong("录制失败!")
mSpeakMode!!.speakText("录制失败")
stopSoundMeter()
}
})
mSoundMeter!!.start(Constant.USER_DATA_ATTACHEMNT_PATH + name)
ToastUtils.showLong("开始录音")
mSpeakMode!!.speakText("开始录音")
}
//停止语音录制
@RequiresApi(api = Build.VERSION_CODES.Q)
fun stopSoundMeter() {
//先重置标识,防止按钮抬起时触发语音结束
Constant.IS_VIDEO_SPEED = false
if (mSoundMeter != null && mSoundMeter!!.isStartSound) {
mSoundMeter!!.stop()
}
pop?.let {
if (it.isShowing) {
it.dismiss()
}
} }
} }
}
fun savePhoto(bitmap: Bitmap) { fun savePhoto(bitmap: Bitmap) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
// 创建一个名为 "MyApp" 的文件夹 // 创建一个名为 "MyApp" 的文件夹
val myAppDir = File(Constant.USER_DATA_ATTACHEMNT_PATH) val myAppDir = File(Constant.USER_DATA_ATTACHEMNT_PATH)
if (!myAppDir.exists()) myAppDir.mkdirs() // 确保文件夹已创建 if (!myAppDir.exists()) myAppDir.mkdirs() // 确保文件夹已创建
// 创建一个名为 fileName 的文件 // 创建一个名为 fileName 的文件
val file = File(myAppDir, "${UUID.randomUUID()}.png") val file = File(myAppDir, "${UUID.randomUUID()}.png")
file.createNewFile() // 创建文件 file.createNewFile() // 创建文件
// 将 Bitmap 压缩为 JPEG 格式,并将其写入文件中 // 将 Bitmap 压缩为 JPEG 格式,并将其写入文件中
val out = FileOutputStream(file) val out = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out) bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)
out.flush() out.flush()
out.close() out.close()
var picList = mutableListOf<String>() var picList = mutableListOf<String>()
if (liveDataPictureList.value == null) { if (liveDataPictureList.value == null) {
picList.add(file.absolutePath) picList.add(file.absolutePath)
} else { } else {
picList.addAll(liveDataPictureList.value!!) picList.addAll(liveDataPictureList.value!!)
picList.add(file.absolutePath) picList.add(file.absolutePath)
}
liveDataPictureList.postValue(picList)
} }
liveDataPictureList.postValue(picList)
}
} }
@@ -661,5 +662,5 @@ fun savePhoto(bitmap: Bitmap) {
} }
} }
} }
} }
} }

View File

@@ -5,6 +5,7 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.navinfo.omqs.R import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.AdapterOfflineMapCityBinding import com.navinfo.omqs.databinding.AdapterOfflineMapCityBinding
@@ -14,6 +15,7 @@ import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
import com.navinfo.omqs.ui.other.BaseViewHolder import com.navinfo.omqs.ui.other.BaseViewHolder
import com.navinfo.omqs.ui.other.OnLifecycleStateListener
import javax.inject.Inject import javax.inject.Inject
/** /**
@@ -68,7 +70,26 @@ class OfflineMapCityListAdapter(
changeViews(binding, cityBean) changeViews(binding, cityBean)
downloadManager.addTask(cityBean) downloadManager.addTask(cityBean)
downloadManager.observer(cityBean.id, holder, DownloadObserver(cityBean.id, holder))
holder.addObserver(object : OnLifecycleStateListener {
override fun onState(tag: String, state: Lifecycle.State) {
when (state) {
Lifecycle.State.STARTED -> {
downloadManager.observer(
cityBean.id,
holder,
DownloadObserver(cityBean.id, holder)
)
}
Lifecycle.State.DESTROYED -> {
downloadManager.removeObserver(cityBean.id)
}
else -> {}
}
}
})
binding.offlineMapDownloadBtn.tag = position binding.offlineMapDownloadBtn.tag = position
binding.offlineMapDownloadBtn.setOnClickListener(downloadBtnClick) binding.offlineMapDownloadBtn.setOnClickListener(downloadBtnClick)
binding.offlineMapCityName.text = cityBean.name binding.offlineMapCityName.text = cityBean.name

View File

@@ -51,6 +51,23 @@ class OfflineMapCityListFragment : Fragment() {
viewModel.cityListLiveData.observe(viewLifecycleOwner) { viewModel.cityListLiveData.observe(viewLifecycleOwner) {
adapter.refreshData(it) adapter.refreshData(it)
} }
}
override fun onStart() {
super.onStart()
}
override fun onStop() {
super.onStop()
}
override fun onPause() {
super.onPause()
}
override fun onResume() {
super.onResume()
viewModel.getCityList() viewModel.getCityList()
} }

View File

@@ -54,6 +54,18 @@ class OfflineMapStateListFragment : Fragment() {
} }
} }
override fun onStart() {
super.onStart()
}
override fun onStop() {
super.onStop()
}
override fun onPause() {
super.onPause()
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null

View File

@@ -29,12 +29,7 @@ class OfflineMapStateListViewModel @Inject constructor(
fun getCityList() { fun getCityList() {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val list = roomDatabase.getOfflineMapDao().getOfflineMapListWithOutNone() val list = roomDatabase.getOfflineMapDao().getOfflineMapListWithOutNone()
if (cityListLiveData.value != null) { cityListLiveData.postValue(list)
if (cityListLiveData.value!!.size != list.size)
cityListLiveData.postValue(list)
}else{
cityListLiveData.postValue(list)
}
} }
} }
} }

View File

@@ -5,8 +5,11 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.omqs.R import com.navinfo.omqs.R
import com.navinfo.omqs.bean.SignBean
import com.navinfo.omqs.databinding.FragmentSignInfoBinding import com.navinfo.omqs.databinding.FragmentSignInfoBinding
import com.navinfo.omqs.ui.activity.map.MainViewModel import com.navinfo.omqs.ui.activity.map.MainViewModel
import com.navinfo.omqs.ui.fragment.BaseFragment import com.navinfo.omqs.ui.fragment.BaseFragment
@@ -53,7 +56,7 @@ class SignMoreInfoFragment : BaseFragment() {
adapter.refreshData(SignUtil.getRoadNameList(it)) adapter.refreshData(SignUtil.getRoadNameList(it))
} }
//常规点限速 //常规点限速
4002->{ 4002 -> {
val adapter = ElectronicEyeInfoAdapter() val adapter = ElectronicEyeInfoAdapter()
binding.signInfoRecyclerview.adapter = adapter binding.signInfoRecyclerview.adapter = adapter
adapter.refreshData(SignUtil.getSpeedLimitMoreInfoText(it)) adapter.refreshData(SignUtil.getSpeedLimitMoreInfoText(it))
@@ -91,6 +94,33 @@ class SignMoreInfoFragment : BaseFragment() {
.commit() .commit()
} }
} }
binding.signInfoTitle.setOnClickListener {
activity?.run {
val rightController = findNavController(R.id.main_activity_right_fragment)
rightController.currentDestination?.let {
if (it.id == R.id.RightEmptyFragment) {
val bundle = Bundle()
val element = viewModel.liveDataSignMoreInfo.value
if (element != null) {
val signBean = SignBean(
iconId = SignUtil.getSignIcon(element),
iconText = SignUtil.getSignIconText(element),
linkId = element.properties[RenderEntity.Companion.LinkTable.linkPid]
?: "",
name = SignUtil.getSignNameText(element),
bottomRightText = SignUtil.getSignBottomRightText(element),
renderEntity = element,
isMoreInfo = SignUtil.isMoreInfo(element),
index = SignUtil.getRoadInfoIndex(element)
)
bundle.putParcelable("SignBean", signBean)
bundle.putBoolean("AutoSave", false)
rightController.navigate(R.id.EvaluationResultFragment, bundle)
}
}
}
}
}
} }
override fun onDestroyView() { override fun onDestroyView() {

View File

@@ -1,5 +1,6 @@
package com.navinfo.omqs.ui.other package com.navinfo.omqs.ui.other
import android.util.Log
import android.view.View import android.view.View
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner

View File

@@ -604,11 +604,10 @@ public final class NIMapView extends RelativeLayout {
BASE(0)/*底图图层组*/, BASE(0)/*底图图层组*/,
VECTOR_TILE(1)/*矢量瓦片组*/, VECTOR_TILE(1)/*矢量瓦片组*/,
VECTOR(2)/*高亮组*/, VECTOR(2)/*高亮组*/,
OPERATE_LINE(3)/*操作图层组*/, NAVIGATION(3)/*定位导航组*/,
OPERATE_MARKER(4)/*操作图层*/, LABEL(4)/*图标,文字图层*/,
NAVIGATION(5)/*定位导航组*/, OPERATE_LINE(5)/*操作图层组*/,
LABEL(6)/*图标,文字图层*/; OPERATE_MARKER(6)/*操作图层*/;
int groupIndex; int groupIndex;
LAYER_GROUPS(int groupIndex) { LAYER_GROUPS(int groupIndex) {