From 94ef6a00f46426a0fadbabb6e8629690c09dc02c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 21 Jun 2024 16:28:22 +0200 Subject: [PATCH] fix: crash when playing video without upload date --- .../main/java/com/github/libretube/api/obj/Streams.kt | 9 +++++---- .../com/github/libretube/services/DownloadService.kt | 2 +- .../com/github/libretube/ui/fragments/PlayerFragment.kt | 3 +-- .../com/github/libretube/ui/views/DescriptionLayout.kt | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/Streams.kt b/app/src/main/java/com/github/libretube/api/obj/Streams.kt index db3223b94..f56226916 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Streams.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Streams.kt @@ -19,7 +19,8 @@ data class Streams( @Serializable(SafeInstantSerializer::class) @SerialName("uploadDate") - val uploadTimestamp: Instant, + val uploadTimestamp: Instant?, + val uploaded: Long? = null, val uploader: String, val uploaderUrl: String, @@ -91,9 +92,9 @@ data class Streams( uploaderName = uploader, uploaderUrl = uploaderUrl, uploaderAvatar = uploaderAvatar, - uploadedDate = uploadTimestamp.toLocalDateTime(TimeZone.currentSystemDefault()).date - .toString(), - uploaded = uploadTimestamp.toEpochMilliseconds(), + uploadedDate = uploadTimestamp?.toLocalDateTime(TimeZone.currentSystemDefault())?.date + ?.toString(), + uploaded = uploaded ?: uploadTimestamp?.toEpochMilliseconds() ?: 0, duration = duration, views = views, uploaderVerified = uploaderVerified, diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index a431dbbdd..adef62d05 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -120,7 +120,7 @@ class DownloadService : LifecycleService() { streams.description, streams.uploader, streams.duration, - streams.uploadTimestamp.toLocalDateTime(TimeZone.currentSystemDefault()).date, + streams.uploadTimestamp?.toLocalDateTime(TimeZone.currentSystemDefault())?.date, thumbnailTargetPath ) Database.downloadDao().insertDownload(download) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 416c17201..aea578df8 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -681,7 +681,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { commentsViewModel.setCommentSheetExpand(null) updateResolutionOnFullscreenChange(true) - openOrCloseFullscreenDialog(true) binding.player.updateMarginsByFullscreenMode() @@ -691,7 +690,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { fun unsetFullscreen() { viewModel.isFullscreen.value = false - if (!PlayerHelper.autoFullscreenEnabled) { + if (!PlayerHelper.autoFullscreenEnabled && activity != null) { mainActivity.requestedOrientation = mainActivity.screenOrientationPref } diff --git a/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt b/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt index c1ccc7701..5eb8d4ea7 100644 --- a/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt +++ b/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt @@ -143,9 +143,10 @@ class DescriptionLayout( } private fun localizeDate(streams: Streams): String { - if (streams.livestream) return "" + if (streams.livestream || streams.uploadTimestamp == null) return "" val date = streams.uploadTimestamp.toLocalDateTime(TimeZone.currentSystemDefault()).date + return TextUtils.SEPARATOR + TextUtils.localizeDate(date) }