Merge pull request #4899 from Bnyro/master

fix: date parsing crash due to YouTube AB testing
This commit is contained in:
Bnyro 2023-10-05 14:44:44 +02:00 committed by GitHub
commit b03d119a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View File

@ -2,18 +2,18 @@ package com.github.libretube.api.obj
import com.github.libretube.db.obj.DownloadItem
import com.github.libretube.enums.FileType
import com.github.libretube.extensions.toLocalDateSafe
import com.github.libretube.extensions.toMillis
import com.github.libretube.helpers.ProxyHelper
import com.github.libretube.parcelable.DownloadData
import kotlin.io.path.Path
import kotlinx.datetime.LocalDate
import kotlinx.serialization.Serializable
import kotlin.io.path.Path
@Serializable
data class Streams(
val title: String,
val description: String,
val uploadDate: LocalDate,
val uploadDate: String,
val uploader: String,
val uploaderUrl: String,
val uploaderAvatar: String? = null,
@ -84,8 +84,8 @@ data class Streams(
uploaderName = uploader,
uploaderUrl = uploaderUrl,
uploaderAvatar = uploaderAvatar,
uploadedDate = uploadDate.toString(),
uploaded = uploadDate.toMillis(),
uploadedDate = uploadDate,
uploaded = uploadDate.toLocalDateSafe().toMillis(),
duration = duration,
views = views,
uploaderVerified = uploaderVerified,

View File

@ -3,5 +3,8 @@ package com.github.libretube.extensions
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.atStartOfDayIn
import kotlinx.datetime.toLocalDate
fun LocalDate.toMillis() = this.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds()
fun String.toLocalDateSafe() = this.substring(0, 10).toLocalDate()

View File

@ -28,6 +28,7 @@ import com.github.libretube.enums.FileType
import com.github.libretube.extensions.formatAsFileSize
import com.github.libretube.extensions.getContentLength
import com.github.libretube.extensions.parcelableExtra
import com.github.libretube.extensions.toLocalDateSafe
import com.github.libretube.extensions.toastFromMainThread
import com.github.libretube.helpers.DownloadHelper
import com.github.libretube.helpers.DownloadHelper.getNotificationId
@ -115,7 +116,7 @@ class DownloadService : LifecycleService() {
streams.title,
streams.description,
streams.uploader,
streams.uploadDate,
streams.uploadDate.toLocalDateSafe(),
thumbnailTargetPath
)
Database.downloadDao().insertDownload(download)

View File

@ -78,6 +78,7 @@ import com.github.libretube.extensions.seekBy
import com.github.libretube.extensions.serializableExtra
import com.github.libretube.extensions.setMetadata
import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toLocalDateSafe
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.extensions.togglePlayPauseState
import com.github.libretube.extensions.updateParameters
@ -873,11 +874,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
private fun localizeDate(streams: Streams): String {
return if (!streams.livestream) {
TextUtils.SEPARATOR + TextUtils.localizeDate(streams.uploadDate)
} else {
""
}
if (streams.livestream) return ""
return TextUtils.SEPARATOR + TextUtils.localizeDate(streams.uploadDate.toLocalDateSafe())
}
@SuppressLint("SetTextI18n")