Merge pull request #4793 from Isira-Seneviratne/Stream_when

feat: Show upload time in stream notifications
This commit is contained in:
Isira Seneviratne 2023-09-17 19:29:01 +05:30 committed by GitHub
commit c5fcd56391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 14 additions and 19 deletions

View File

@ -16,7 +16,7 @@ data class ContentItem(
val isShort: Boolean? = null,
val uploaderVerified: Boolean? = null,
val uploaderName: String? = null,
val uploaded: Long? = null,
val uploaded: Long = 0,
val shortDescription: String? = null,
// Channel and Playlist attributes
val name: String? = null,

View File

@ -20,7 +20,7 @@ data class StreamItem(
val duration: Long? = null,
val views: Long? = null,
val uploaderVerified: Boolean? = null,
val uploaded: Long? = null,
val uploaded: Long = 0,
val shortDescription: String? = null,
val isShort: Boolean = false
) : Parcelable {

View File

@ -8,11 +8,11 @@ import com.github.libretube.db.obj.SearchHistoryItem
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.PreferenceHelper
import java.time.Instant
import java.time.ZoneId
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.datetime.toKotlinLocalDate
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
object DatabaseHelper {
private const val MAX_SEARCH_HISTORY_SIZE = 20
@ -28,12 +28,8 @@ object DatabaseHelper {
val watchHistoryItem = WatchHistoryItem(
videoId,
stream.title,
stream.uploaded?.let {
Instant.ofEpochMilli(it)
.atZone(ZoneId.systemDefault())
.toLocalDate()
.toKotlinLocalDate()
},
Instant.fromEpochMilliseconds(stream.uploaded)
.toLocalDateTime(TimeZone.currentSystemDefault()).date,
stream.uploaderName,
stream.uploaderUrl?.toID(),
stream.uploaderAvatar,

View File

@ -30,7 +30,6 @@ data class LocalPlaylistItem(
uploaderUrl = uploaderUrl,
uploaderAvatar = ProxyHelper.rewriteUrl(uploaderAvatar),
uploadedDate = uploadDate,
uploaded = null,
duration = duration
)
}

View File

@ -26,7 +26,7 @@ data class WatchHistoryItem(
title = title,
thumbnail = thumbnailUrl,
uploaderName = uploader,
uploaded = uploadDate?.toMillis(),
uploaded = uploadDate?.toMillis() ?: 0,
uploaderAvatar = uploaderAvatar,
uploaderUrl = uploaderUrl,
duration = duration

View File

@ -83,7 +83,7 @@ class SearchAdapter(
thumbnailDuration.setFormattedDuration(item.duration, item.isShort)
videoTitle.text = item.title
val viewsString = item.views.takeIf { it != -1L }?.formatShort().orEmpty()
val uploadDate = item.uploaded?.takeIf { it > 0 }?.let {
val uploadDate = item.uploaded.takeIf { it > 0 }?.let {
" ${TextUtils.SEPARATOR} ${TextUtils.formatRelativeDate(root.context, it)}"
}.orEmpty()
videoInfo.text = root.context.getString(

View File

@ -120,7 +120,7 @@ class VideosAdapter(
val fragmentManager = activity.supportFragmentManager
val uploadDate =
video.uploaded?.takeIf { it > 0 }?.let { TextUtils.formatRelativeDate(context, it) }
video.uploaded.takeIf { it > 0 }?.let { TextUtils.formatRelativeDate(context, it) }
// Trending layout
holder.trendingRowBinding?.apply {

View File

@ -308,9 +308,7 @@ class SubscriptionsFragment : Fragment() {
// add an "all caught up item"
if (selectedSortOrder == 0) {
val lastCheckedFeedTime = PreferenceHelper.getLastCheckedFeedTime()
val caughtUpIndex = feed.indexOfFirst {
(it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime
}
val caughtUpIndex = feed.indexOfFirst { it.uploaded / 1000 < lastCheckedFeedTime }
if (caughtUpIndex > 0) {
sortedFeed.add(
caughtUpIndex,

View File

@ -168,7 +168,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
private suspend fun createStreamNotification(
group: String,
stream: StreamItem
): Triple<Int, Long?, Notification> { // Notification ID, uploaded date and notification object
): Triple<Int, Long, Notification> { // Notification ID, uploaded date and notification object
val videoId = stream.url!!.toID()
val intent = Intent(applicationContext, MainActivity::class.java)
.setFlags(INTENT_FLAGS)
@ -192,6 +192,8 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
.bigPicture(thumbnail)
.bigLargeIcon(null as Bitmap?) // Hides the icon when expanding
)
.setWhen(stream.uploaded)
.setShowWhen(true)
return Triple(notificationId, stream.uploaded, notificationBuilder.build())
}