From 9ef7876e1c1ebad926a69cd5d44fd317a568e94b Mon Sep 17 00:00:00 2001 From: uttiya10 <56562649+uttiya10@users.noreply.github.com> Date: Fri, 23 Apr 2021 20:26:57 -0400 Subject: [PATCH 1/3] Display Source and Server Name On AnimeViewController --- NineAnimator.xcodeproj/project.pbxproj | 4 + .../Base.lproj/AnimePlayer.storyboard | 102 ++++++++++++++++-- .../Player Scene/AnimeViewController.swift | 29 +++-- .../SourceDescriptionTableViewCell.swift | 41 +++++++ 4 files changed, 159 insertions(+), 17 deletions(-) create mode 100644 NineAnimator/Views/Anime Scene/SourceDescriptionTableViewCell.swift diff --git a/NineAnimator.xcodeproj/project.pbxproj b/NineAnimator.xcodeproj/project.pbxproj index 33f4544ba..c82a6fe6b 100644 --- a/NineAnimator.xcodeproj/project.pbxproj +++ b/NineAnimator.xcodeproj/project.pbxproj @@ -476,6 +476,7 @@ BF762C612616A8FB00265DA4 /* Pantsubase+Episode.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF762C602616A8FB00265DA4 /* Pantsubase+Episode.swift */; }; BF762C662616BDBD00265DA4 /* PantsudriveParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF762C652616BDBD00265DA4 /* PantsudriveParser.swift */; }; BF76D9F524EA27C000734C43 /* AnimeHub+Episode.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCB22AA24DF378800406034 /* AnimeHub+Episode.swift */; }; + BF7D075E26324F5500842CBC /* SourceDescriptionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7D075D26324F5500842CBC /* SourceDescriptionTableViewCell.swift */; }; BF86795425F99BBC0046773E /* CachedDownloadsToAppSupportDataMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF86795325F99BBC0046773E /* CachedDownloadsToAppSupportDataMigrator.swift */; }; BF9203DC25E07E6E00CB2D91 /* AudioBackgroundController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9203DB25E07E6E00CB2D91 /* AudioBackgroundController.swift */; }; BF95264224F1E06B00924B79 /* AnilistUserRecommendations.graphql in Resources */ = {isa = PBXBuildFile; fileRef = BF95264124F1E06B00924B79 /* AnilistUserRecommendations.graphql */; }; @@ -1088,6 +1089,7 @@ BF762C5B2616A8BA00265DA4 /* Pantsubase+Anime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pantsubase+Anime.swift"; sourceTree = ""; }; BF762C602616A8FB00265DA4 /* Pantsubase+Episode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pantsubase+Episode.swift"; sourceTree = ""; }; BF762C652616BDBD00265DA4 /* PantsudriveParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PantsudriveParser.swift; sourceTree = ""; }; + BF7D075D26324F5500842CBC /* SourceDescriptionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceDescriptionTableViewCell.swift; sourceTree = ""; }; BF86795325F99BBC0046773E /* CachedDownloadsToAppSupportDataMigrator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CachedDownloadsToAppSupportDataMigrator.swift; sourceTree = ""; }; BF9203DB25E07E6E00CB2D91 /* AudioBackgroundController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioBackgroundController.swift; sourceTree = ""; }; BF95264124F1E06B00924B79 /* AnilistUserRecommendations.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = AnilistUserRecommendations.graphql; sourceTree = ""; }; @@ -2189,6 +2191,7 @@ 2CD9B9A521FE605B00203442 /* AnimeSynopsisCellTableViewCell.swift */, 2C8F6E7F2205E76D0047798B /* AnimePredictedEpisodeTableViewCell.swift */, 2CDA17A422065456009543F9 /* OfflineEpisodeTableViewCell.swift */, + BF7D075D26324F5500842CBC /* SourceDescriptionTableViewCell.swift */, ); path = "Anime Scene"; sourceTree = ""; @@ -2918,6 +2921,7 @@ 2CAEA891235D385400AC2370 /* LibraryHeaderView.swift in Sources */, 2C4FDDAC22482AE90059B7D8 /* UrlFormEncoding.swift in Sources */, 2C86C1EF225D7FB600950ABF /* SetupWhatsNewViewController.swift in Sources */, + BF7D075E26324F5500842CBC /* SourceDescriptionTableViewCell.swift in Sources */, 2CBDBC5B24BCBC0F000B360D /* UserLibrary.xcdatamodeld in Sources */, 2C8374EA24AF808A0009F8D7 /* SettingsRichPresenceController.swift in Sources */, 2C6A390A23A0180B00FC00A9 /* FourAnime+Episode.swift in Sources */, diff --git a/NineAnimator/Base.lproj/AnimePlayer.storyboard b/NineAnimator/Base.lproj/AnimePlayer.storyboard index 50f593c0b..5d7d6bca3 100644 --- a/NineAnimator/Base.lproj/AnimePlayer.storyboard +++ b/NineAnimator/Base.lproj/AnimePlayer.storyboard @@ -1,9 +1,9 @@ - + - + @@ -85,7 +85,7 @@ - + + + + + + + + + + + + + + + + + + + + + - + @@ -465,7 +533,7 @@ - + @@ -532,7 +600,7 @@ - + @@ -572,7 +640,7 @@ - + @@ -692,6 +760,20 @@ + + + + + + + + + + + + + + diff --git a/NineAnimator/Controllers/Player Scene/AnimeViewController.swift b/NineAnimator/Controllers/Player Scene/AnimeViewController.swift index 800add9f0..f1fcf26bc 100644 --- a/NineAnimator/Controllers/Player Scene/AnimeViewController.swift +++ b/NineAnimator/Controllers/Player Scene/AnimeViewController.swift @@ -344,7 +344,7 @@ extension AnimeViewController { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch Section(rawValue: section)! { - case .suggestion, .synopsis: + case .suggestion, .synopsis, .sourceDescription: return anime == nil ? 0 : 1 case .episodes: return anime?.numberOfEpisodeLinks ?? 0 @@ -368,6 +368,16 @@ extension AnimeViewController { tableView?.endUpdates() } return cell + case .sourceDescription: + let cell = tableView.dequeueReusableCell(withIdentifier: "anime.source.description", for: indexPath) as! SourceDescriptionTableViewCell + + cell.setPresenting( + source: anime!.source, + server: anime!.servers[server!] ?? "No server" + ) { [weak self] cell in + self?.showSelectServerDialog(sourceView: cell) + } + return cell case .episodes: let episode = episodeLink(for: indexPath)! @@ -889,7 +899,9 @@ extension AnimeViewController { if anime != nil { actionSheet.addAction({ let action = UIAlertAction(title: "Select Server", style: .default) { - [weak self] _ in self?.showSelectServerDialog() + [weak self] _ in + guard let self = self else { return } + self.showSelectServerDialog(sourceView: self.moreOptionsButton) } action.image = #imageLiteral(resourceName: "Server") action.textAlignment = .left @@ -942,11 +954,12 @@ extension AnimeViewController { present(actionSheet, animated: true, completion: nil) } - private func showSelectServerDialog() { + private func showSelectServerDialog(sourceView: UIView) { let alertView = UIAlertController(title: "Select Server", message: nil, preferredStyle: .actionSheet) if let popover = alertView.popoverPresentationController { - popover.sourceView = moreOptionsButton + popover.sourceView = sourceView + popover.sourceRect = sourceView.bounds } for server in anime!.servers { @@ -988,7 +1001,7 @@ extension AnimeViewController { self.server = server tableView.reloadSections( - Section.indexSet(.episodes, .suggestion), + Section.indexSet(.episodes, .suggestion, .sourceDescription), with: .automatic ) @@ -1477,7 +1490,9 @@ fileprivate extension AnimeViewController { case synopsis = 1 - case episodes = 2 + case sourceDescription = 2 + + case episodes = 3 subscript(_ item: Int) -> IndexPath { IndexPath(item: item, section: self.rawValue) @@ -1506,5 +1521,5 @@ fileprivate extension AnimeViewController { } fileprivate extension Array where Element == AnimeViewController.Section { - static let all: [AnimeViewController.Section] = [ .suggestion, .synopsis, .episodes ] + static let all: [AnimeViewController.Section] = [ .suggestion, .synopsis, .sourceDescription, .episodes ] } diff --git a/NineAnimator/Views/Anime Scene/SourceDescriptionTableViewCell.swift b/NineAnimator/Views/Anime Scene/SourceDescriptionTableViewCell.swift new file mode 100644 index 000000000..37e7be20c --- /dev/null +++ b/NineAnimator/Views/Anime Scene/SourceDescriptionTableViewCell.swift @@ -0,0 +1,41 @@ +// +// This file is part of the NineAnimator project. +// +// Copyright © 2018-2020 Marcus Zhou. All rights reserved. +// +// NineAnimator is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// NineAnimator is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with NineAnimator. If not, see . +// + +import UIKit + +class SourceDescriptionTableViewCell: UITableViewCell { + @IBOutlet private weak var sourceHeaderTitle: UILabel! + @IBOutlet private weak var serverTitleButton: UIButton! + + private var onTapHandler: ((UIButton) -> Void)? + + func setPresenting(source: Source, server: String, handler: @escaping (UIButton) -> Void) { + sourceHeaderTitle.text = "Episodes on \(source.name)" + onTapHandler = handler + serverTitleButton.setTitle(server, for: .normal) + + // Remove separator line for this cell + separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude) + directionalLayoutMargins = .zero + } + + @IBAction private func onServerTitleClicked(_ sender: Any) { + onTapHandler?(serverTitleButton) + } +} From 2628a21cf8c441b858833293b3ae49c9c061208f Mon Sep 17 00:00:00 2001 From: uttiya10 <56562649+uttiya10@users.noreply.github.com> Date: Fri, 23 Apr 2021 21:45:24 -0400 Subject: [PATCH 2/3] Fix Breaking Constraints on macOS --- NineAnimator/Base.lproj/AnimePlayer.storyboard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineAnimator/Base.lproj/AnimePlayer.storyboard b/NineAnimator/Base.lproj/AnimePlayer.storyboard index 5d7d6bca3..7ffc283ba 100644 --- a/NineAnimator/Base.lproj/AnimePlayer.storyboard +++ b/NineAnimator/Base.lproj/AnimePlayer.storyboard @@ -454,7 +454,7 @@