Skip to content

Commit

Permalink
RSS improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Jul 22, 2024
1 parent 1261f64 commit a521f5a
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 188 deletions.
2 changes: 1 addition & 1 deletion Submodules/LibTorrent-Swift
2 changes: 1 addition & 1 deletion iTorrent.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "7bc0d46fb180803d8f7dc610bf256ad6e564c23daa917119278ae7ce0b814310",
"originHash" : "44b544b185235ec15216e26ccc849f4038f673959944f92ed64af199c9d4bf6f",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down
105 changes: 34 additions & 71 deletions iTorrent/Core/Assets/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"sourceLanguage" : "en",
"strings" : {
"" : {

},
"%@ of %@ (%@)" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -231,22 +228,6 @@
}
}
},
"common.download" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Download"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Скачать"
}
}
}
},
"common.enable" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -791,23 +772,6 @@
}
}
},
"details.path.migrate" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Migrate storage"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Мигрировать хранилище"
}
}
}
},
"details.pause" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -2879,23 +2843,6 @@
}
}
},
"preferences.notifications.seed" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "On seeding finished"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "По окончании раздачи"
}
}
}
},
"preferences.queueLimits" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3552,98 +3499,114 @@
}
}
},
"rsschannel.readAll" : {
"rss.downloadButtonType.added" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Read all"
"value" : "Already added"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Прочитать всё"
"value" : "Уже добавлено"
}
}
}
},
"rsschannel.safari" : {
"rss.downloadButtonType.magnet" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open in Safari"
"value" : "Download Magnet"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Открыть в Safari"
"value" : "Скачать Magnet"
}
}
}
},
"rsschannel.seen" : {
"rss.downloadButtonType.torrent" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Seen"
"value" : "Download"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Прочитать"
"value" : "Скачать"
}
}
}
},
"rsschannel.unseen" : {
"rsschannel.readAll" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Unseen"
"value" : "Read all"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Развидеть"
"value" : "Прочитать всё"
}
}
}
},
"rsschannel.safari" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open in Safari"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Открыть в Safari"
}
}
}
},
"rssdetail.magnetFound" : {
"rsschannel.seen" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Magnet link is attached to this post"
"value" : "Seen"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Пост содержит Magnet ссылку"
"value" : "Прочитать"
}
}
}
},
"rssdetail.torrentFound" : {
"rsschannel.unseen" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Torrent file is attached to this post"
"value" : "Unseen"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Пост содержит Torrent файл"
"value" : "Развидеть"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions iTorrent/Screens/Rss/Channel/Cells/RssChannelItemCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class RssChannelItemCell<VM: RssChannelItemCellViewModel>: MvvmCollectionViewLis
}
viewModel.$date.uiSink { [timeLabel] text in
timeLabel?.text = text
timeLabel?.isHidden = text == nil
timeLabel?.isHidden = text.isNilOrEmpty
}
viewModel.$subtitle.uiSink { [subtitleLabel] text in
subtitleLabel?.text = text
subtitleLabel?.isHidden = text == nil
subtitleLabel?.isHidden = text.isNilOrEmpty
}
}
}
Expand Down
85 changes: 66 additions & 19 deletions iTorrent/Screens/Rss/Details/RssDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,30 @@ import LibTorrent

class RssDetailsViewController<VM: RssDetailsViewModel>: BaseViewController<VM> {
var webView: WKWebView!

override func loadView() {
if UIApplication.shared.canOpenURL(viewModel.rssModel.link) {
let button = UIBarButtonItem(primaryAction: .init(image: .init(systemName: "safari"), handler: { [unowned self] _ in
let safariVC = BaseSafariViewController(url: viewModel.rssModel.link)
present(safariVC, animated: true)
}))
navigationItem.setRightBarButton(button, animated: false)
}

webView = WKWebView()
webView.backgroundColor = .secondarySystemBackground
#if !os(visionOS)
webView.scrollView.keyboardDismissMode = .onDrag
#endif
view = webView
}

var webViewViewController: UIViewController!
@IBOutlet var downloadButtonContainer: UIView!
@IBOutlet var downloadButtonNonSafeAreaHolder: UIView!
@IBOutlet var downloadButton: UIButton!
@IBOutlet var separatorHeight: NSLayoutConstraint!

override func viewDidLoad() {
super.viewDidLoad()
setup()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
webViewViewController.additionalSafeAreaInsets.bottom = downloadButtonNonSafeAreaHolder.bounds.height
}

private lazy var delegates = Delegates(parent: self)
}

private extension RssDetailsViewController {
func setup() {
navigationItem.largeTitleDisplayMode = .never
setupDownloadButton()
setupWebView()
binding()

webView.navigationDelegate = delegates
Expand All @@ -49,10 +44,62 @@ private extension RssDetailsViewController {

func binding() {
disposeBag.bind {
viewModel.$title.sink { [unowned self] text in
viewModel.$title.uiSink { [unowned self] text in
title = text
}
viewModel.$downloadType.uiSink { [unowned self] downloadType in
downloadButtonContainer.isHidden = downloadType == nil
downloadButton.setTitle(downloadType?.title, for: .normal)
downloadButton.isEnabled = downloadType != .added
view.layoutSubviews()
}
downloadButton.tapPublisher.sink { [unowned self] _ in
viewModel.download?()
}
}
}

func setupDownloadButton() {
separatorHeight.constant = 1 / traitCollection.displayScale
downloadButton.configuration?.titleTextAttributesTransformer = .init { attributes in
var result = attributes
result.font = UIFont.preferredFont(forTextStyle: .headline)
return result
}
}

func setupWebView() {
if let link = viewModel.rssModel.link,
UIApplication.shared.canOpenURL(link)
{
let button = UIBarButtonItem(primaryAction: .init(image: .init(systemName: "safari"), handler: { [unowned self] _ in
let safariVC = BaseSafariViewController(url: link)
present(safariVC, animated: true)
}))
navigationItem.setRightBarButton(button, animated: false)
}

webView = WKWebView()
webView.translatesAutoresizingMaskIntoConstraints = false

webViewViewController = UIViewController()
webViewViewController.view = webView

addChild(webViewViewController)
view.insertSubview(webView, at: 0)
webViewViewController.didMove(toParent: self)

NSLayoutConstraint.activate([
view.leadingAnchor.constraint(equalTo: webView.leadingAnchor),
view.topAnchor.constraint(equalTo: webView.topAnchor),
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])

webView.backgroundColor = .secondarySystemBackground
#if !os(visionOS)
webView.scrollView.keyboardDismissMode = .onDrag
#endif
}

func loadHtml() {
Expand Down
Loading

0 comments on commit a521f5a

Please sign in to comment.