Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FXIOS-9353 #20714 Improving BVC viewDidLoad #24487

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class BrowserViewController: UIViewController,
let navigationViewProvider = ContextualHintViewProvider(forHintType: .navigation, with: profile)

self.navigationContextHintVC = ContextualHintViewController(with: navigationViewProvider, windowUUID: windowUUID)
self.searchTelemetry = SearchTelemetry(tabManager: tabManager)

super.init(nibName: nil, bundle: nil)
didInit()
Expand Down Expand Up @@ -746,35 +747,20 @@ class BrowserViewController: UIViewController,

override func viewDidLoad() {
super.viewDidLoad()
KeyboardHelper.defaultHelper.addDelegate(self)
trackTelemetry()
setupNotifications()
addSubviews()
listenForThemeChange(view)
setupAccessibleActions()

clipboardBarDisplayHandler = ClipboardBarDisplayHandler(prefs: profile.prefs, tabManager: tabManager)
clipboardBarDisplayHandler?.delegate = self

navigationToolbarContainer.toolbarDelegate = self

scrollController.header = header
scrollController.overKeyboardContainer = overKeyboardContainer
scrollController.bottomContainer = bottomContainer
setupEssentialUI()
subscribeToRedux()

updateToolbarStateForTraitCollection(traitCollection)
Task(priority: .background) {
// App startup telemetry accesses RustLogins to queryLogins, shouldn't be on the app startup critical path
self.trackStartupTelemetry()
}
}

private func setupEssentialUI() {
addSubviews()
setupConstraints()

// Setup UIDropInteraction to handle dragging and dropping
// links into the view from other apps.
let dropInteraction = UIDropInteraction(delegate: self)
view.addInteraction(dropInteraction)

searchTelemetry = SearchTelemetry(tabManager: tabManager)

// Awesomebar Location Telemetry
SearchBarSettingsViewModel.recordLocationTelemetry(for: isBottomSearchBar ? .bottom : .top)
setupNotifications()

overlayManager.setURLBar(urlBarView: urlBarView)

Expand All @@ -787,20 +773,31 @@ class BrowserViewController: UIViewController,
statusBarOverlay.hasTopTabs = ToolbarHelper().shouldShowTopTabs(for: traitCollection)
statusBarOverlay.applyTheme(theme: theme)

KeyboardHelper.defaultHelper.addDelegate(self)
listenForThemeChange(view)
setupAccessibleActions()

clipboardBarDisplayHandler = ClipboardBarDisplayHandler(prefs: profile.prefs,
tabManager: tabManager)
clipboardBarDisplayHandler?.delegate = self

navigationToolbarContainer.toolbarDelegate = self
scrollController.header = header
scrollController.overKeyboardContainer = overKeyboardContainer
scrollController.bottomContainer = bottomContainer

// Setup UIDropInteraction to handle dragging and dropping
// links into the view from other apps.
let dropInteraction = UIDropInteraction(delegate: self)
view.addInteraction(dropInteraction)

// Feature flag for credit card until we fully enable this feature
let autofillCreditCardStatus = featureFlags.isFeatureEnabled(
.creditCardAutofillStatus, checking: .buildOnly)
// We need to update autofill status on sync manager as there could be delay from nimbus
// in getting the value. When the delay happens the credit cards might not sync
// as the default value is false
profile.syncManager?.updateCreditCardAutofillStatus(value: autofillCreditCardStatus)
// Credit card initial setup telemetry
creditCardInitialSetupTelemetry()

// Send settings telemetry for Fakespot
FakespotUtils().addSettingTelemetry()

subscribeToRedux()
}

private func setupAccessibleActions() {
Expand Down Expand Up @@ -4358,10 +4355,14 @@ extension BrowserViewController: DevicePickerViewControllerDelegate, Instruction
}

extension BrowserViewController {
func trackTelemetry() {
func trackStartupTelemetry() {
let toolbarLocation: SearchBarPosition = self.isBottomSearchBar ? .bottom : .top
SearchBarSettingsViewModel.recordLocationTelemetry(for: toolbarLocation)
trackAccessibility()
trackNotificationPermission()
appStartupTelemetry.sendStartupTelemetry()
creditCardInitialSetupTelemetry()
FakespotUtils().addSettingTelemetry()
}

func trackAccessibility() {
Expand Down Expand Up @@ -4397,15 +4398,17 @@ extension BrowserViewController {
extras: [Key.isInvertColorsEnabled.rawValue: UIAccessibility.isInvertColorsEnabled.description]
)

let a11yEnabled = UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory.description
let a11yCategory = UIApplication.shared.preferredContentSizeCategory.rawValue.description
TelemetryWrapper.recordEvent(
category: .action,
method: .dynamicTextSize,
object: .app,
extras: [Key.isAccessibilitySizeEnabled.rawValue: a11yEnabled,
Key.preferredContentSizeCategory.rawValue: a11yCategory]
)
ensureMainThread {
let a11yEnabled = UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory.description
let a11yCategory = UIApplication.shared.preferredContentSizeCategory.rawValue.description
TelemetryWrapper.recordEvent(
category: .action,
method: .dynamicTextSize,
object: .app,
extras: [Key.isAccessibilitySizeEnabled.rawValue: a11yEnabled,
Key.preferredContentSizeCategory.rawValue: a11yCategory]
)
}
}

func trackNotificationPermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Shared
/// Data source for handling LoginData objects from a Cursor
class LoginDataSource: NSObject, UITableViewDataSource {
// in case there are no items to run cellForRowAt on, use an empty state view
private let emptyStateView = NoLoginsView()
private lazy var emptyStateView = NoLoginsView()
var viewModel: PasswordManagerViewModel

let boolSettings: (BoolSetting, BoolSetting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class PasswordManagerViewModel {
var hasLoadedBreaches = false
var theme: Theme

init(profile: Profile, searchController: UISearchController, theme: Theme, loginProvider: LoginProvider) {
init(profile: Profile, searchController: UISearchController?, theme: Theme, loginProvider: LoginProvider) {
self.profile = profile
self.searchController = searchController
self.theme = theme
Expand Down
3 changes: 1 addition & 2 deletions firefox-ios/Client/Telemetry/AppStartupTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ final class AppStartupTelemetry {

// MARK: Logins
func queryLogins() {
let searchController = UISearchController()
let loginsViewModel = PasswordManagerViewModel(
profile: profile,
searchController: searchController,
searchController: nil,
theme: LightTheme(),
loginProvider: profile.logins
)
Expand Down