Skip to content

Commit

Permalink
Unify naming
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 committed Jul 29, 2024
1 parent b1b307f commit cd7850b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 65 deletions.
37 changes: 17 additions & 20 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@
6F03CB092C32F331004179A8 /* PixelFiringAsync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F03CB082C32F331004179A8 /* PixelFiringAsync.swift */; };
6F0FEF6B2C516D540090CDE4 /* NewTabPageSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F0FEF6A2C516D540090CDE4 /* NewTabPageSettingsStorage.swift */; };
6F0FEF6D2C52639E0090CDE4 /* ReorderableForEach.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F0FEF6C2C52639E0090CDE4 /* ReorderableForEach.swift */; };
6F35379E2C4AAF2E009F8717 /* NewTabPagePreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379D2C4AAF2E009F8717 /* NewTabPagePreferencesView.swift */; };
6F3537A02C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */; };
6F3537A22C4AB97A009F8717 /* NewTabPagePreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */; };
6F3537A02C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */; };
6F35379E2C4AAF2E009F8717 /* NewTabPageSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */; };
6F3537A02C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */; };
6F3537A22C4AB97A009F8717 /* NewTabPageSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */; };
6F3537A42C4AC140009F8717 /* NTPDaxLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A32C4AC140009F8717 /* NTPDaxLogoView.swift */; };
6F40D15B2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */; };
6F40D15E2C34436500BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */; };
Expand All @@ -280,9 +279,9 @@
6F96FF102C2B128500162692 /* NewTabPageCustomizeButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F96FF0F2C2B128500162692 /* NewTabPageCustomizeButtonView.swift */; };
6F9FFE262C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE252C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift */; };
6F9FFE282C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE272C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift */; };
6F9FFE2A2C57ADB100A238BE /* EditableShortcutsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */; };
6F9FFE2D2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */; };
6F9FFE302C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */; };
6F9FFE2A2C57ADB100A238BE /* EditableShortcutsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */; };
6FA3438F2C3D3BC300470677 /* Favorite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FA3438E2C3D3BC300470677 /* Favorite.swift */; };
6FA343922C3D3C3B00470677 /* FavoriteIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FA343912C3D3C3B00470677 /* FavoriteIconView.swift */; };
6FB1FE9E2C24D41D0075B68B /* NewTabPageSectionsDebugView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB1FE9D2C24D41D0075B68B /* NewTabPageSectionsDebugView.swift */; };
Expand Down Expand Up @@ -1427,10 +1426,9 @@
6F03CB082C32F331004179A8 /* PixelFiringAsync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelFiringAsync.swift; sourceTree = "<group>"; };
6F0FEF6A2C516D540090CDE4 /* NewTabPageSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsStorage.swift; sourceTree = "<group>"; };
6F0FEF6C2C52639E0090CDE4 /* ReorderableForEach.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableForEach.swift; sourceTree = "<group>"; };
6F35379D2C4AAF2E009F8717 /* NewTabPagePreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPagePreferencesView.swift; sourceTree = "<group>"; };
6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NTPPreferencesSectionItemView.swift; sourceTree = "<group>"; };
6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPagePreferencesModel.swift; sourceTree = "<group>"; };
6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NTPPreferencesSectionItemView.swift; sourceTree = "<group>"; };
6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsView.swift; sourceTree = "<group>"; };
6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsSectionItemView.swift; sourceTree = "<group>"; };
6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsModel.swift; sourceTree = "<group>"; };
6F3537A32C4AC140009F8717 /* NTPDaxLogoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NTPDaxLogoView.swift; sourceTree = "<group>"; };
6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucket.swift; sourceTree = "<group>"; };
6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucketTests.swift; sourceTree = "<group>"; };
Expand All @@ -1447,9 +1445,9 @@
6F96FF0F2C2B128500162692 /* NewTabPageCustomizeButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageCustomizeButtonView.swift; sourceTree = "<group>"; };
6F9FFE252C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcutsSettingsStorage.swift; sourceTree = "<group>"; };
6F9FFE272C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSectionsSettingsStorage.swift; sourceTree = "<group>"; };
6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditableShortcutsView.swift; sourceTree = "<group>"; };
6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcutsSettingsModel.swift; sourceTree = "<group>"; };
6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSectionsSettingsModel.swift; sourceTree = "<group>"; };
6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditableShortcutsView.swift; sourceTree = "<group>"; };
6FA3438E2C3D3BC300470677 /* Favorite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Favorite.swift; sourceTree = "<group>"; };
6FA343912C3D3C3B00470677 /* FavoriteIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteIconView.swift; sourceTree = "<group>"; };
6FB030C7234331B400A10DB9 /* Configuration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Configuration.xcconfig; path = Configuration/Configuration.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3524,14 +3522,14 @@
name = NewTabPage;
sourceTree = "<group>";
};
6F35379C2C4AAF1C009F8717 /* Preferences */ = {
6F35379C2C4AAF1C009F8717 /* Settings */ = {
isa = PBXGroup;
children = (
6F9FFE2E2C57B14100A238BE /* Model */,
6F9FFE2B2C57AE4200A238BE /* Storage */,
6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */,
6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */,
);
name = Preferences;
name = Settings;
sourceTree = "<group>";
};
6F691CC82C4979DD002E9553 /* Tooltip */ = {
Expand All @@ -3549,8 +3547,7 @@
6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */,
6F9FFE252C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift */,
6F9FFE272C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift */,
6F35379D2C4AAF2E009F8717 /* NewTabPagePreferencesView.swift */,
6F35379F2C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift */,
6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */,
);
name = Storage;
sourceTree = "<group>";
Expand All @@ -3560,7 +3557,7 @@
children = (
6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */,
6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */,
6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */,
6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -3631,7 +3628,7 @@
6FE1273B2C204C0D00EB5724 /* Subviews */ = {
isa = PBXGroup;
children = (
6F35379C2C4AAF1C009F8717 /* Preferences */,
6F35379C2C4AAF1C009F8717 /* Settings */,
6FE127472C20941A00EB5724 /* Shortcuts */,
6FE127412C204DE900EB5724 /* Favorites */,
6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonView.swift */,
Expand Down Expand Up @@ -6960,7 +6957,7 @@
83BE9BC3215D69C1009844D9 /* AppConfigurationFetch.swift in Sources */,
37CF91622BB474AA00BADCAE /* CrashCollectionOnboardingView.swift in Sources */,
1EEC460627A9499600E75FCB /* DownloadsList.swift in Sources */,
6F3537A22C4AB97A009F8717 /* NewTabPagePreferencesModel.swift in Sources */,
6F3537A22C4AB97A009F8717 /* NewTabPageSettingsModel.swift in Sources */,
9F23B8032C2BCD0000950875 /* DaxDialogStyles.swift in Sources */,
C1641EAF2BC2F5140012607A /* ImportPasswordsViewController.swift in Sources */,
D63FF8982C1B6A45006DE24D /* DuckPlayer.swift in Sources */,
Expand Down Expand Up @@ -7115,7 +7112,7 @@
311BD1AD2836BB3900AEF6C1 /* AutofillItemsEmptyView.swift in Sources */,
C1F341C52A6924000032057B /* EmailAddressPromptView.swift in Sources */,
316931D727BD10BB0095F5ED /* SaveToDownloadsAlert.swift in Sources */,
6F35379E2C4AAF2E009F8717 /* NewTabPagePreferencesView.swift in Sources */,
6F35379E2C4AAF2E009F8717 /* NewTabPageSettingsView.swift in Sources */,
31C70B5B2804C61000FB6AD1 /* SaveAutofillLoginManager.swift in Sources */,
982123502B6D233E00F08C57 /* UserSession.swift in Sources */,
85449EFD23FDA71F00512AAF /* KeyboardSettings.swift in Sources */,
Expand Down Expand Up @@ -7292,7 +7289,7 @@
CBD4F13F279EBFAF00B20FD7 /* HomeMessageViewModel.swift in Sources */,
1E4DCF4A27B6A38000961E25 /* DownloadListRepresentable.swift in Sources */,
1DEAADFB2BA71E9A00E25A97 /* SettingsPrivacyProtectionDescriptionView.swift in Sources */,
6F3537A02C4AAFD2009F8717 /* NTPPreferencesSectionItemView.swift in Sources */,
6F3537A02C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift in Sources */,
2DC3FC65C6D9DA634426672D /* AutofillNoAuthAvailableView.swift in Sources */,
6F03CAFC2C32C6F6004179A8 /* NewTabPageMessagesModel.swift in Sources */,
);
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/EditableShortcutsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ private extension View {
}
}

extension NewTabPagePreferencesModel.NTPSetting<NewTabPageShortcut>: Reorderable, Hashable, Equatable {
extension NewTabPageSettingsModel.NTPSetting<NewTabPageShortcut>: Reorderable, Hashable, Equatable {

var dropItemProvider: NSItemProvider {
NSItemProvider(object: item.id as NSString)
}

var dropType: UTType { .text }

static func == (lhs: NewTabPagePreferencesModel.NTPSetting<Item>, rhs: NewTabPagePreferencesModel.NTPSetting<Item>) -> Bool {
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.item == rhs.item
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/NewTabPageSectionsSettingsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import Foundation

typealias NewTabPageSectionsSettingsModel = NewTabPagePreferencesModel<NewTabPageSection, NewTabPageSectionsSettingsStorage>
typealias NewTabPageSectionsSettingsModel = NewTabPageSettingsModel<NewTabPageSection, NewTabPageSectionsSettingsStorage>

extension NewTabPageSectionsSettingsModel {
convenience init(storage: NewTabPageSectionsSettingsStorage = NewTabPageSectionsSettingsStorage()) {
self.init(preferencesStorage: storage)
self.init(settingsStorage: storage)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NewTabPagePreferencesModel.swift
// NewTabPageSettingsModel.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
Expand All @@ -20,29 +20,29 @@
import Foundation
import SwiftUI

final class NewTabPagePreferencesModel<SettingItem: NewTabPageSettingsStorageItem, Storage: NewTabPageSettingsStorage>: ObservableObject where Storage.SettingItem == SettingItem {
final class NewTabPageSettingsModel<SettingItem: NewTabPageSettingsStorageItem, Storage: NewTabPageSettingsStorage>: ObservableObject where Storage.SettingItem == SettingItem {

/// Preferences page settings collection with bindings
/// Settings page settings collection with bindings
@Published private(set) var itemsSettings: [NTPSetting<SettingItem>] = []

/// Enabled items, ordered.
@Published private(set) var enabledItems: [SettingItem] = []

private let preferencesStorage: Storage
private let settingsStorage: Storage

init(preferencesStorage: Storage) {
self.preferencesStorage = preferencesStorage
init(settingsStorage: Storage) {
self.settingsStorage = settingsStorage

updatePublishedValues()
}

func moveItems(from: IndexSet, to: Int) {
preferencesStorage.moveItems(from, toOffset: to)
settingsStorage.moveItems(from, toOffset: to)
updatePublishedValues()
}

func save() {
preferencesStorage.save()
settingsStorage.save()
}

private func updatePublishedValues() {
Expand All @@ -51,22 +51,22 @@ final class NewTabPagePreferencesModel<SettingItem: NewTabPageSettingsStorageIte
}

private func populateEnabledItems() {
enabledItems = preferencesStorage.enabledItems
enabledItems = settingsStorage.enabledItems
}

private func populateSettings() {
itemsSettings = preferencesStorage.itemsOrder.map { item in
itemsSettings = settingsStorage.itemsOrder.map { item in
NTPSetting(item: item, isEnabled: Binding(get: {
self.preferencesStorage.isEnabled(item)
self.settingsStorage.isEnabled(item)
}, set: { newValue in
self.preferencesStorage.setItem(item, enabled: newValue)
self.settingsStorage.setItem(item, enabled: newValue)
self.updatePublishedValues()
}))
}
}
}

extension NewTabPagePreferencesModel {
extension NewTabPageSettingsModel {
struct NTPSetting<Item> {
let item: Item
let isEnabled: Binding<Bool>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NTPPreferencesSectionItemView.swift
// NewTabPageSettingsSectionItemView.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
Expand All @@ -19,7 +19,7 @@

import SwiftUI

struct NTPPreferencesSectionItemView: View {
struct NewTabPageSettingsSectionItemView: View {

let title: String
let iconResource: ImageResource
Expand All @@ -43,5 +43,5 @@ struct NTPPreferencesSectionItemView: View {

#Preview {
@State var isEnabled: Bool = false
return NTPPreferencesSectionItemView(title: "Foo", iconResource: .favorite24, isEnabled: $isEnabled).fixedSize(horizontal: false, vertical: true)
return NewTabPageSettingsSectionItemView(title: "Foo", iconResource: .favorite24, isEnabled: $isEnabled).fixedSize(horizontal: false, vertical: true)
}
Loading

0 comments on commit cd7850b

Please sign in to comment.