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

Commit

Permalink
Allow adding feeds via share sheet if viewing feed URL directly
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Feb 17, 2021
1 parent 93a4882 commit 80959b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Client/Frontend/Brave Today/Composer/FeedDataSource+RSS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,20 @@ extension FeedItem.Content {
extension FeedItem.Source {
init?(from feed: FeedKit.Feed, location: RSSFeedLocation) {
let id = location.id
let feedTitle: String
switch feed {
guard let title = feed.title else { return nil }
self.init(id: id, isDefault: true, category: "", name: title, isUserSource: true)
}
}

extension Feed {
var title: String? {
switch self {
case .atom(let feed):
guard let title = feed.title else { return nil }
feedTitle = title
return feed.title
case .rss(let feed):
guard let title = feed.title else { return nil }
feedTitle = title
return feed.title
case .json(let feed):
guard let title = feed.title else { return nil }
feedTitle = title
return feed.title
}
self.init(id: id, isDefault: true, category: "", name: feedTitle, isUserSource: true)
}
}
22 changes: 22 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SafariServices
import BraveUI
import NetworkExtension
import YubiKit
import FeedKit

private let log = Logger.browserLogger

Expand Down Expand Up @@ -1856,6 +1857,27 @@ class BrowserViewController: UIViewController {
activities.append(createPDFActivity)
}
#endif
} else {
// Check if its a feed, url is a temp document file URL
if let selectedTab = tabManager.selectedTab,
(selectedTab.mimeType == "application/xml" || selectedTab.mimeType == "application/json"),
let tabURL = selectedTab.url {
let parser = FeedParser(URL: url)
if case .success(let feed) = parser.parse() {
let addToBraveToday = AddFeedToBraveTodayActivity() { [weak self] in
guard let self = self else { return }
let controller = BraveTodayAddSourceResultsViewController(
dataSource: self.feedDataSource,
searchedURL: tabURL,
rssFeedLocations: [.init(title: feed.title, url: tabURL)],
sourcesAdded: nil
)
let container = UINavigationController(rootViewController: controller)
self.present(container, animated: true)
}
activities.append(addToBraveToday)
}
}
}

let controller = helper.createActivityViewController(items: activities) { [weak self] completed, _, documentUrl in
Expand Down

0 comments on commit 80959b5

Please sign in to comment.