Skip to content

Commit

Permalink
🐛 修复节目单未刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed May 27, 2024
1 parent 9a5d488 commit 59fef0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
11 changes: 0 additions & 11 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,17 @@ class EpgRepository : FileCacheRepository("epg.json") {
refreshTimeThreshold: Int,
) = withContext(Dispatchers.Default) {
try {
val xmlJson = getOrRefresh({ lastModified, cacheData ->
if (epgXmlRepository.cacheFileLastModified() > lastModified)
return@getOrRefresh true

// if (!cacheData.isNullOrBlank()) {
// val epgList = Json.decodeFromString<List<Epg>>(cacheData)
// val oldHashCode = epgList.map { it.channel }.hashCode()
// return@getOrRefresh oldHashCode != filteredChannels.hashCode()
// }

// true
false
if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < refreshTimeThreshold) {
log.d("未到时间点,不刷新节目单")
return@withContext EpgList()
}

val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())

val xmlJson = getOrRefresh({ lastModified, _ ->
dateFormat.format(System.currentTimeMillis()) != dateFormat.format(lastModified)
}) {
val xmlString = epgXmlRepository.getEpgXml(xmlUrl, refreshTimeThreshold)
val xmlString = epgXmlRepository.getEpgXml(xmlUrl)
Json.encodeToString(parseFromXml(xmlString, filteredChannels).value)
}

Expand Down Expand Up @@ -154,20 +151,9 @@ private class EpgXmlRepository : FileCacheRepository("epg.xml") {
/**
* 获取xml
*/
suspend fun getEpgXml(url: String, refreshTimeThreshold: Int): String {
if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < refreshTimeThreshold) {
log.d("未到时间点,不刷新节目单")
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
}

val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())

return getOrRefresh({ lastModified, _ ->
dateFormat.format(System.currentTimeMillis()) != dateFormat.format(lastModified)
}) {
suspend fun getEpgXml(url: String): String {
return getOrRefresh(0) {
fetchXml(url)
}
}

fun cacheFileLastModified() = getCacheFile().lastModified()
}

0 comments on commit 59fef0e

Please sign in to comment.