Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Remove Featured Anime Tab #243

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NineAnimator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@
BFA0704C24DE596D00E7C8BE /* Array+SafeSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFA0704B24DE596D00E7C8BE /* Array+SafeSubscript.swift */; };
BFAA489524DE0723009BE142 /* AnimeHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA489424DE0723009BE142 /* AnimeHub.swift */; };
BFAA489724DE0BA6009BE142 /* AnimeHub+Featured.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA489624DE0BA6009BE142 /* AnimeHub+Featured.swift */; };
BFAD190B262E5EE700D944D2 /* UserNotificationManager+FeaturedAnimeRecommendation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAD190A262E5EE700D944D2 /* UserNotificationManager+FeaturedAnimeRecommendation.swift */; };
BFBAEF5224DF228B00ADA414 /* AnimeHub+Anime.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBAEF5124DF228B00ADA414 /* AnimeHub+Anime.swift */; };
BFCBEE6624E0C4E100D8C54B /* FacebookParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCBEE6524E0C4E100D8C54B /* FacebookParser.swift */; };
BFD0F7D725CA35B100621241 /* AnimeTwist+SourceDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFD0F7D625CA35B100621241 /* AnimeTwist+SourceDescriptor.swift */; };
Expand Down Expand Up @@ -1099,6 +1100,7 @@
BFA0704B24DE596D00E7C8BE /* Array+SafeSubscript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SafeSubscript.swift"; sourceTree = "<group>"; };
BFAA489424DE0723009BE142 /* AnimeHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimeHub.swift; sourceTree = "<group>"; };
BFAA489624DE0BA6009BE142 /* AnimeHub+Featured.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnimeHub+Featured.swift"; sourceTree = "<group>"; };
BFAD190A262E5EE700D944D2 /* UserNotificationManager+FeaturedAnimeRecommendation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserNotificationManager+FeaturedAnimeRecommendation.swift"; sourceTree = "<group>"; };
BFBAEF5124DF228B00ADA414 /* AnimeHub+Anime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnimeHub+Anime.swift"; sourceTree = "<group>"; };
BFCB22AA24DF378800406034 /* AnimeHub+Episode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnimeHub+Episode.swift"; sourceTree = "<group>"; };
BFCBEE6524E0C4E100D8C54B /* FacebookParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FacebookParser.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2280,6 +2282,7 @@
children = (
2C3545A421DA84F500321B18 /* UserNotificationManager.swift */,
2C60EAB92266A22400280637 /* UserNotificationManager+RecommendationSource.swift */,
BFAD190A262E5EE700D944D2 /* UserNotificationManager+FeaturedAnimeRecommendation.swift */,
);
path = "User Notification";
sourceTree = "<group>";
Expand Down Expand Up @@ -2810,6 +2813,7 @@
2C055B0124AAB0E300FCAC25 /* MasterAnimeLinkRetriver.swift in Sources */,
2C1C716F221853AD00760A69 /* Anilist.swift in Sources */,
2C6CF24E221C2E090009D554 /* InformationSceneHeadingTableViewCell.swift in Sources */,
BFAD190B262E5EE700D944D2 /* UserNotificationManager+FeaturedAnimeRecommendation.swift in Sources */,
2C0CFC3D2263D9AB00EC793E /* DiscoveryLoadingTableViewCell.swift in Sources */,
2C2C54FF221606F800BAA76E /* User+UserDefaultKeys.swift in Sources */,
2CE5B8E0225ECAC200A2CF89 /* SetupFinishingViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ class DiscoverySceneViewController: UITableViewController {
}
}

override open var keyCommands: [UIKeyCommand]? {
if #available(iOS 13.0, *) {
return [
UIKeyCommand(
title: "Refresh All Recommendations",
action: #selector(reloadRecommendationList),
input: "r",
modifierFlags: .command
)
]
} else { return nil }
}

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.makeThemable()
}
Expand Down Expand Up @@ -318,7 +331,7 @@ fileprivate extension DiscoverySceneViewController {
}

/// Reload the entire recommendation list
func reloadRecommendationList(shouldInformTableView: Bool = true) {
@objc func reloadRecommendationList(shouldInformTableView: Bool = true) {
// Abort all previous tasks
recommendationLoadingTasks = [:]
recommendationList = NineAnimator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// 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 <http://www.gnu.org/licenses/>.
//

extension UserNotificationManager {
class FeaturedAnimeRecommendation: RecommendationSource {
var name = "Featured Anime"

var priority: Priority = .defaultMedium

var shouldPresentRecommendation: Bool {
// Hide recommendation source if the currently
// selected anime source returned no featured anime
return lastDisplayedSourceHasFeatured ||
(NineAnimator.default.user.source.name != currentlyLoadedSource.name)
}

var currentlyLoadedSource = NineAnimator.default.user.source
var lastDisplayedSourceHasFeatured = true

// This source also controls its child recommendation source
lazy var latestAnimeRecommendationSource = { LatestAnimeRecommendation(self) }()

func shouldReload(recommendation: Recommendation) -> Bool {
// Reload if the user changed currently selected source
NineAnimator.default.user.source.name != currentlyLoadedSource.name
}

func generateRecommendations() -> NineAnimatorPromise<Recommendation> {
NineAnimatorPromise<FeaturedContainer> {
self.currentlyLoadedSource = NineAnimator.default.user.source
return self.currentlyLoadedSource.featured($0)
} .then { result in
let featuredItems = result.featured.map {
RecommendingItem(.anime($0))
}

self.lastDisplayedSourceHasFeatured = !featuredItems.isEmpty

// Update child source as well
let latestAnimeItems = result.latest.map {
RecommendingItem(.anime($0))
}
self.latestAnimeRecommendationSource.latestAnime = latestAnimeItems

return Recommendation(
self,
items: featuredItems,
title: "Featured Anime",
subtitle: "On \(self.currentlyLoadedSource.name)"
)
}
}

/// Child source for Featured Anime Recommendation
class LatestAnimeRecommendation: RecommendationSource {
var name = "Latest Anime"

var priority: Priority = .defaultMedium

var shouldPresentRecommendation = false

var latestAnime: [RecommendingItem] = [] {
didSet {
shouldPresentRecommendation = !latestAnime.isEmpty
fireDidUpdateNotification()
}
}

let parent: FeaturedAnimeRecommendation

init(_ parent: FeaturedAnimeRecommendation) {
self.parent = parent
}

func shouldReload(recommendation: Recommendation) -> Bool {
recommendation.items != latestAnime
}

func generateRecommendations() -> NineAnimatorPromise<Recommendation> {
.success(
.init(
self,
items: latestAnime,
title: "Latest Anime",
subtitle: "On \(parent.currentlyLoadedSource.name)"
)
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class UserNotificationManager: NSObject, UNUserNotificationCenterDelegate {

private let animeCachingDirectory: URL

private let subscriptionRecommendationSource = SubscribedAnimeRecommendationSource()

override init() {
let fileManager = FileManager.default
self.animeCachingDirectory = try! fileManager.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
Expand All @@ -73,7 +71,12 @@ class UserNotificationManager: NSObject, UNUserNotificationCenterDelegate {
registerNotificationCategories()

// Add anime subscription as a recommendation source
NineAnimator.default.register(additionalRecommendationSource: subscriptionRecommendationSource)
NineAnimator.default.register(additionalRecommendationSource: SubscribedAnimeRecommendationSource())

// Add featured and latest anime recommendation sources
let featuredRecommendationSource = FeaturedAnimeRecommendation()
NineAnimator.default.register(additionalRecommendationSource: featuredRecommendationSource)
NineAnimator.default.register(additionalRecommendationSource: featuredRecommendationSource.latestAnimeRecommendationSource)
}
}

Expand Down
2 changes: 1 addition & 1 deletion NineAnimator/Models/Recommendation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protocol RecommendationSource: AnyObject {
}

/// Representing a recommended item
struct RecommendingItem {
struct RecommendingItem: Hashable {
enum CaptionStyle {
case standard
case highlight
Expand Down