Skip to content

Commit

Permalink
Add time information and live video
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Feb 4, 2023
1 parent c556120 commit a02d45a
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 19 deletions.
12 changes: 10 additions & 2 deletions Fosdem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
924E15BE2922CCA9005A8EA2 /* RoomState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924E15BD2922CCA9005A8EA2 /* RoomState.swift */; };
924E15C329238AA5005A8EA2 /* ListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924E15C229238AA5005A8EA2 /* ListItem.swift */; };
925321602925716A004C7E5C /* EventUserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9253215F2925716A004C7E5C /* EventUserInfo.swift */; };
925B0261298EAE0E00AFA83D /* LiveIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925B0260298EAE0E00AFA83D /* LiveIcon.swift */; };
925B0263298EB2A400AFA83D /* VideoPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925B0262298EB2A400AFA83D /* VideoPlayer.swift */; };
92A2BDF82948CAE50034864F /* schedule_2019.xml in Resources */ = {isa = PBXBuildFile; fileRef = 92A2BDF72948CAE50034864F /* schedule_2019.xml */; };
92A2BDFC2948D4AC0034864F /* schedule_2023.xml in Resources */ = {isa = PBXBuildFile; fileRef = 92A2BDFA2948D4AC0034864F /* schedule_2023.xml */; };
92A2BDFD2948D4AC0034864F /* schedule_2022.xml in Resources */ = {isa = PBXBuildFile; fileRef = 92A2BDFB2948D4AC0034864F /* schedule_2022.xml */; };
Expand Down Expand Up @@ -91,6 +93,8 @@
924E15BD2922CCA9005A8EA2 /* RoomState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomState.swift; sourceTree = "<group>"; };
924E15C229238AA5005A8EA2 /* ListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItem.swift; sourceTree = "<group>"; };
9253215F2925716A004C7E5C /* EventUserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventUserInfo.swift; sourceTree = "<group>"; };
925B0260298EAE0E00AFA83D /* LiveIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveIcon.swift; sourceTree = "<group>"; };
925B0262298EB2A400AFA83D /* VideoPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayer.swift; sourceTree = "<group>"; };
92A2BDF72948CAE50034864F /* schedule_2019.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = schedule_2019.xml; sourceTree = "<group>"; };
92A2BDF92948CC5E0034864F /* FosdemTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = FosdemTests.xctestplan; path = Fosdem.xcodeproj/FosdemTests.xctestplan; sourceTree = "<group>"; };
92A2BDFA2948D4AC0034864F /* schedule_2023.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = schedule_2023.xml; sourceTree = "<group>"; };
Expand Down Expand Up @@ -170,6 +174,8 @@
92D9E7B9291D95E1007D203D /* EventDetailHeader.swift */,
924E15C229238AA5005A8EA2 /* ListItem.swift */,
92B987FB2981CD10007574EB /* AboutView.swift */,
925B0260298EAE0E00AFA83D /* LiveIcon.swift */,
925B0262298EB2A400AFA83D /* VideoPlayer.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -421,6 +427,7 @@
146A8677220601DD008A61AD /* XmlFinder.swift in Sources */,
92CE31AF28FC49DC0073813E /* YearHelper.swift in Sources */,
92C271D02922292500E8C25D /* PreviewEvent.swift in Sources */,
925B0263298EB2A400AFA83D /* VideoPlayer.swift in Sources */,
14D2771C2205D07200740042 /* Fosdem.xcdatamodeld in Sources */,
14DA2290220C735600CBE015 /* DataImporter.swift in Sources */,
146A867E22089497008A61AD /* Link.swift in Sources */,
Expand All @@ -435,6 +442,7 @@
14DA228E220C6B9000CBE015 /* ManagedObjectProtocol.swift in Sources */,
146A86702205EFE9008A61AD /* Person.swift in Sources */,
14D2774C2205D19D00740042 /* RemoteScheduleFetcher.swift in Sources */,
925B0261298EAE0E00AFA83D /* LiveIcon.swift in Sources */,
92B987FC2981CD10007574EB /* AboutView.swift in Sources */,
92077D5128FF01C600BF8A03 /* EventDetailView.swift in Sources */,
92F70AA02922B49A000BE6CB /* UrlHelper.swift in Sources */,
Expand Down Expand Up @@ -613,7 +621,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = eu.seanmolenaar.Fosdem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -641,7 +649,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = eu.seanmolenaar.Fosdem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
4 changes: 2 additions & 2 deletions Fosdem/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down
13 changes: 13 additions & 0 deletions Fosdem/Models/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public class Event: NSManagedObject, ManagedObjectProtocol, Identifiable {
return Int(startInFormat("dd")) ?? 0
}

public var end: Date {
return start.addingTimeInterval(duration)
}

public var isOngoing: Bool {
let date = Date()
return date > start && date < end
}

public var isEnded: Bool {
return end < Date()
}

