Skip to content

Commit

Permalink
feat: add part of support for tvos
Browse files Browse the repository at this point in the history
  • Loading branch information
dimensi committed Mar 17, 2024
1 parent 11e7484 commit aa6cd9b
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 94 deletions.
3 changes: 2 additions & 1 deletion Anime365ApiClient/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let package = Package(
name: "Anime365ApiClient",
platforms: [
.iOS(.v17),
.macOS(.v14)
.macOS(.v14),
.tvOS(.v16)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
Expand Down
3 changes: 2 additions & 1 deletion ScraperAPI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let package = Package(
name: "ScraperAPI",
platforms: [
.iOS(.v17),
.macOS(.v14)
.macOS(.v14),
.tvOS(.v16)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
Expand Down
3 changes: 1 addition & 2 deletions ichime.xcodeproj/xcshareddata/xcschemes/ichime.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
showNonLocalizedStrings = "YES">
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
Expand Down
2 changes: 2 additions & 0 deletions ichime/ContentView/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct ContentViewWithTabBar: View {
.tabItem {
Label("Я смотрю", systemImage: "film.stack")
}
#if !os(tvOS)
.badge(notificationCounterWatcher.counter)
#endif

NavigationStack {
MyListsView()
Expand Down
2 changes: 2 additions & 0 deletions ichime/ContentView/ContentViewWithSideBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct ContentViewWithSideBar: View {
.tag(SideBarLinks.myLists)

Label("Уведомления", systemImage: "bell")
#if !os(tvOS)
.badge(notificationCounterWatcher.counter)
#endif
.tag(SideBarLinks.notifications)
}
}
Expand Down
6 changes: 6 additions & 0 deletions ichime/CurrentlyWatching/View/CurrentlyWatchingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ struct CurrentlyWatchingView: View {
} description: {
Text("Подпишись чтоб получить все возможности приложения")
}
#if !os(tvOS)
.textSelection(.enabled)
#endif
case let .loadingFailed(error):
ContentUnavailableView {
Label("Ошибка при загрузке", systemImage: "exclamationmark.triangle")
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)
#endif
case .loadedButEmpty:
ContentUnavailableView {
Label("Ничего не нашлось", systemImage: "list.bullet")
Expand Down Expand Up @@ -157,7 +161,9 @@ struct LoadedCurrentlyWatching: View {
Section {
NavigationLink(value: CurrentlyWatchingView.SubRoute.notifications) {
Label("Уведомления", systemImage: "bell")
#if !os(tvOS)
.badge(counter)
#endif
}
}
}
Expand Down
52 changes: 29 additions & 23 deletions ichime/Episode/Component/VideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ final class VideoPlayerController: NSObject, ObservableObject {
return metadata
}

private func changeOrientation(to orientation: UIInterfaceOrientationMask) {
// tell the app to change the orientation
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
else { return }
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
print("Changing to", orientation == .portrait ? "portrait" : "landscape")
}
#if !os(tvOS)
private func changeOrientation(to orientation: UIInterfaceOrientationMask) {
// tell the app to change the orientation
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
else { return }
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
print("Changing to", orientation == .portrait ? "portrait" : "landscape")
}
#endif

class Coordinator: NSObject, AVPlayerViewControllerDelegate {
var control: VideoPlayerController
Expand All @@ -248,20 +250,22 @@ final class VideoPlayerController: NSObject, ObservableObject {
self.control = control
}

func playerViewController(
_: AVPlayerViewController,
willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator
) {
// Called when the player enters fullscreen mode
}
#if !os(tvOS)
func playerViewController(
_: AVPlayerViewController,
willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator
) {
// Called when the player enters fullscreen mode
}

func playerViewController(
_: AVPlayerViewController,
willEndFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator
) {
// Called when the player exits fullscreen mode
control.destroyPlayer()
}
func playerViewController(
_: AVPlayerViewController,
willEndFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator
) {
// Called when the player exits fullscreen mode
control.destroyPlayer()
}
#endif

// Не ломает пип после выхода из пипа
func playerViewController(
Expand All @@ -284,9 +288,11 @@ final class VideoPlayerController: NSObject, ObservableObject {

struct VideoPlayerLoader: View {
var body: some View {
Color(UIColor.systemBackground).ignoresSafeArea(.all).overlay {
ProgressView("Загружаем видео")
}
#if !os(tvOS)
Color(UIColor.systemBackground).ignoresSafeArea(.all).overlay {
ProgressView("Загружаем видео")
}
#endif
}
}

Expand Down
4 changes: 3 additions & 1 deletion ichime/Episode/View/EpisodeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ struct EpisodeListView: View {
}
}
.navigationTitle("Список серий")
.navigationBarTitleDisplayMode(.large)
#if !os(tvOS)
.navigationBarTitleDisplayMode(.large)
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ struct EpisodeTranslationQualitySelectorView: View {
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)

#endif
case .loadedButEmpty:
ContentUnavailableView {
Label("Ничего не нашлось", systemImage: "list.bullet")
Expand Down Expand Up @@ -125,15 +126,17 @@ struct EpisodeTranslationQualitySelectorView: View {
}
}
}
.navigationTitle(translationTeam)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Закрыть") {
self.dismiss()
}
}
}
.navigationTitle(translationTeam)
#if !os(tvOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}

func handleStartPlay(video: URL, subtitle: URL?) {
Expand Down
6 changes: 5 additions & 1 deletion ichime/Episode/View/EpisodeTranslationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ struct EpisodeTranslationsView: View {
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)
#endif

case .loadedButEmpty:
ContentUnavailableView {
Expand Down Expand Up @@ -137,7 +139,9 @@ struct EpisodeTranslationsView: View {
}
}
.navigationTitle(episodeTitle)
.navigationBarTitleDisplayMode(.large)
#if !os(tvOS)
.navigationBarTitleDisplayMode(.large)
#endif
}

func findTranslation(id: Int, groupedTranslations: GroupedTranslation) -> Translation? {
Expand Down
8 changes: 5 additions & 3 deletions ichime/MyLists/Component/AnimeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ struct AnimeList: View {
)
.font(.footnote).padding(.leading)
}.contextMenu(menuItems: {
ShareLink(item: show.websiteUrl) {
Label("Поделиться", systemImage: "square.and.arrow.up")
}
#if !os(tvOS)
ShareLink(item: show.websiteUrl) {
Label("Поделиться", systemImage: "square.and.arrow.up")
}
#endif
NavigationLink(destination: ShowView(showId: show.id)) {
Text("Открыть")
}
Expand Down
8 changes: 5 additions & 3 deletions ichime/MyLists/Component/UserRateForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ struct UserRateForm: View {
Text("/ \(totalEpisodes)")
}
}
Section("Ваша заметка") {
TextEditor(text: $comment)
}
#if !os(tvOS)
Section("Ваша заметка") {
TextEditor(text: $comment)
}
#endif
Button("Удалить из списка", role: .destructive) {
isDeleteDialogOpen = true
}
Expand Down
9 changes: 6 additions & 3 deletions ichime/MyLists/View/MyListEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ struct MyListEditView: View {
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)

#endif
case let .loaded(userRate):
UserRateForm(userRate, totalEpisodes: totalEpisodes) { newUserRate in
Task {
Expand All @@ -114,15 +115,17 @@ struct MyListEditView: View {
}
}
}
.navigationTitle(show.name.ru)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Закрыть") {
self.dismiss()
}
}
}
.navigationTitle(show.name.ru)
#if !os(tvOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}

Expand Down
16 changes: 11 additions & 5 deletions ichime/MyLists/View/MyListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MyListViewModel: ObservableObject {
guard case let .isAuth(user) = userManager.state else {
fatalError("This screen can use only with auth")
}

if !userManager.subscribed {
return await updateState(.needSubscribe)
}
Expand All @@ -101,7 +101,7 @@ class MyListViewModel: ObservableObject {
if !userManager.subscribed {
return await updateState(.needSubscribe)
}

guard let type else {
return await updateState(.loaded(categories))
}
Expand Down Expand Up @@ -164,14 +164,18 @@ struct MyListsView: View {
} description: {
Text("Подпишись чтоб получить все возможности приложения")
}
#if !os(tvOS)
.textSelection(.enabled)
#endif
case let .loadingFailed(error):
ContentUnavailableView {
Label("Ошибка при загрузке", systemImage: "exclamationmark.triangle")
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)
#endif
case .loadedButEmpty:
ContentUnavailableView {
Label("Ничего не нашлось", systemImage: "list.bullet")
Expand Down Expand Up @@ -221,9 +225,11 @@ struct ToolbarWrapper<Content: View>: View {
content()
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
ShareLink(item: shareText) {
Label("Поделиться", systemImage: "square.and.arrow.up")
}
#if !os(tvOS)
ShareLink(item: shareText) {
Label("Поделиться", systemImage: "square.and.arrow.up")
}
#endif
}
ToolbarItem(placement: .topBarTrailing) {
Menu {
Expand Down
2 changes: 2 additions & 0 deletions ichime/NotificationCenter/View/NotificationCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ struct NotificationCenterView: View {
} description: {
Text(error.localizedDescription)
}
#if !os(tvOS)
.textSelection(.enabled)
#endif
case .loadedButEmpty:
ContentUnavailableView {
Label("Пока еще не было уведомлений", systemImage: "list.bullet")
Expand Down
12 changes: 8 additions & 4 deletions ichime/Profile/Sheet/ProfileSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ struct ProfileSheet: View {
}
)
.frame(width: 50, height: 50)
.background(Color(UIColor.secondarySystemBackground))
.clipShape(.circle)
#if !os(tvOS)
.background(Color(UIColor.secondarySystemBackground))
#endif
.clipShape(.circle)
}

Section {
Expand All @@ -69,15 +71,17 @@ struct ProfileSheet: View {
}
}
}
.navigationTitle("Ваш профиль")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Закрыть") {
self.dismiss()
}
}
}
.navigationTitle("Ваш профиль")
#if !os(tvOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion ichime/Profile/View/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ struct AuthenticationAppFeature: View {
.padding(.all)
#if os(macOS)
.background(Color.primary.blendMode(.overlay), in: RoundedRectangle(cornerRadius: 12))
#else
#endif
#if !os(tvOS)
.background(Color(uiColor: UIColor.secondarySystemBackground), in: RoundedRectangle(cornerRadius: 12))
#endif

Expand Down
Loading

0 comments on commit aa6cd9b

Please sign in to comment.