Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Aug 5, 2020
1 parent ed34397 commit 9e05aff
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 84 deletions.
8 changes: 4 additions & 4 deletions ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 080522020;
CURRENT_PROJECT_VERSION = 080532020;
DEVELOPMENT_ASSET_PATHS = "\"ACHNBrowserUI/Preview Content\"";
DEVELOPMENT_TEAM = Z6P74P6T99;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1417,7 +1417,7 @@
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 080522020;
CURRENT_PROJECT_VERSION = 080532020;
DEVELOPMENT_ASSET_PATHS = "\"ACHNBrowserUI/Preview Content\"";
DEVELOPMENT_TEAM = Z6P74P6T99;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1449,7 +1449,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 080522020;
CURRENT_PROJECT_VERSION = 080532020;
DEVELOPMENT_TEAM = Z6P74P6T99;
INFOPLIST_FILE = Widgets/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand Down Expand Up @@ -1480,7 +1480,7 @@
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 080522020;
CURRENT_PROJECT_VERSION = 080532020;
DEVELOPMENT_TEAM = Z6P74P6T99;
INFOPLIST_FILE = Widgets/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Backend
import UI

struct CategoryRowView: View {
@EnvironmentObject private var items: Items
let category: Backend.Category

var body: some View {
Expand All @@ -23,7 +24,7 @@ struct CategoryRowView: View {
Text(category.label())
.style(appStyle: .rowTitle)
Spacer()
Text("\(Items.shared.categories[category]?.count ?? 0)")
Text("\(items.categories[category]?.count ?? 0)")
.style(appStyle: .rowDescription)
}
}.listRowBackground(Color.acSecondaryBackground)
Expand Down
67 changes: 26 additions & 41 deletions ACHNBrowserUI/ACHNBrowserUI/views/items/ItemsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct ItemsView: View {
}

@StateObject var viewModel: ItemsViewModel
@State private var showSortSheet = false
@State private var contentMode: ContentMode = .listLarge
let customTitle: String?

Expand Down Expand Up @@ -58,16 +57,32 @@ struct ItemsView: View {
}

private var sortButton: some View {
Button(action: {
showSortSheet.toggle()
}) {
Image(systemName: viewModel.sort == nil ? "arrow.up.arrow.down.circle" : "arrow.up.arrow.down.circle.fill")
.style(appStyle: .barButton)
.foregroundColor(.acText)
Menu {
ForEach(ItemsViewModel.Sort.allCases(for: viewModel.category), id: \.self) { sort in
Button(LocalizedStringKey(sort.rawValue.localizedCapitalized),
action: {
self.viewModel.sort = sort
})
}
if viewModel.sort != nil {
Divider()
Button("Clear Selection", action: {
self.viewModel.sort = nil
})
}
} label: {
Button(action: {

}) {
Image(systemName: viewModel.sort == nil ? "arrow.up.arrow.down.circle" : "arrow.up.arrow.down.circle.fill")
.style(appStyle: .barButton)
.foregroundColor(.acText)
}
.buttonStyle(BorderedBarButtonStyle())
.accentColor(Color.acText.opacity(0.2))
.safeHoverEffectBarItem(position: .trailing)
}
.buttonStyle(BorderedBarButtonStyle())
.accentColor(Color.acText.opacity(0.2))
.safeHoverEffectBarItem(position: .trailing)

}

private var layoutButton: some View {
Expand All @@ -89,39 +104,11 @@ struct ItemsView: View {
.accentColor(Color.acText.opacity(0.2))
.safeHoverEffectBarItem(position: .trailing)
}

private var sortSheet: ActionSheet {
var buttons: [ActionSheet.Button] = []
for sort in ItemsViewModel.Sort.allCases(for: viewModel.category) {
buttons.append(.default(Text(LocalizedStringKey(sort.rawValue.localizedCapitalized)),
action: {
self.viewModel.sort = sort
}))
}

if viewModel.sort != nil {
buttons.append(.default(Text("Clear Selection"), action: {
self.viewModel.sort = nil
}))
}

buttons.append(.cancel())

let title = Text("Sort items")

if let currentSort = viewModel.sort {
let currentSortName = NSLocalizedString(currentSort.rawValue.localizedCapitalized, comment: "")
return ActionSheet(title: title,
message: Text("Current Sort: \(currentSortName)"),
buttons: buttons)
}

return ActionSheet(title: title, buttons: buttons)
}

var body: some View {
contentView
.modifier(DismissingKeyboardOnSwipe())
.navigationBarTitleDisplayMode(contentMode == .grid ? .inline : .automatic)
.navigationBarTitle(customTitle != nil ?
Text(LocalizedStringKey(customTitle!)) :
Text(viewModel.category.label()),
Expand All @@ -131,7 +118,6 @@ struct ItemsView: View {
layoutButton
sortButton
})
.actionSheet(isPresented: $showSortSheet, content: { self.sortSheet })
}

@ViewBuilder
Expand All @@ -158,7 +144,6 @@ struct ItemsView: View {
}
}
}
.animation(.interactiveSpring())
.listStyle(GroupedListStyle())
.id(viewModel.sort)
}
Expand Down
53 changes: 15 additions & 38 deletions ACHNBrowserUI/ACHNBrowserUI/views/villagers/VillagersSortView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,32 @@
import SwiftUI

struct VillagersSortView: View {

@State private var showSortSheet = false
@Binding var sort: VillagersViewModel.Sort?

enum Sort: String, CaseIterable {
case name, species
}

private var sortButton: some View {
Button(action: {
self.showSortSheet.toggle()
}) {
private var sortMenu: some View {
Menu {
ForEach(VillagersViewModel.Sort.allCases, id: \.self) { sort in
Button(LocalizedStringKey(sort.rawValue.localizedCapitalized), action: {
self.sort = sort
})
}
if sort != nil {
Divider()
Button("Clear Selection", action: {
self.sort = nil
})
}
} label: {
Image(systemName: sort == nil ? "arrow.up.arrow.down.circle" : "arrow.up.arrow.down.circle.fill")
.imageScale(.large)
}
.safeHoverEffectBarItem(position: .trailing)
}

private var sortSheet: ActionSheet {
var buttons: [ActionSheet.Button] = []
for sort in VillagersViewModel.Sort.allCases {
buttons.append(.default(Text(LocalizedStringKey(sort.rawValue.localizedCapitalized)),
action: {
self.sort = sort
}))
}

if sort != nil {
buttons.append(.default(Text("Clear Selection"), action: {
self.sort = nil
}))
}

buttons.append(.cancel())

let title = Text("Sort villagers")

if let currentSort = sort {
let currentSortName = NSLocalizedString(currentSort.rawValue.localizedCapitalized, comment: "")
return ActionSheet(title: title,
message: Text("Current Sort: \(currentSortName)"),
buttons: buttons)
}

return ActionSheet(title: title, buttons: buttons)
}

var body: some View {
sortButton
.actionSheet(isPresented: $showSortSheet, content: { self.sortSheet })
sortMenu
}
}

0 comments on commit 9e05aff

Please sign in to comment.