Remote tabs: finishing touches

This commit is contained in:
James Magahern
2022-08-05 18:55:19 -07:00
parent 61773b97db
commit e8c6111592
11 changed files with 273 additions and 62 deletions

View File

@@ -28,6 +28,30 @@ struct LabelContentConfiguration : UIContentConfiguration
}
}
struct TextFieldContentConfiguration : UIContentConfiguration
{
var text: String = ""
var placeholderText: String? = nil
var textChanged: ((String) -> Void)
func makeContentView() -> UIView & UIContentView {
let textField = UITextField(frame: .zero)
textField.borderStyle = .roundedRect
textField.autocorrectionType = .no
textField.autocapitalizationType = .none
return GenericContentView<UITextField, TextFieldContentConfiguration>(configuration: self, view: textField) { config, textField in
textField.text = config.text
textField.placeholder = config.placeholderText
textField.addAction(UIAction { _ in config.textChanged(textField.text ?? "") }, for: .editingChanged)
}
}
func updated(for state: UIConfigurationState) -> TextFieldContentConfiguration {
self
}
}
struct ButtonContentConfiguration : UIContentConfiguration
{
var menu: UIMenu
@@ -56,11 +80,13 @@ class GeneralSettingsViewController: UIViewController
{
enum Section: String, CaseIterable {
case searchEngine = "Search Engine"
case syncServer = "Sync Server"
}
typealias Item = String
static let SearchProviderPopupItem = "searchProvider.popup"
static let SyncServerItem = "syncServer.field"
let dataSource: UICollectionViewDiffableDataSource<Section, Item>
let collectionView: UICollectionView
@@ -109,7 +135,7 @@ class GeneralSettingsViewController: UIViewController
if idiom == .mac {
return LabelContentConfiguration(
text: sectionName + ": ",
insets: UIEdgeInsets(top: 0, left: 10.0, bottom: 0, right: 10.0),
insets: UIEdgeInsets(top: 0.0, left: 10.0, bottom: 0, right: 10.0),
textAlignment: .right
)
} else {
@@ -141,11 +167,19 @@ class GeneralSettingsViewController: UIViewController
})
cell.contentConfiguration = ButtonContentConfiguration(menu: menu)
#if !targetEnvironment(macCatalyst)
cell.backgroundConfiguration = UIBackgroundConfiguration.listGroupedCell()
#endif
} else if identifier == Self.SyncServerItem {
cell.contentConfiguration = TextFieldContentConfiguration(
text: Settings.shared.syncServer,
placeholderText: "https://sync.server.com",
textChanged: { newString in
Settings.shared.syncServer = newString
}
)
}
#if !targetEnvironment(macCatalyst)
cell.backgroundConfiguration = UIBackgroundConfiguration.listGroupedCell()
#endif
}
let sectionHeaderRegistry = UICollectionView.SupplementaryRegistration<UICollectionViewCell>(elementKind: UICollectionView.elementKindSectionHeader, handler: {
@@ -189,6 +223,7 @@ class GeneralSettingsViewController: UIViewController
// iOS
// snapshot.appendItems(Settings.SearchProviderSetting.allCases.map { $0.rawValue }, toSection: .searchEngine)
snapshot.appendItems([ Self.SearchProviderPopupItem ], toSection: .searchEngine)
snapshot.appendItems([ Self.SyncServerItem ], toSection: .syncServer)
dataSource.apply(snapshot, animatingDifferences: false)
}

View File

@@ -105,4 +105,7 @@ class Settings
@SettingProperty(key: "userStylesheet")
public var userStylesheet: String = ""
@SettingProperty(key: "syncServer")
public var syncServer: String = "https://attractor.severnaya.net"
}