mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Format watch history item dates.
This commit is contained in:
parent
58374ddba1
commit
57477ff9fd
@ -3,6 +3,7 @@ package com.github.libretube.db
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.github.libretube.db.dao.CustomInstanceDao
|
||||
import com.github.libretube.db.dao.DownloadDao
|
||||
import com.github.libretube.db.dao.LocalPlaylistsDao
|
||||
@ -42,6 +43,7 @@ import com.github.libretube.db.obj.WatchPosition
|
||||
AutoMigration(from = 9, to = 10)
|
||||
]
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
/**
|
||||
* Watch History
|
||||
|
13
app/src/main/java/com/github/libretube/db/Converters.kt
Normal file
13
app/src/main/java/com/github/libretube/db/Converters.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.github.libretube.db
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.toLocalDate
|
||||
|
||||
object Converters {
|
||||
@TypeConverter
|
||||
fun localDateToString(localDate: LocalDate?) = localDate?.toString()
|
||||
|
||||
@TypeConverter
|
||||
fun stringToLocalDate(string: String?) = string?.toLocalDate()
|
||||
}
|
@ -17,7 +17,7 @@ object DatabaseHelper {
|
||||
val watchHistoryItem = WatchHistoryItem(
|
||||
videoId,
|
||||
streams.title,
|
||||
streams.uploadDate.toString(),
|
||||
streams.uploadDate,
|
||||
streams.uploader,
|
||||
streams.uploaderUrl.toID(),
|
||||
streams.uploaderAvatar,
|
||||
|
@ -3,6 +3,7 @@ package com.github.libretube.db.obj
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@ -10,7 +11,7 @@ import kotlinx.serialization.Serializable
|
||||
data class WatchHistoryItem(
|
||||
@PrimaryKey val videoId: String = "",
|
||||
@ColumnInfo val title: String? = null,
|
||||
@ColumnInfo val uploadDate: String? = null,
|
||||
@ColumnInfo val uploadDate: LocalDate? = null,
|
||||
@ColumnInfo val uploader: String? = null,
|
||||
@ColumnInfo val uploaderUrl: String? = null,
|
||||
@ColumnInfo var uploaderAvatar: String? = null,
|
||||
|
@ -14,6 +14,7 @@ import com.github.libretube.ui.extensions.setFormattedDuration
|
||||
import com.github.libretube.ui.extensions.setWatchProgressLength
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||
import com.github.libretube.ui.viewholders.WatchHistoryViewHolder
|
||||
import com.github.libretube.util.TextUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
@ -55,7 +56,7 @@ class WatchHistoryAdapter(
|
||||
holder.binding.apply {
|
||||
videoTitle.text = video.title
|
||||
channelName.text = video.uploader
|
||||
videoInfo.text = video.uploadDate
|
||||
videoInfo.text = video.uploadDate?.let { TextUtils.localizeDate(it) }
|
||||
thumbnailDuration.setFormattedDuration(video.duration!!, null)
|
||||
ImageHelper.loadImage(video.thumbnailUrl, thumbnail)
|
||||
ImageHelper.loadImage(video.uploaderAvatar, channelImage)
|
||||
|
@ -26,7 +26,6 @@ import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.core.text.parseAsHtml
|
||||
@ -818,8 +817,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
|
||||
|
||||
private fun localizeDate(streams: Streams): String {
|
||||
return if (!streams.livestream) {
|
||||
val locale = ConfigurationCompat.getLocales(resources.configuration)[0]!!
|
||||
TextUtils.SEPARATOR + TextUtils.localizeDate(streams.uploadDate, locale)
|
||||
TextUtils.SEPARATOR + TextUtils.localizeDate(streams.uploadDate)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class WatchHistoryFragment : Fragment() {
|
||||
uploaderName = it.uploader,
|
||||
uploaderUrl = it.uploaderUrl,
|
||||
uploaderAvatar = it.uploaderAvatar,
|
||||
uploadedDate = it.uploadDate,
|
||||
uploadedDate = it.uploadDate?.toString(),
|
||||
duration = it.duration
|
||||
)
|
||||
}.toTypedArray()
|
||||
|
@ -9,7 +9,6 @@ import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.*
|
||||
import kotlin.time.Duration
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.toJavaLocalDate
|
||||
@ -27,14 +26,17 @@ object TextUtils {
|
||||
const val RESERVED_CHARS = "?:\"*|/\\<>\u0000"
|
||||
|
||||
/**
|
||||
* Localize the date from a time string
|
||||
* @param date The date to parse
|
||||
* @param locale The locale to use, otherwise uses system default
|
||||
* return Localized date string
|
||||
* Date time formatter which uses the [FormatStyle.MEDIUM] format style.
|
||||
*/
|
||||
fun localizeDate(date: LocalDate, locale: Locale): String {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale)
|
||||
return date.toJavaLocalDate().format(formatter)
|
||||
private val MEDIUM_DATE_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
|
||||
|
||||
/**
|
||||
* Localize the date from a date string, using the medium format.
|
||||
* @param date The date to parse
|
||||
* @return localized date string
|
||||
*/
|
||||
fun localizeDate(date: LocalDate): String {
|
||||
return date.toJavaLocalDate().format(MEDIUM_DATE_FORMATTER)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user