func startInFormat(_ format: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format
Expand Down
2 changes: 1 addition & 1 deletion Fosdem/Utils/PreviewEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct PreviewEvent {
event.links = Set([link])

event.start = Date()
event.duration = TimeInterval(15)
event.duration = TimeInterval(150)
event.title = "Welcome to the Free Software Radio Devroom"
event.subtitle = subtitle ? "This presentation will give you an overview what to expect in the Free Software Radio devroom at FOSDEM 2022." : nil
event.desc = """
Expand Down
4 changes: 2 additions & 2 deletions Fosdem/Utils/UrlHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ extension Room {
}

func liveStreamLink() -> URL {
return URL(string: "https://live.fosdem.org/watch/\(urlName)")!
return URL(string: "https://stream.fosdem.org/\(urlName).m3u8")!
}

func chatLink() -> URL {
return URL(string: "https://chat.fosdem.org/#/room/\(urlName):fosdem.org")!
return URL(string: "https://chat.fosdem.org/#/room/%23\(YearHelper().year)-\(name.lowercased()):fosdem.org")!
}
}

Expand Down
15 changes: 9 additions & 6 deletions Fosdem/Views/EventDetailHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ struct EventDetailHeader: View {
.font(.subheadline)
}
Divider()
Label(event.formatTime(), systemImage: "calendar.badge.clock")
HStack {
Label(event.formatTime(), systemImage: "calendar.badge.clock")
if event.isOngoing { LiveIcon() }
}
Divider()
HStack {
if event.room.isVirtual() {
SwiftUI.Link(destination: event.room.chatLink()) {
Label(event.room.name, systemImage: "bubble.left.circle")
}
} else {
if !event.room.isVirtual() {
SwiftUI.Link(destination: event.room.getNavigationLink()) {
Label(event.room.name, systemImage: "location.circle")
}
Divider()
}
SwiftUI.Link(destination: event.room.chatLink()) {
Label(event.room.name, systemImage: "bubble.left.circle")
}

if let item = Conference.roomStates.first(where: { $0.roomname == event.room.name }) {
Expand Down
4 changes: 4 additions & 0 deletions Fosdem/Views/EventDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct EventDetailView: View {
Picker("Test", selection: $selectedTabIndex, content: {
Text("Description").tag(0)
Text("Links").disabled(event.links.isEmpty).tag(1)
if event.isOngoing { Text("Live Video").tag(2) }
}).pickerStyle(.segmented)

ZStack {
Expand All @@ -70,6 +71,9 @@ struct EventDetailView: View {
}
}
}
if selectedTabIndex == 2 {
VideoPlayer(event.room.liveStreamLink())
}
}
}
}.navigationTitle(Text(event.title))
Expand Down
2 changes: 1 addition & 1 deletion Fosdem/Views/EventListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct EventListView: View {


List(myEvents) { event in
NavigationLink(value: event, label: { ListItem(event) })
NavigationLink(value: event, label: { ListItem(event, bookmarkEmphasis: false) })
}.listStyle(.plain).tabItem {
Label("My events", systemImage: "person.circle")
}.overlay(Group {
Expand Down
16 changes: 11 additions & 5 deletions Fosdem/Views/ListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import SwiftUI

struct ListItem: View {
@ObservedObject private var event: Event
private var bookmarkEmphasis: Bool

@Environment(\.managedObjectContext) var context

init(_ event: Event) {
init(_ event: Event, bookmarkEmphasis: Bool = true) {
self.event = event
self.bookmarkEmphasis = bookmarkEmphasis
}

var body: some View {
HStack {
if let lastSeen = event.userInfo.lastSeen, event.lastUpdated > lastSeen {
Rectangle().foregroundColor(.accentColor).frame(maxWidth: 1, maxHeight: .infinity)
if let lastSeen = event.userInfo.lastSeen, event.lastUpdated > lastSeen && !event.isEnded {
Circle().foregroundColor(.accentColor)
.frame(width: 7, height: 7)
}
VStack(alignment: .trailing) {
Text(event.startInFormat("EE").capitalized)
Expand All @@ -31,8 +34,11 @@ struct ListItem: View {
.italic()
}

if event.isOngoing { LiveIcon() }

Text(event.title)
.bold(event.userInfo.favorite)
.bold(event.userInfo.favorite && bookmarkEmphasis)
.foregroundColor(!event.isEnded ? .primary : .gray)

}.contextMenu {
Label(event.track.name.capitalized, systemImage: event.type.icon)
Expand All @@ -50,7 +56,7 @@ struct ListItem: View {
}
ShareLink("Share web link", item: event.getPublicLink(), message: Text(event.title))
}.swipeActions {
Toggle(isOn: $event.userInfo.favorite, label: {
Button(action: { event.userInfo.favorite.toggle() }, label: {
Label("Favorite", systemImage: event.userInfo.favorite ? "star.fill" : "star")
}).tint(.orange)
}
Expand Down
31 changes: 31 additions & 0 deletions Fosdem/Views/LiveIcon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// LiveIcon.swift
// Fosdem
//
// Created by Sean Molenaar on 04/02/2023.
// Copyright © 2023 Sean Molenaar. All rights reserved.
//

import SwiftUI

struct LiveIcon: View {
@State private var blinking: Bool = false

var body: some View {
Circle().foregroundColor(.red)
.opacity(blinking ? 0 : 1)
.frame(width: 10, height: 10)
.animation(.easeInOut(duration: 1).repeatForever(), value: blinking)
.onAppear {
withAnimation {
blinking = true
}
}
}
}

struct LiveIcon_Previews: PreviewProvider {
static var previews: some View {
LiveIcon()
}
}
35 changes: 35 additions & 0 deletions Fosdem/Views/VideoPlayer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// VideoPlayer.swift
// Fosdem
//
// Created by Sean Molenaar on 04/02/2023.
// Copyright © 2023 Sean Molenaar. All rights reserved.
//

import SwiftUI
import AVKit

struct VideoPlayer: View {
private var player: AVPlayer
init(_ url: URL) {
let player = AVPlayer(url: url)
player.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible
player.allowsExternalPlayback = true

self.player = player
}

var body: some View {
AVKit.VideoPlayer(player: player)
.frame(height: 300)
.onAppear {
player.play()
}
}
}

struct VideoPlayer_Previews: PreviewProvider {
static var previews: some View {
VideoPlayer(URL(string: "https://github.com")!)
}
}

0 comments on commit a02d45a

Please sign in to comment.