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

Rearrange Settings #872

Merged
merged 13 commits into from
Jan 30, 2024
18 changes: 17 additions & 1 deletion Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
031BF9552AB25AFB00F4517F /* SiteVersionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */; };
032109472AA7C3FC00912DFC /* CommunityLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032109462AA7C3FC00912DFC /* CommunityLabelView.swift */; };
032109492AA7C41800912DFC /* AvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032109482AA7C41800912DFC /* AvatarView.swift */; };
032C1E042B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032C1E032B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift */; };
032C1E062B5DBDB100FB4F23 /* LocalAccountSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032C1E052B5DBDB100FB4F23 /* LocalAccountSettingsView.swift */; };
032DD2FD2AC3594B00F1B33D /* LinkAttatchmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032DD2FC2AC3594B00F1B33D /* LinkAttatchmentView.swift */; };
034C724F2A82B61200B8A4B8 /* LayoutWidgetTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034C724E2A82B61200B8A4B8 /* LayoutWidgetTracker.swift */; };
035EB0CA2A8687C200227859 /* JumpButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035EB0C92A8687C200227859 /* JumpButtonView.swift */; };
Expand Down Expand Up @@ -588,6 +590,8 @@
031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVersionTests.swift; sourceTree = "<group>"; };
032109462AA7C3FC00912DFC /* CommunityLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityLabelView.swift; sourceTree = "<group>"; };
032109482AA7C41800912DFC /* AvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarView.swift; sourceTree = "<group>"; };
032C1E032B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickSwitcherSettingsView.swift; sourceTree = "<group>"; };
032C1E052B5DBDB100FB4F23 /* LocalAccountSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalAccountSettingsView.swift; sourceTree = "<group>"; };
032DD2FC2AC3594B00F1B33D /* LinkAttatchmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkAttatchmentView.swift; sourceTree = "<group>"; };
034C724E2A82B61200B8A4B8 /* LayoutWidgetTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutWidgetTracker.swift; sourceTree = "<group>"; };
035EB0C92A8687C200227859 /* JumpButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumpButtonView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1128,10 +1132,10 @@
isa = PBXGroup;
children = (
0308E1132B0EA32A000CA955 /* AccountSettingsView.swift */,
039C8DB62B35A32D0096BAAF /* AccountSwitcherSettingsView.swift */,
03A18CBA2B0FD6F000BA69D2 /* ProfileSettingsView.swift */,
031A617B2B1BDFD100ABF23B /* AdvancedAccountSettingsView.swift */,
03F4DC9E2B1A8AD500556C67 /* SignInAndSecuritySettingsView.swift */,
032C1E052B5DBDB100FB4F23 /* LocalAccountSettingsView.swift */,
031A617D2B1CE90F00ABF23B /* ChangePasswordView.swift */,
03F4DC9C2B193F4C00556C67 /* MatrixLinkView.swift */,
03F4DCA22B1A8B0400556C67 /* AccountGeneralSettingsView.swift */,
Expand Down Expand Up @@ -1310,6 +1314,15 @@
path = Community;
sourceTree = "<group>";
};
032C1E022B5D7D9C00FB4F23 /* AccountList */ = {
isa = PBXGroup;
children = (
039C8DB62B35A32D0096BAAF /* AccountSwitcherSettingsView.swift */,
032C1E032B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift */,
);
path = AccountList;
sourceTree = "<group>";
};
032CC9C52A844D8200322E2A /* LayoutWidgets */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1683,6 +1696,7 @@
63344C522A07D189001BC616 /* Views */ = {
isa = PBXGroup;
children = (
032C1E022B5D7D9C00FB4F23 /* AccountList */,
0308E1122B0EA31F000CA955 /* Account */,
030AC0432A62F82B00037155 /* General */,
03E79F3D2AE3E6FF0006700D /* Sorting */,
Expand Down Expand Up @@ -3101,6 +3115,7 @@
CD525F652A4B6D8F00BCA794 /* CommunityLinkView.swift in Sources */,
637218592A3A2AAD008C4816 /* APISiteAggregates.swift in Sources */,
50A881262A71A511003E3661 /* PersistenceRepository+Dependency.swift in Sources */,
032C1E062B5DBDB100FB4F23 /* LocalAccountSettingsView.swift in Sources */,
6DA7E9A22A50764E0095AB68 /* UserViewTab.swift in Sources */,
50785F732A98E03F00117245 /* SiteInformationTracker+Dependency.swift in Sources */,
CD863FBA2A6AEB5900A31ED9 /* View+FancyTabScrollCompatible.swift in Sources */,
Expand Down Expand Up @@ -3479,6 +3494,7 @@
637218552A3A2AAD008C4816 /* APITagline.swift in Sources */,
6322A5CB27F77A4D00135D4F /* Loading View.swift in Sources */,
03A1B3F72A84000400AB0DE0 /* APIContentAggregatesProtocol.swift in Sources */,
032C1E042B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift in Sources */,
CD4DBC032A6F803C001A1E61 /* ReplyToPost.swift in Sources */,
CD6483302A38D31C00EE6CA3 /* UpvoteCounterView.swift in Sources */,
032DD2FD2AC3594B00F1B33D /* LinkAttatchmentView.swift in Sources */,
Expand Down
4 changes: 1 addition & 3 deletions Mlem/App State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppState: ObservableObject {
@Dependency(\.apiClient) var apiClient

@AppStorage("defaultAccountId") var defaultAccountId: Int?
@AppStorage("profileTabLabel") var profileTabLabel: ProfileTabLabel = .username
@AppStorage("profileTabLabel") var profileTabLabel: ProfileTabLabel = .nickname
@AppStorage("showUserAvatarOnProfileTab") var showUserAvatar: Bool = true

@Published private(set) var currentActiveAccount: SavedAccount?
Expand All @@ -26,8 +26,6 @@ class AppState: ObservableObject {
}

switch profileTabLabel {
case .username:
return currentActiveAccount.username
case .instance:
return currentActiveAccount.hostName ?? "Instance"
case .nickname:
Expand Down
26 changes: 16 additions & 10 deletions Mlem/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ struct ContentView: View {
)
}
.sheet(isPresented: $isPresentingAccountSwitcher) {
QuickSwitcherView()
.presentationDetents([.medium, .large])
if accountsTracker.savedAccounts.count == 1 {
AddSavedInstanceView(onboarding: false)
} else {
QuickSwitcherView()
.presentationDetents([.medium, .large])
}
}
.sheet(item: $editorTracker.editResponse) { editing in
NavigationStack {
Expand Down Expand Up @@ -175,7 +179,7 @@ struct ContentView: View {
}

func showAccountSwitcherDragCallback() {
if !homeButtonExists, allowTabBarSwipeUpGesture, accountsTracker.savedAccounts.count > 2 {
if !homeButtonExists, allowTabBarSwipeUpGesture, accountsTracker.savedAccounts.count > 1 {
isPresentingAccountSwitcher = true
}
}
Expand All @@ -185,14 +189,16 @@ struct ContentView: View {
.onEnded { _ in
// disable long press in accessibility mode to prevent conflict with HUD
if !accessibilityFont {
if accountsTracker.savedAccounts.count > 2 {
hapticManager.play(haptic: .rigidInfo, priority: .high)
isPresentingAccountSwitcher = true
} else if accountsTracker.savedAccounts.count == 2 {
if UserDefaults.standard.bool(forKey: "allowQuickSwitcherLongPressGesture") {
hapticManager.play(haptic: .rigidInfo, priority: .high)
for account in accountsTracker.savedAccounts where account != appState.currentActiveAccount {
setFlow(.account(account))
break
if accountsTracker.savedAccounts.count == 2 {
hapticManager.play(haptic: .rigidInfo, priority: .high)
for account in accountsTracker.savedAccounts where account != appState.currentActiveAccount {
setFlow(.account(account))
break
}
} else {
isPresentingAccountSwitcher = true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mlem/Enums/Settings/ProfileTabLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

enum ProfileTabLabel: String {
case username, instance, nickname, anonymous
case nickname, instance, anonymous
}

extension ProfileTabLabel: SettingsOptions {
Expand Down
4 changes: 4 additions & 0 deletions Mlem/Extensions/View Modifiers/View+HandleLemmyLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct HandleLemmyLinksDisplay: ViewModifier {
SignInAndSecuritySettingsView()
case .accountGeneral:
AccountGeneralSettingsView()
case .accountLocal:
LocalAccountSettingsView()
case .accountAdvanced:
AdvancedAccountSettingsView()
case .accountDiscussionLanguages:
Expand All @@ -87,6 +89,8 @@ struct HandleLemmyLinksDisplay: ViewModifier {
MatrixLinkView()
case .accounts:
AccountSwitcherSettingsView()
case .quickSwitcher:
QuickSwitcherSettingsView()
case .general:
GeneralSettingsView()
case .sorting:
Expand Down
1 change: 0 additions & 1 deletion Mlem/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ enum Icons {
static let leftRight: String = "arrow.left.arrow.right"
static let developerMode: String = "wrench.adjustable.fill"
static let limitImageHeightSetting: String = "rectangle.compress.vertical"
static let swipeUpGestureSetting: String = "arrow.up.to.line.alt"
static let collapseComments: String = "arrow.down.and.line.horizontal.and.arrow.up"

// misc
Expand Down
2 changes: 1 addition & 1 deletion Mlem/Models/Saved Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SavedAccount: Identifiable, Codable, Equatable, Hashable {
let accessToken: String
var siteVersion: SiteVersion?
let username: String
let storedNickname: String?
var storedNickname: String?
let avatarUrl: URL?
var lastUsed: Date? // nil when loading SavedAccounts from before this was added

Expand Down
2 changes: 2 additions & 0 deletions Mlem/Navigation/Destination Values/SettingsValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ enum SettingsPage: DestinationValue {
case signInAndSecurity
case accountGeneral
case accountAdvanced
case accountLocal
case accountDiscussionLanguages
case linkMatrixAccount
case accounts
case quickSwitcher
case general
case sorting
case contentFilters
Expand Down
71 changes: 54 additions & 17 deletions Mlem/Views/Tabs/Settings/Components/Settings Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,18 @@ struct SelectableSettingsItem<T: SettingsOptions>: View {

struct SquircleLabelStyle: LabelStyle {
var color: Color
var fontSize: CGFloat = 14
let ios16FontSize: CGFloat = 17

/**
This computed property handles the fact that on iOS 17, the font size of 17 makes the icons too large. The code will not compile if fontSize itself is either absent or computed, so we define it above, compute an adjusted value here, and use the computed value.
*/
var adjustedFontSize: CGFloat {
if #available(iOS 17.0, *) {
return fontSize
} else {
return ios16FontSize
}
}
var fontSize: CGFloat = 17

func makeBody(configuration: Configuration) -> some View {
Label {
configuration.title
} icon: {
HStack(alignment: .center, spacing: 16) {
configuration.icon
.font(.system(size: adjustedFontSize))
.font(.system(size: fontSize))
.foregroundColor(.white)
.frame(width: AppConstants.settingsIconSize, height: AppConstants.settingsIconSize)
.background(color)
.clipShape(RoundedRectangle(cornerRadius: AppConstants.smallItemCornerRadius))
.accessibilityHidden(true)
configuration.title
}
}
}
Expand All @@ -109,6 +97,55 @@ struct SettingsButtonStyle: ButtonStyle {
}
}

struct FooterLinkView: View {
let title: String
let destination: AppRoute

var body: some View {
NavigationLink(destination) {
HStack(spacing: 3) {
Text(title)
Image(systemName: Icons.forward)
.fontWeight(.semibold)
.imageScale(.small)
}
.font(.footnote)
}
}
}

struct CheckboxToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.label
Spacer()
Checkbox(isOn: configuration.isOn)
.animation(.default, value: configuration.isOn)
}
.onTapGesture {
configuration.isOn.toggle()
}
}
}

struct Checkbox: View {
let isOn: Bool

var body: some View {
VStack {
if isOn {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.white, .blue)
.imageScale(.large)
} else {
Image(systemName: "circle")
.foregroundStyle(Color(uiColor: .tertiaryLabel))
.imageScale(.large)
}
}
}
}

struct SettingsPickerButton<PickerLabel: View>: View {
@Binding var isOn: Bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct AccountGeneralSettingsView: View {
}
}
}
} footer: {
Text("Show content flagged as Not Safe For Work.")
}
Section {
SwitchableSettingsItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ struct AccountSettingsView: View {
}
.disabled(settingsDisabled)

Section {
NavigationLink(.settings(.accountLocal)) {
Label("Local Options", systemImage: "iphone.gen3")
.labelStyle(SquircleLabelStyle(color: .blue))
}
} footer: {
Text("These options are stored locally in Mlem and not on your Lemmy account.")
}

// Section {
// NavigationLink { EmptyView() } label: {
// Label("Blocked Commuities", systemImage: "house.fill").labelStyle(SquircleLabelStyle(color: .gray))
Expand Down Expand Up @@ -122,6 +131,9 @@ struct AccountSettingsView: View {
accountForDeletion = appState.currentActiveAccount
}
.frame(maxWidth: .infinity)
.sheet(item: $accountForDeletion) { account in
DeleteAccountView(account: account)
}
}

} else {
Expand All @@ -131,8 +143,5 @@ struct AccountSettingsView: View {
.navigationTitle("Account Settings")
.fancyTabScrollCompatible()
.hoistNavigation()
.sheet(item: $accountForDeletion) { account in
DeleteAccountView(account: account)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct AdvancedAccountSettingsView: View {
}
}
}
} footer: {
Text("Bot accounts cannot vote on posts.")
}
}
.navigationTitle("Advanced")
Expand Down
Loading
Loading