Skip to content

Commit

Permalink
Added hidden tools
Browse files Browse the repository at this point in the history
  • Loading branch information
siveryt committed May 26, 2024
1 parent 0d1a4a3 commit db74223
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
41 changes: 32 additions & 9 deletions Toolbox/Mainscreen/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct ContentView: View {
@AppStorage("cvOrder") var order = [0]
@AppStorage("cvHasAlreadyEdited") var hasAlreadyEdited = false

@AppStorage("cvHidden") var hidden: [Int] = []

@State var toollist:[Tool] = [
Tool(view: AnyView(DiceView()), title: NSLocalizedString("Dice", comment: "Menu item"), icon: "dice"),
Expand Down Expand Up @@ -67,19 +68,34 @@ struct ContentView: View {
NavigationView {
List() {
ForEach(Array(zip(tools.indices, tools)), id: \.0) { toolIndex, tool in
if (toolIndex == 0){
NavigationLink(destination: tools[toolIndex].view) {
Label(tools[toolIndex].title, systemImage: tools[toolIndex].icon).foregroundColor(.primary)
}
.popoverTip(MainscreenMoveTip())
} else {
NavigationLink(destination: tools[toolIndex].view) {
Label(tools[toolIndex].title, systemImage: tools[toolIndex].icon).foregroundColor(.primary)
if (!hidden.contains(toolIndex)) {
if (toolIndex == 0){
NavigationLink(destination: tools[toolIndex].view) {
Label(tools[toolIndex].title, systemImage: tools[toolIndex].icon).foregroundColor(.primary)
}
.popoverTip(MainscreenMoveTip())
.contextMenu {
Button(action:{
hide(index: toolIndex)
}){
Label("Hide", systemImage: "eye.slash")
}
}
} else {
NavigationLink(destination: tools[toolIndex].view) {
Label(tools[toolIndex].title, systemImage: tools[toolIndex].icon).foregroundColor(.primary)
}
.contextMenu {
Button(action:{
hide(index: toolIndex)
}){
Label("Hide", systemImage: "eye.slash")
}
}
}
}



}
.onMove(perform: onMove)
}
Expand Down Expand Up @@ -145,6 +161,13 @@ struct ContentView: View {
.whatsNewSheet()
}

private func hide(index: Int) {
print("Hiding \(index)")
withAnimation{
hidden.append(index)
}
}

}


Expand Down
59 changes: 59 additions & 0 deletions Toolbox/Mainscreen/InfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ struct infoView: View {
Label("Permissions", systemImage: "shield")
}

NavigationLink(destination: infoHidden()){
Label("Hidden", systemImage: "eye.slash")
}

Button(action: {
if let url = URL(string: "http://toolbox.sivery.de") {
UIApplication.shared.open(url)
Expand Down Expand Up @@ -367,6 +371,61 @@ struct permissions: View {
}
}

struct infoHidden: View {
@AppStorage("cvHidden") var hidden: [Int] = []
@State var tools = ContentView().toollist
@State var showingInfoAlert = false

var body: some View {
VStack {
if (hidden.count != 0){
List {
ForEach(Array(zip(tools.indices, tools)), id: \.0) { toolIndex, tool in
if (hidden.contains(toolIndex)) {
NavigationLink(destination: tools[toolIndex].view) {
Label(tools[toolIndex].title, systemImage: tools[toolIndex].icon).foregroundColor(.primary)
}
.contextMenu {
Button(action:{
unhide(index: toolIndex)
}){
Label("Show Again", systemImage: "eye")
}
}
}
}
}
} else {
Text("You have no tools hidden")
}
}
.navigationTitle("Hidden Tools")
.navigationBarTitleDisplayMode(.inline)
.alert(isPresented: $showingInfoAlert) {
Alert(
title: Text("What?"),
message: Text("Tools you previously hid on the app's main screen can be used here.\nIf you want to move them back to the main screen, tap and hold them.\nThe same goes for hiding them again."),
dismissButton: .destructive(Text("Got it!")) // I have to use .destructive and not .default, because .default often times is the default primary blue and not the color set in Assets AccentColor
)
}
.toolbar(){
ToolbarItem(placement: .primaryAction) {
Button(action: {
showingInfoAlert = true
}, label: {
Image(systemName: "questionmark.circle")
})
}
}
}

private func unhide(index: Int) {
withAnimation {
hidden.removeAll { $0 == index }
}
}
}

struct permissions_Previews: PreviewProvider {
static var previews: some View {
permissions()
Expand Down

0 comments on commit db74223

Please sign in to comment.