#52 Hide already selected menu items

This commit is contained in:
Marcin Czachurski 2023-04-21 16:58:52 +02:00
parent f2efbaa47e
commit 76e0e4cc5f
8 changed files with 146 additions and 96 deletions

View File

@ -165,21 +165,21 @@ class ApplicationSettingsHandler {
CoreDataHandler.shared.save()
}
func set(customNavigationMenuItem1: Int32) {
func set(customNavigationMenuItem1: Int) {
let defaultSettings = self.get()
defaultSettings.customNavigationMenuItem1 = customNavigationMenuItem1
defaultSettings.customNavigationMenuItem1 = Int32(customNavigationMenuItem1)
CoreDataHandler.shared.save()
}
func set(customNavigationMenuItem2: Int32) {
func set(customNavigationMenuItem2: Int) {
let defaultSettings = self.get()
defaultSettings.customNavigationMenuItem2 = customNavigationMenuItem2
defaultSettings.customNavigationMenuItem2 = Int32(customNavigationMenuItem2)
CoreDataHandler.shared.save()
}
func set(customNavigationMenuItem3: Int32) {
func set(customNavigationMenuItem3: Int) {
let defaultSettings = self.get()
defaultSettings.customNavigationMenuItem3 = customNavigationMenuItem3
defaultSettings.customNavigationMenuItem3 = Int32(customNavigationMenuItem3)
CoreDataHandler.shared.save()
}

View File

@ -40,6 +40,7 @@
F85D4DFE29B78C8400345267 /* HashtagModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85D4DFD29B78C8400345267 /* HashtagModel.swift */; };
F85DBF8F296732E20069BF89 /* AccountsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85DBF8E296732E20069BF89 /* AccountsView.swift */; };
F86167C6297FE6CC004D1F67 /* AvatarShapesSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86167C5297FE6CC004D1F67 /* AvatarShapesSectionView.swift */; };
F8624D3D29F2D3AC00204986 /* SelectedMenuItemDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8624D3C29F2D3AC00204986 /* SelectedMenuItemDetails.swift */; };
F864F75F29BB91B400B13921 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F864F75E29BB91B400B13921 /* WidgetKit.framework */; };
F864F76129BB91B400B13921 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F864F76029BB91B400B13921 /* SwiftUI.framework */; };
F864F76429BB91B400B13921 /* VernissageWidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F864F76329BB91B400B13921 /* VernissageWidgetBundle.swift */; };
@ -248,6 +249,7 @@
F85D4DFD29B78C8400345267 /* HashtagModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagModel.swift; sourceTree = "<group>"; };
F85DBF8E296732E20069BF89 /* AccountsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsView.swift; sourceTree = "<group>"; };
F86167C5297FE6CC004D1F67 /* AvatarShapesSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarShapesSectionView.swift; sourceTree = "<group>"; };
F8624D3C29F2D3AC00204986 /* SelectedMenuItemDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedMenuItemDetails.swift; sourceTree = "<group>"; };
F864F75D29BB91B400B13921 /* VernissageWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = VernissageWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
F864F75E29BB91B400B13921 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
F864F76029BB91B400B13921 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
@ -489,6 +491,7 @@
F89F57AF29D1C11200001EE3 /* RelationshipModel.swift */,
F8DF38E329DD68820047F1AA /* ViewOffsetKey.swift */,
F871F21C29EF0D7000A351EF /* NavigationMenuItemDetails.swift */,
F8624D3C29F2D3AC00204986 /* SelectedMenuItemDetails.swift */,
);
path = Models;
sourceTree = "<group>";
@ -1077,6 +1080,7 @@
F805DCF129DBEF83006A1FD9 /* ReportView.swift in Sources */,
F8B0886029943498002AB40A /* OtherSectionView.swift in Sources */,
F808641429756666009F035C /* NotificationRowView.swift in Sources */,
F8624D3D29F2D3AC00204986 /* SelectedMenuItemDetails.swift in Sources */,
F8210DDD2966CF17001D9973 /* StatusData+Status.swift in Sources */,
F8210DCF2966B600001D9973 /* ImageRowAsync.swift in Sources */,
F85D498329642FAC00751DF7 /* AttachmentData+Comperable.swift in Sources */,
@ -1191,7 +1195,7 @@
CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_TEAM = B2U9FEKYP8;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VernissageWidget/Info.plist;
@ -1202,7 +1206,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.widget;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -1219,7 +1223,7 @@
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_TEAM = B2U9FEKYP8;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VernissageWidget/Info.plist;
@ -1230,7 +1234,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.widget;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -1246,7 +1250,7 @@
CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_TEAM = B2U9FEKYP8;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VernissageShare/Info.plist;
@ -1258,7 +1262,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.share;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -1273,7 +1277,7 @@
buildSettings = {
CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_TEAM = B2U9FEKYP8;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VernissageShare/Info.plist;
@ -1285,7 +1289,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage.share;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -1422,7 +1426,7 @@
CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\"";
DEVELOPMENT_TEAM = B2U9FEKYP8;
ENABLE_PREVIEWS = YES;
@ -1440,7 +1444,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -1463,7 +1467,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 124;
CURRENT_PROJECT_VERSION = 125;
DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\"";
DEVELOPMENT_TEAM = B2U9FEKYP8;
ENABLE_PREVIEWS = YES;
@ -1481,7 +1485,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.6.0;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.mczachurski.vernissage;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

View File

@ -8,7 +8,8 @@ import Foundation
import SwiftUI
class NavigationMenuItemDetails: ObservableObject, Identifiable {
let id: Int32
@Published var title: LocalizedStringKey
@Published var image: String
@Published var viewMode: MainView.ViewMode {
didSet {
@ -17,11 +18,7 @@ class NavigationMenuItemDetails: ObservableObject, Identifiable {
}
}
@Published var title: LocalizedStringKey
@Published var image: String
init(id: Int32, viewMode: MainView.ViewMode) {
self.id = id
init(viewMode: MainView.ViewMode) {
self.viewMode = viewMode
self.title = viewMode.title
self.image = viewMode.image

View File

@ -0,0 +1,16 @@
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the Apache License 2.0.
//
import Foundation
class SelectedMenuItemDetails: NavigationMenuItemDetails {
public let position: Int
init(position: Int, viewMode: MainView.ViewMode) {
self.position = position
super.init(viewMode: viewMode)
}
}

View File

@ -23,20 +23,22 @@ private struct NavigationMenuButtons: ViewModifier {
private let imageFontSize = 20.0
private let customMenuItems = [
NavigationMenuItemDetails(id: 1, viewMode: .home),
NavigationMenuItemDetails(id: 2, viewMode: .local),
NavigationMenuItemDetails(id: 3, viewMode: .federated),
NavigationMenuItemDetails(id: 4, viewMode: .search),
NavigationMenuItemDetails(id: 5, viewMode: .profile),
NavigationMenuItemDetails(id: 6, viewMode: .notifications)
NavigationMenuItemDetails(viewMode: .home),
NavigationMenuItemDetails(viewMode: .local),
NavigationMenuItemDetails(viewMode: .federated),
NavigationMenuItemDetails(viewMode: .search),
NavigationMenuItemDetails(viewMode: .profile),
NavigationMenuItemDetails(viewMode: .notifications)
]
@State private var selectedCustomMenuItems = [
NavigationMenuItemDetails(id: 1, viewMode: .home),
NavigationMenuItemDetails(id: 2, viewMode: .local),
NavigationMenuItemDetails(id: 3, viewMode: .profile)
@State private var displayedCustomMenuItems = [
SelectedMenuItemDetails(position: 1, viewMode: .home),
SelectedMenuItemDetails(position: 2, viewMode: .local),
SelectedMenuItemDetails(position: 3, viewMode: .profile)
]
@State private var hiddenMenuItems: [MainView.ViewMode] = []
@Binding var menuPosition: MenuPosition
init(menuPosition: Binding<MenuPosition>, onViewModeIconTap: @escaping (MainView.ViewMode) -> Void) {
@ -120,7 +122,7 @@ private struct NavigationMenuButtons: ViewModifier {
@ViewBuilder
private func contextMenuView() -> some View {
Menu {
MainNavigationOptions { viewMode in
MainNavigationOptions(hiddenMenuItems: $hiddenMenuItems) { viewMode in
self.onViewModeIconTap(viewMode)
}
} label: {
@ -134,8 +136,8 @@ private struct NavigationMenuButtons: ViewModifier {
@ViewBuilder
private func customMenuItemsView() -> some View {
ForEach(self.selectedCustomMenuItems) { item in
self.customMenuItemView(customMenuItem: item)
ForEach(self.displayedCustomMenuItems) { item in
self.customMenuItemView(item)
}
}
@ -154,39 +156,41 @@ private struct NavigationMenuButtons: ViewModifier {
}
@ViewBuilder
private func customMenuItemView(customMenuItem: NavigationMenuItemDetails) -> some View {
private func customMenuItemView(_ displayedCustomMenuItem: SelectedMenuItemDetails) -> some View {
Button {
self.onViewModeIconTap(customMenuItem.viewMode)
self.onViewModeIconTap(displayedCustomMenuItem.viewMode)
} label: {
Image(systemName: customMenuItem.image)
Image(systemName: displayedCustomMenuItem.image)
.font(.system(size: self.imageFontSize))
.foregroundColor(.mainTextColor.opacity(0.75))
.padding(.vertical, 10)
.padding(.horizontal, 8)
}.contextMenu {
self.listOfIconsView(customMenuItem: customMenuItem)
self.listOfIconsView(displayedCustomMenuItem)
}
}
@ViewBuilder
private func listOfIconsView(customMenuItem: NavigationMenuItemDetails) -> some View {
private func listOfIconsView(_ displayedCustomMenuItem: SelectedMenuItemDetails) -> some View {
ForEach(self.customMenuItems) { item in
Button {
withAnimation {
customMenuItem.viewMode = item.viewMode
displayedCustomMenuItem.viewMode = item.viewMode
}
// Saving in core data.
switch customMenuItem.id {
switch displayedCustomMenuItem.position {
case 1:
ApplicationSettingsHandler.shared.set(customNavigationMenuItem1: item.id)
ApplicationSettingsHandler.shared.set(customNavigationMenuItem1: item.viewMode.rawValue)
case 2:
ApplicationSettingsHandler.shared.set(customNavigationMenuItem2: item.id)
ApplicationSettingsHandler.shared.set(customNavigationMenuItem2: item.viewMode.rawValue)
case 3:
ApplicationSettingsHandler.shared.set(customNavigationMenuItem3: item.id)
ApplicationSettingsHandler.shared.set(customNavigationMenuItem3: item.viewMode.rawValue)
default:
break
}
self.hiddenMenuItems = self.displayedCustomMenuItems.map({ $0.viewMode })
} label: {
Label(item.title, systemImage: item.image)
}
@ -196,17 +200,19 @@ private struct NavigationMenuButtons: ViewModifier {
private func loadCustomMenuItems() {
let applicationSettings = ApplicationSettingsHandler.shared.get()
self.setCustomMenuItem(menuId: 1, savedId: Int(applicationSettings.customNavigationMenuItem1))
self.setCustomMenuItem(menuId: 2, savedId: Int(applicationSettings.customNavigationMenuItem2))
self.setCustomMenuItem(menuId: 3, savedId: Int(applicationSettings.customNavigationMenuItem3))
self.setCustomMenuItem(position: 1, viewMode: MainView.ViewMode(rawValue: Int(applicationSettings.customNavigationMenuItem1)) ?? .home)
self.setCustomMenuItem(position: 2, viewMode: MainView.ViewMode(rawValue: Int(applicationSettings.customNavigationMenuItem2)) ?? .local)
self.setCustomMenuItem(position: 3, viewMode: MainView.ViewMode(rawValue: Int(applicationSettings.customNavigationMenuItem3)) ?? .profile)
self.hiddenMenuItems = self.displayedCustomMenuItems.map({ $0.viewMode })
}
private func setCustomMenuItem(menuId: Int, savedId: Int) {
if let selectedCustomMenuItem = self.selectedCustomMenuItems.first(where: { $0.id == menuId }),
let customMenuItem = self.customMenuItems.first(where: { $0.id == savedId }) {
selectedCustomMenuItem.title = customMenuItem.title
selectedCustomMenuItem.viewMode = customMenuItem.viewMode
selectedCustomMenuItem.image = customMenuItem.image
private func setCustomMenuItem(position: Int, viewMode: MainView.ViewMode) {
if let displayedCustomMenuItem = self.displayedCustomMenuItems.first(where: { $0.position == position }),
let customMenuItem = self.customMenuItems.first(where: { $0.viewMode == viewMode }) {
displayedCustomMenuItem.title = customMenuItem.title
displayedCustomMenuItem.viewMode = customMenuItem.viewMode
displayedCustomMenuItem.image = customMenuItem.image
}
}
}

View File

@ -196,7 +196,7 @@ struct HomeFeedView: View {
.padding(12)
.font(.footnote)
.fontWeight(.light)
.foregroundColor(Color.white)
.foregroundColor(Color.mainTextColor)
.background(.ultraThinMaterial)
.clipShape(Capsule())
}

View File

@ -29,8 +29,16 @@ struct MainView: View {
@FetchRequest(sortDescriptors: [SortDescriptor(\.acct, order: .forward)]) var dbAccounts: FetchedResults<AccountData>
public enum ViewMode {
case home, local, federated, profile, notifications, trendingPhotos, trendingTags, trendingAccounts, search
public enum ViewMode: Int {
case home = 1
case local = 2
case federated = 3
case search = 4
case profile = 5
case notifications = 6
case trendingPhotos = 7
case trendingTags = 8
case trendingAccounts = 9
public var title: LocalizedStringKey {
switch self {
@ -147,7 +155,7 @@ struct MainView: View {
private func getPrincipalToolbar() -> some ToolbarContent {
ToolbarItem(placement: .principal) {
Menu {
MainNavigationOptions { viewMode in
MainNavigationOptions(hiddenMenuItems: Binding.constant([])) { viewMode in
self.switchView(to: viewMode)
}
} label: {

View File

@ -10,40 +10,55 @@ import SwiftUI
struct MainNavigationOptions: View {
let onViewModeIconTap: (MainView.ViewMode) -> Void
@Binding var hiddenMenuItems: [MainView.ViewMode]
init(hiddenMenuItems: Binding<[MainView.ViewMode]>, onViewModeIconTap: @escaping (MainView.ViewMode) -> Void) {
self._hiddenMenuItems = hiddenMenuItems
self.onViewModeIconTap = onViewModeIconTap
}
var body: some View {
Button {
self.onViewModeIconTap(.home)
} label: {
HStack {
Text(MainView.ViewMode.home.title)
Image(systemName: MainView.ViewMode.home.image)
if !self.hiddenMenuItems.contains(where: { $0 == .home }) {
Button {
self.onViewModeIconTap(.home)
} label: {
HStack {
Text(MainView.ViewMode.home.title)
Image(systemName: MainView.ViewMode.home.image)
}
}
}
Button {
self.onViewModeIconTap(.local)
} label: {
HStack {
Text(MainView.ViewMode.local.title)
Image(systemName: MainView.ViewMode.local.image)
if !self.hiddenMenuItems.contains(where: { $0 == .local }) {
Button {
self.onViewModeIconTap(.local)
} label: {
HStack {
Text(MainView.ViewMode.local.title)
Image(systemName: MainView.ViewMode.local.image)
}
}
}
Button {
self.onViewModeIconTap(.federated)
} label: {
HStack {
Text(MainView.ViewMode.federated.title)
Image(systemName: MainView.ViewMode.federated.image)
if !self.hiddenMenuItems.contains(where: { $0 == .federated }) {
Button {
self.onViewModeIconTap(.federated)
} label: {
HStack {
Text(MainView.ViewMode.federated.title)
Image(systemName: MainView.ViewMode.federated.image)
}
}
}
Button {
self.onViewModeIconTap(.search)
} label: {
HStack {
Text(MainView.ViewMode.search.title)
Image(systemName: MainView.ViewMode.search.image)
if !self.hiddenMenuItems.contains(where: { $0 == .search }) {
Button {
self.onViewModeIconTap(.search)
} label: {
HStack {
Text(MainView.ViewMode.search.title)
Image(systemName: MainView.ViewMode.search.image)
}
}
}
@ -85,21 +100,25 @@ struct MainNavigationOptions: View {
Divider()
Button {
self.onViewModeIconTap(.profile)
} label: {
HStack {
Text(MainView.ViewMode.profile.title)
Image(systemName: MainView.ViewMode.profile.image)
if !self.hiddenMenuItems.contains(where: { $0 == .profile }) {
Button {
self.onViewModeIconTap(.profile)
} label: {
HStack {
Text(MainView.ViewMode.profile.title)
Image(systemName: MainView.ViewMode.profile.image)
}
}
}
Button {
self.onViewModeIconTap(.notifications)
} label: {
HStack {
Text(MainView.ViewMode.notifications.title)
Image(systemName: MainView.ViewMode.notifications.image)
if !self.hiddenMenuItems.contains(where: { $0 == .notifications }) {
Button {
self.onViewModeIconTap(.notifications)
} label: {
HStack {
Text(MainView.ViewMode.notifications.title)
Image(systemName: MainView.ViewMode.notifications.image)
}
}
}
}