desc:过滤文件不存在的视频

main
xiaowusky 2 years ago
parent 9422caaf71
commit 64a7cafe3f

@ -9,7 +9,9 @@ import com.common.commonlib.db.entity.Warning
import com.yinuo.safetywatcher.watcher.utils.LztekUtil
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import java.io.File
@OptIn(DelicateCoroutinesApi::class)
class App : CommonApplication() {
@ -28,6 +30,8 @@ class App : CommonApplication() {
private fun tryFixDbData() {
GlobalScope.launch {
// 修复告警数据
async {
val warningDao = DBUtils.warningDao()
val warningList = warningDao.queryWarningsNoEndTime()
warningList?.apply {
@ -36,11 +40,25 @@ class App : CommonApplication() {
}
warningDao.updateAll(warningList)
}
}.await()
// 修复视频数据
async {
val videoDao = DBUtils.videoDao()
val videoList = videoDao.getAll()
videoList.apply {
forEach { video ->
if (!File(video.path).exists()) {
videoDao.delete(video)
}
}
}
}.await()
}
}
private suspend fun tryAssignment(warningDao: WarningDao, warning: Warning): Long {
val latest = warningDao.findLatestByName(warning.gasName)
return latest?.endTime ?: System.currentTimeMillis()
return if (latest?.endTime!! > 0L) latest?.endTime else System.currentTimeMillis()
}
}

@ -101,13 +101,12 @@ class HistoryVideoActivity : BaseActivity() {
val videos = videoDao.getAllByTime(startTime, endTime)
launch(Dispatchers.Main) {
val sortList = mutableListOf<Video>()
sortList.apply {
addAll(videos)
sortWith { o1, o2 ->
var sortList = mutableListOf<Video>()
sortList.addAll(videos)
sortList = sortList.filter { File(it.path).exists() } as MutableList<Video>
sortList.sortWith { o1, o2 ->
(o2.time - o1.time).toInt()
}
}
mAdapter.setData(sortList)
}
}

@ -15,6 +15,7 @@ object LztekUtil {
fun setObject(value: Lztek) {
mLztek = value
mLztek?.hideNavigationBar()
}
fun getLztek(): Lztek? {

Loading…
Cancel
Save