Add tappable description links and timestamps in iOS

This commit is contained in:
Arkadiusz Fal
2022-08-19 23:55:02 +02:00
parent eeda7a5c6e
commit 97fc8fa4b7
14 changed files with 308 additions and 70 deletions

View File

@@ -499,6 +499,22 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
range: nil
)
let linkRegex = #"(<a\s+(?:[^>]*?\s+)?href=\"[^"]*\">[^<]*<\/a>)"#
let hrefRegex = #"href=\"([^"]*)\">"#
guard let hrefRegex = try? NSRegularExpression(pattern: hrefRegex) else { return description }
description = description.replacingMatches(regex: linkRegex) { matchingGroup in
let results = hrefRegex.matches(in: matchingGroup, range: NSRange(matchingGroup.startIndex..., in: matchingGroup))
if let result = results.first {
if let swiftRange = Range(result.range(at: 1), in: matchingGroup) {
return String(matchingGroup[swiftRange])
}
}
return matchingGroup
}
description = description.replacingOccurrences(
of: "<[^>]+>",
with: "",

View File

@@ -96,6 +96,7 @@ final class NavigationModel: ObservableObject {
}
navigation.hideKeyboard()
let presentingPlayer = player.presentingPlayer
player.hide()
navigation.presentingChannel = false
@@ -110,8 +111,14 @@ final class NavigationModel: ObservableObject {
navigation.sidebarSectionChanged.toggle()
navigation.tabSelection = .recentlyOpened(recent.tag)
} else {
withAnimation(.linear(duration: 0.3)) {
navigation.presentingChannel = true
var delay = 0.0
#if os(iOS)
if presentingPlayer { delay = 1.0 }
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
withAnimation(.linear(duration: 0.3)) {
navigation.presentingChannel = true
}
}
}
}
@@ -134,6 +141,8 @@ final class NavigationModel: ObservableObject {
#endif
navigation.hideKeyboard()
let presentingPlayer = player.presentingPlayer
player.hide()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
recents.add(recent)
@@ -142,8 +151,14 @@ final class NavigationModel: ObservableObject {
navigation.sidebarSectionChanged.toggle()
navigation.tabSelection = .recentlyOpened(recent.tag)
} else {
withAnimation(.linear(duration: 0.3)) {
navigation.presentingPlaylist = true
var delay = 0.0
#if os(iOS)
if presentingPlayer { delay = 1.0 }
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
withAnimation(.linear(duration: 0.3)) {
navigation.presentingPlaylist = true
}
}
}
}
@@ -156,18 +171,24 @@ final class NavigationModel: ObservableObject {
navigation: NavigationModel,
search: SearchModel
) {
player.hide()
navigation.presentingChannel = false
navigation.presentingPlaylist = false
navigation.tabSelection = .search
navigation.hideKeyboard()
let presentingPlayer = player.presentingPlayer
player.hide()
if let searchQuery = searchQuery {
let recent = RecentItem(from: searchQuery)
recents.add(recent)
DispatchQueue.main.async {
var delay = 0.0
#if os(iOS)
if presentingPlayer { delay = 1.0 }
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
search.queryText = searchQuery
search.changeQuery { query in query.query = searchQuery }
}

View File

@@ -39,14 +39,14 @@ struct Video: Identifiable, Equatable, Hashable {
init(
id: String? = nil,
videoID: String,
title: String,
author: String,
length: TimeInterval,
published: String,
views: Int,
title: String = "",
author: String = "",
length: TimeInterval = .zero,
published: String = "",
views: Int = 0,
description: String? = nil,
genre: String? = nil,
channel: Channel,
channel: Channel = .init(id: "", name: ""),
thumbnails: [Thumbnail] = [],
indexID: String? = nil,
live: Bool = false,