2021-08-22 03:42:06 +02:00
|
|
|
//
|
|
|
|
// BrowserConfigurationViewController.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 22/8/21.
|
|
|
|
// Copyright © 2021 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class BrowserConfigurationViewController: UITableViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
title = NSLocalizedString("Browser Selection", comment: "Browser")
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(browserPreferenceDidChange), name: .browserPreferenceDidChange, object: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Table view data source
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
2021-08-25 09:05:18 +02:00
|
|
|
return 2
|
2021-08-22 03:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2021-08-25 09:05:18 +02:00
|
|
|
return 1
|
2021-08-22 03:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
if indexPath.section == 0 {
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "BrowserCell", for: indexPath) as! BrowserCell
|
2021-08-25 09:05:18 +02:00
|
|
|
cell.configure(with: Browser.allCases[0])
|
2021-08-22 03:42:06 +02:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
if indexPath.section == 1 {
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "BrowserCell", for: indexPath) as! BrowserCell
|
2021-08-25 09:05:18 +02:00
|
|
|
cell.configure(with: Browser.allCases[1])
|
2021-08-22 03:42:06 +02:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "BrowserCell") ?? UITableViewCell()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
guard let cell = tableView.cellForRow(at: indexPath) as? BrowserCell else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cell.updateBrowserSelection()
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
|
|
if section == 0 {
|
|
|
|
return NSLocalizedString("Open Links In", comment: "Open Links")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
|
|
if section == 0 {
|
|
|
|
return NSLocalizedString("Links will open in NetNewsWire.", comment: "NNW browser footer.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if section == 1 {
|
|
|
|
return NSLocalizedString("Links will open in the default system browser configured in Settings.", comment: "Default browser footer.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Notifications
|
|
|
|
@objc func browserPreferenceDidChange() {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|