Skip to content

Commit

Permalink
inject fireproofing into settings view and tidy up settings view prov…
Browse files Browse the repository at this point in the history
…ider a little
  • Loading branch information
brindy committed Nov 20, 2024
1 parent f6a9414 commit 7337e26
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
12 changes: 10 additions & 2 deletions DuckDuckGo/FireproofingSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ class FireproofingSettingsViewController: UITableViewController {
var model = [String]()
private var shouldShowRemoveAll = false

// TODO inject this
private let fireproofing: Fireproofing = UserDefaultsFireproofing.shared
private let fireproofing: Fireproofing

init?(coder: NSCoder, fireproofing: Fireproofing) {
self.fireproofing = fireproofing
super.init(coder: coder)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
refreshModel()
Expand Down
46 changes: 32 additions & 14 deletions DuckDuckGo/SettingsLegacyViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,34 @@ import Common

class SettingsLegacyViewProvider: ObservableObject {

enum StoryboardName {
static let settings = "Settings"
static let homeRow = "HomeRow"
static let feedback = "Feedback"
}

let syncService: DDGSyncing
let syncDataProviders: SyncDataProviders
let appSettings: AppSettings
let bookmarksDatabase: CoreDataDatabase
let tabManager: TabManager
let syncPausedStateManager: any SyncPausedStateManaging
let fireproofing: Fireproofing

init(syncService: any DDGSyncing,
syncDataProviders: SyncDataProviders,
appSettings: any AppSettings,
bookmarksDatabase: CoreDataDatabase,
tabManager: TabManager,
syncPausedStateManager: any SyncPausedStateManaging) {
syncPausedStateManager: any SyncPausedStateManaging,
fireproofing: Fireproofing = UserDefaultsFireproofing.shared) {
self.syncService = syncService
self.syncDataProviders = syncDataProviders
self.appSettings = appSettings
self.bookmarksDatabase = bookmarksDatabase
self.tabManager = tabManager
self.syncPausedStateManager = syncPausedStateManager
self.fireproofing = fireproofing
}

enum LegacyView {
Expand All @@ -63,28 +72,37 @@ class SettingsLegacyViewProvider: ObservableObject {
feedback,
debug
}

private func instantiate(_ identifier: String, fromStoryboard name: String) -> UIViewController {
let storyboard = UIStoryboard(name: name, bundle: nil)
return storyboard.instantiateViewController(withIdentifier: identifier)
}

// Legacy UIKit Views (Pushed unmodified)
var addToDock: UIViewController { instantiate( "instructions", fromStoryboard: "HomeRow") }
var appIcon: UIViewController { instantiate("AppIcon", fromStoryboard: "Settings") }
var gpc: UIViewController { instantiate("DoNotSell", fromStoryboard: "Settings") }
var autoConsent: UIViewController { instantiate("AutoconsentSettingsViewController", fromStoryboard: "Settings") }
var unprotectedSites: UIViewController { instantiate("UnprotectedSites", fromStoryboard: "Settings") }
var fireproofSites: UIViewController { instantiate("FireProofSites", fromStoryboard: "Settings") }
var keyboard: UIViewController { instantiate("Keyboard", fromStoryboard: "Settings") }
var feedback: UIViewController { instantiate("Feedback", fromStoryboard: "Feedback") }
var autoclearData: UIViewController {
let storyboard = UIStoryboard(name: "Settings", bundle: nil)

private func instantiateFireproofingController() -> UIViewController {
let storyboard = UIStoryboard(name: StoryboardName.settings, bundle: nil)
return storyboard.instantiateViewController(identifier: "FireProofSites") { coder in
return FireproofingSettingsViewController(coder: coder, fireproofing: self.fireproofing)
}
}

private func instantiateAutoClearController() -> UIViewController {
let storyboard = UIStoryboard(name: StoryboardName.settings, bundle: nil)
return storyboard.instantiateViewController(identifier: "AutoClearSettingsViewController", creator: { coder in
return AutoClearSettingsViewController(appSettings: self.appSettings, coder: coder)
})
}

// Legacy UIKit Views (Pushed unmodified)
var addToDock: UIViewController { instantiate( "instructions", fromStoryboard: StoryboardName.homeRow) }
var appIcon: UIViewController { instantiate("AppIcon", fromStoryboard: StoryboardName.settings) }
var gpc: UIViewController { instantiate("DoNotSell", fromStoryboard: StoryboardName.settings) }
var autoConsent: UIViewController { instantiate("AutoconsentSettingsViewController", fromStoryboard: StoryboardName.settings) }
var unprotectedSites: UIViewController { instantiate("UnprotectedSites", fromStoryboard: StoryboardName.settings) }
var fireproofSites: UIViewController { instantiateFireproofingController() }
var keyboard: UIViewController { instantiate("Keyboard", fromStoryboard: StoryboardName.settings) }
var feedback: UIViewController { instantiate("Feedback", fromStoryboard: StoryboardName.feedback) }
var autoclearData: UIViewController { instantiateAutoClearController() }

@MainActor
func syncSettings(source: String? = nil) -> SyncSettingsViewController {
return SyncSettingsViewController(syncService: self.syncService,
Expand Down

0 comments on commit 7337e26

Please sign in to comment.