修改UI部分
This commit is contained in:
@@ -24,6 +24,11 @@ class Constant {
|
||||
*/
|
||||
lateinit var OFFLINE_MAP_PATH: String
|
||||
|
||||
/**
|
||||
* 下载目录
|
||||
*/
|
||||
lateinit var DOWNLOAD_PATH: String
|
||||
|
||||
/**
|
||||
* 服务器地址
|
||||
*/
|
||||
|
||||
@@ -104,13 +104,13 @@ class TaskDownloadScope(
|
||||
var randomAccessFile: RandomAccessFile? = null
|
||||
try {
|
||||
//创建离线地图 下载文件夹,.map文件夹的下一级
|
||||
val fileDir = File("${Constant.OFFLINE_MAP_PATH}download")
|
||||
val fileDir = File("${Constant.DOWNLOAD_PATH}download")
|
||||
if (!fileDir.exists()) {
|
||||
fileDir.mkdirs()
|
||||
}
|
||||
|
||||
val fileTemp =
|
||||
File("${Constant.OFFLINE_MAP_PATH}download/${taskBean.id}_${taskBean.dataVersion}")
|
||||
File("${Constant.DOWNLOAD_PATH}${taskBean.id}_${taskBean.dataVersion}")
|
||||
val startPosition = taskBean.currentSize
|
||||
//验证断点有效性
|
||||
if (startPosition < 0) throw IOException("jingo Start position less than zero")
|
||||
@@ -119,8 +119,13 @@ class TaskDownloadScope(
|
||||
url = taskBean.getDownLoadUrl()
|
||||
)
|
||||
val responseBody = response.body()
|
||||
|
||||
change(FileDownloadStatus.LOADING)
|
||||
responseBody ?: throw IOException("jingo ResponseBody is null")
|
||||
|
||||
if (startPosition == 0L) {
|
||||
taskBean.fileSize = responseBody.contentLength()
|
||||
}
|
||||
//写入文件
|
||||
randomAccessFile = RandomAccessFile(fileTemp, "rwd")
|
||||
randomAccessFile.seek(startPosition)
|
||||
@@ -144,7 +149,7 @@ class TaskDownloadScope(
|
||||
Log.e("jingo", "文件下载完成 ${taskBean.currentSize} == ${taskBean.fileSize}")
|
||||
if (taskBean.currentSize == taskBean.fileSize) {
|
||||
val res =
|
||||
fileTemp.renameTo(File("${Constant.OFFLINE_MAP_PATH}${taskBean.evaluationTaskName}.zip"))
|
||||
fileTemp.renameTo(File("${Constant.DOWNLOAD_PATH}${taskBean.evaluationTaskName}.zip"))
|
||||
Log.e("jingo", "文件下载完成 修改文件 $res")
|
||||
change(FileDownloadStatus.DONE)
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.navinfo.omqs.tools
|
||||
import android.content.Context
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.bean.OfflineMapCityBean
|
||||
import com.navinfo.omqs.bean.TaskBean
|
||||
import java.io.File
|
||||
|
||||
class FileManager {
|
||||
@@ -20,13 +21,14 @@ class FileManager {
|
||||
}
|
||||
|
||||
//初始化数据文件夹
|
||||
fun initRootDir(context:Context){
|
||||
fun initRootDir(context: Context) {
|
||||
// 在SD卡创建项目目录
|
||||
val sdCardPath = context.getExternalFilesDir(null)
|
||||
sdCardPath?.let {
|
||||
Constant.ROOT_PATH = sdCardPath.absolutePath
|
||||
Constant.MAP_PATH = Constant.ROOT_PATH + "/map/"
|
||||
Constant.OFFLINE_MAP_PATH = Constant.MAP_PATH + "offline/"
|
||||
Constant.DOWNLOAD_PATH = Constant.ROOT_PATH + "/download/"
|
||||
val file = File(Constant.MAP_PATH)
|
||||
if (!file.exists()) {
|
||||
file.mkdirs()
|
||||
@@ -37,7 +39,7 @@ class FileManager {
|
||||
with(File(Constant.DATA_PATH)) {
|
||||
if (!this.exists()) this.mkdirs()
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
Constant.DATA_PATH = Constant.ROOT_PATH + "/data/"
|
||||
}
|
||||
}
|
||||
@@ -102,5 +104,65 @@ class FileManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查离线地图文件
|
||||
*/
|
||||
suspend fun checkOMDBFileInfo(taskBean: TaskBean) {
|
||||
//访问离线地图文件夹
|
||||
val fileDir = File("${Constant.DOWNLOAD_PATH}")
|
||||
//如果连本地文件夹还没有,就不用修改任何数据了
|
||||
if (!fileDir.exists()) {
|
||||
return
|
||||
}
|
||||
//访问离线地图临时下载文件夹
|
||||
val fileTempDir = File(Constant.DOWNLOAD_PATH)
|
||||
//是否有一份.map文件了
|
||||
var mapFile: File? = null
|
||||
//文件夹里文件挨个访问
|
||||
for (item in fileDir.listFiles()) {
|
||||
//先找到对应的省市文件,例如:540000_西藏自治区_20230401195018.map",以id开头
|
||||
if (item.isFile && item.name.startsWith("${taskBean.id}_")) {
|
||||
//如果本地文件与从网络获取到版本号一致,表示这个文件已经下载完毕,不用处理了
|
||||
if (item.name == "${taskBean.id}_${taskBean.dataVersion}") {
|
||||
taskBean.status = FileDownloadStatus.DONE
|
||||
return
|
||||
}
|
||||
//文件存在,版本号不对应,留给下面流程处理
|
||||
mapFile = item
|
||||
break
|
||||
}
|
||||
}
|
||||
//临时下载文件夹
|
||||
if (fileTempDir.exists()) {
|
||||
for (item in fileTempDir.listFiles()) {
|
||||
//先找到对应的省市文件,例如:540000_20230401195018",以id开头
|
||||
if (item.isFile && item.name.startsWith("${taskBean.id}_")) {
|
||||
//如果本地文件与从网络获取到版本号一致,表示这个文件已经在下载列表中
|
||||
if (item.name == "${taskBean.id}_${taskBean.dataVersion}") {
|
||||
//如果这个临时文件的大小和下载大小是一致的,说明已经下载完了,但是在下载环节没有更名移动成功,需要重命名和移动文件夹
|
||||
if (item.length() == taskBean.fileSize) {
|
||||
//移动更名文件后删除旧数据,修改状态
|
||||
if (item.renameTo(File("${Constant.OFFLINE_MAP_PATH}${taskBean.evaluationTaskName}.zip"))) {
|
||||
//删除旧版本数据
|
||||
mapFile?.delete()
|
||||
taskBean.status = FileDownloadStatus.DONE
|
||||
return
|
||||
}
|
||||
} else { // 临时文件大小和目标不一致,说明下载了一半
|
||||
taskBean.status = FileDownloadStatus.PAUSE
|
||||
taskBean.currentSize = item.length()
|
||||
return
|
||||
}
|
||||
} else { //虽然省市id开头一致,但是版本号不一致,说明之前版本下载了一部分,现在要更新了,原来下载的文件直接删除
|
||||
taskBean.status = FileDownloadStatus.UPDATE
|
||||
item.delete()
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class MainViewModel @Inject constructor(
|
||||
private var niLocationList: MutableList<NiLocation> = ArrayList<NiLocation>()
|
||||
|
||||
init {
|
||||
mapController.layerManagerHandler.setOnQsRecordItemClickListener(object :
|
||||
mapController.markerHandle.setOnQsRecordItemClickListener(object :
|
||||
OnQsRecordItemClickListener {
|
||||
override fun onQsRecordList(list: MutableList<String>) {
|
||||
liveDataQsRecordIdList.value = list
|
||||
|
||||
@@ -212,7 +212,7 @@ class EvaluationResultViewModel @Inject constructor(
|
||||
it.copyToRealmOrUpdate(liveDataQsRecordBean.value)
|
||||
}
|
||||
// realm.close()
|
||||
mapController.layerManagerHandler.addOrUpdateQsRecordMark(liveDataQsRecordBean.value!!)
|
||||
mapController.markerHandle.addOrUpdateQsRecordMark(liveDataQsRecordBean.value!!)
|
||||
liveDataFinish.postValue(true)
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ class EvaluationResultViewModel @Inject constructor(
|
||||
objects?.deleteFromRealm()
|
||||
}
|
||||
// realm.close()
|
||||
mapController.layerManagerHandler.removeQsRecordMark(liveDataQsRecordBean.value!!)
|
||||
mapController.markerHandle.removeQsRecordMark(liveDataQsRecordBean.value!!)
|
||||
liveDataFinish.postValue(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.navinfo.omqs.ui.other.BaseViewHolder
|
||||
*使用 LifecycleRegistry 给 ViewHolder 分发生命周期(这里使用了这个)
|
||||
*/
|
||||
class TaskListAdapter(
|
||||
private val downloadManager: TaskDownloadManager, private val context: Context
|
||||
private val downloadManager: TaskDownloadManager
|
||||
) : BaseRecyclerViewAdapter<TaskBean>() {
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ class TaskListAdapter(
|
||||
binding.taskDownloadBtn.tag = position
|
||||
binding.taskDownloadBtn.setOnClickListener(downloadBtnClick)
|
||||
binding.taskName.text = taskBean.evaluationTaskName
|
||||
binding.taskCityName.text = taskBean.cityName
|
||||
binding.taskDataVersion.text = "版本号:${taskBean.dataVersion}"
|
||||
// binding.offlineMapCitySize.text = cityBean.getFileSizeText()
|
||||
}
|
||||
|
||||
@@ -82,10 +84,12 @@ class TaskListAdapter(
|
||||
}
|
||||
|
||||
|
||||
private fun changeViews(binding: AdapterTaskListBinding, cityBean: TaskBean) {
|
||||
binding.taskProgress.progress =
|
||||
(cityBean.currentSize * 100 / cityBean.fileSize).toInt()
|
||||
when (cityBean.status) {
|
||||
private fun changeViews(binding: AdapterTaskListBinding, taskBean: TaskBean) {
|
||||
if (taskBean.fileSize > 0L) {
|
||||
binding.taskProgress.progress =
|
||||
(taskBean.currentSize * 100 / taskBean.fileSize).toInt()
|
||||
}
|
||||
when (taskBean.status) {
|
||||
FileDownloadStatus.NONE -> {
|
||||
if (binding.taskProgress.visibility == View.VISIBLE) binding.taskProgress.visibility =
|
||||
View.INVISIBLE
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.navinfo.omqs.databinding.FragmentTaskListBinding
|
||||
import com.navinfo.omqs.http.taskdownload.TaskDownloadManager
|
||||
@@ -22,7 +23,6 @@ class TaskListFragment : BaseFragment(){
|
||||
private val adapter: TaskListAdapter by lazy {
|
||||
TaskListAdapter(
|
||||
downloadManager,
|
||||
requireContext()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ class TaskListFragment : BaseFragment(){
|
||||
adapter.refreshData(it)
|
||||
}
|
||||
viewModel.getTaskList(requireContext())
|
||||
binding.taskBack.setOnClickListener{
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
@@ -52,8 +52,11 @@ class TaskListViewModel @Inject constructor(
|
||||
else -> {}
|
||||
}
|
||||
val objects = realm.where(TaskBean::class.java).findAll()
|
||||
liveDataTaskList.postValue(realm.copyFromRealm(objects))
|
||||
// realm.close()
|
||||
val taskList = realm.copyFromRealm(objects)
|
||||
for(item in taskList){
|
||||
FileManager.checkOMDBFileInfo(item)
|
||||
}
|
||||
liveDataTaskList.postValue(taskList)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user