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 isShort: Boolean? = null,
val uploaderVerified: Boolean? = null, val uploaderVerified: Boolean? = null,
val uploaderName: String? = null, val uploaderName: String? = null,
val uploaded: Long? = null, val uploaded: Long = 0,
val shortDescription: String? = null, val shortDescription: String? = null,
// Channel and Playlist attributes // Channel and Playlist attributes
val name: String? = null, val name: String? = null,

View File

@ -20,7 +20,7 @@ data class StreamItem(
val duration: Long? = null, val duration: Long? = null,
val views: Long? = null, val views: Long? = null,
val uploaderVerified: Boolean? = null, val uploaderVerified: Boolean? = null,
val uploaded: Long? = null, val uploaded: Long = 0,
val shortDescription: String? = null, val shortDescription: String? = null,
val isShort: Boolean = false val isShort: Boolean = false
) : Parcelable { ) : 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.db.obj.WatchHistoryItem
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.PreferenceHelper
import java.time.Instant
import java.time.ZoneId
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.datetime.toKotlinLocalDate import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
object DatabaseHelper { object DatabaseHelper {
private const val MAX_SEARCH_HISTORY_SIZE = 20 private const val MAX_SEARCH_HISTORY_SIZE = 20
@ -28,12 +28,8 @@ object DatabaseHelper {
val watchHistoryItem = WatchHistoryItem( val watchHistoryItem = WatchHistoryItem(
videoId, videoId,
stream.title, stream.title,
stream.uploaded?.let { Instant.fromEpochMilliseconds(stream.uploaded)
Instant.ofEpochMilli(it) .toLocalDateTime(TimeZone.currentSystemDefault()).date,
.atZone(ZoneId.systemDefault())
.toLocalDate()
.toKotlinLocalDate()
},
stream.uploaderName, stream.uploaderName,
stream.uploaderUrl?.toID(), stream.uploaderUrl?.toID(),
stream.uploaderAvatar, stream.uploaderAvatar,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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