You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.6 KiB
90 lines
2.6 KiB
//
|
|
// PodcastEpisodeViewCell.swift
|
|
// PodcastsClone
|
|
//
|
|
// Created by etudiant on 2023-05-12.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
|
|
struct EpisodeViewCell: View {
|
|
|
|
let episode: Episode
|
|
|
|
private let formatter: DateFormatter = {
|
|
// TODO display date smartly
|
|
// TODAY
|
|
// 1-6D AGO
|
|
// 14 MAY (no year if same year as now)
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "dd/MM/yyyy"
|
|
return formatter
|
|
}()
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading) {
|
|
// TODO make divider reach the edge on the right
|
|
Divider()
|
|
.foregroundColor(Color.theme.backgroundSecondary)
|
|
|
|
Text(formatter.string(from: episode.publicationDate))
|
|
.font(.subheadline)
|
|
.foregroundColor(Color.theme.secondary)
|
|
|
|
(Text(episode.title)
|
|
.font(.headline)
|
|
.foregroundColor(Color.theme.primary)
|
|
+ Text("\n\(episode.description)")
|
|
.font(.body)
|
|
.foregroundColor(Color.theme.secondary))
|
|
.lineLimit(4)
|
|
.truncationMode(.tail)
|
|
|
|
HStack {
|
|
Image(systemName: "play.fill")
|
|
.foregroundColor(Color.theme.accent)
|
|
.padding()
|
|
.background(Color.theme.backgroundSecondary)
|
|
.clipShape(Circle())
|
|
Text(timeString(time: episode.duration))
|
|
.foregroundColor(Color.theme.accent)
|
|
Spacer()
|
|
Text(Strings.threeDots)
|
|
.foregroundColor(Color.theme.secondary)
|
|
.padding(.horizontal)
|
|
}
|
|
|
|
}
|
|
.padding()
|
|
}
|
|
|
|
private func timeString(time: TimeInterval) -> String {
|
|
let hours = Int(time) / 3600
|
|
let minutes = Int(time) / 60 % 60
|
|
|
|
var timeComponents = [String]()
|
|
if hours > 0 {
|
|
timeComponents.append("\(hours) hr")
|
|
}
|
|
if minutes > 0 {
|
|
timeComponents.append("\(minutes) min")
|
|
}
|
|
|
|
return timeComponents.joined(separator: " ")
|
|
}
|
|
}
|
|
|
|
struct EpisodeViewCell_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
EpisodeViewCell(episode: Episode(
|
|
id: UUID(),
|
|
publicationDate: Date.now,
|
|
title: "Episode title and stuff -- what it's about, who's in it, all sorts of things can end up in this title. To us, it's a string",
|
|
description: "This is a great episode. The description kinda goes on and on and on and on and on and on and on and on.",
|
|
duration: 4000
|
|
))
|
|
}
|
|
}
|