Skip to content

Commit

Permalink
fixed airspam ui but created another UI problem
Browse files Browse the repository at this point in the history
  • Loading branch information
c22dev committed Dec 23, 2022
1 parent 14bd313 commit d8fe939
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions TrollBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.0.4;
MARKETING_VERSION = 0.0.5;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = live.cclerc.trollbox;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -563,7 +563,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.0.4;
MARKETING_VERSION = 0.0.5;
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = live.cclerc.trollbox;
Expand Down
149 changes: 73 additions & 76 deletions TrollBox/Tools/AirSpam/AirSpam.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ struct AirSpam: View {
var body: some View {
NavigationView {
Group {
if trollController.people.count == 0 { // No users in radius
VStack {
ProgressView()
Text("Searching for devices...")
.foregroundColor(.secondary)
.padding()
}
} else {
LazyVGrid(columns: gridItemLayout, spacing: 8) {
ForEach(trollController.people.sorted(by: { a, b in a.displayName ?? "" < b.displayName ?? "" }), id: \.node) { p in
PersonView(person: p, selected: $selectedPeople[p.node])
.environmentObject(trollController)
}
}
.padding()
VStack {
if trollController.isRunning { Text("Sent AirDrops: \(totalAirDrops)") }
HStack { // delay control between airdrops
Expand All @@ -53,92 +53,89 @@ struct AirSpam: View {
.padding()
}
}
}
.onAppear {
// Start searching nodes
trollController.startBrowser()
}
.onChange(of: rechargeDuration) { newValue in
trollController.rechargeDuration = newValue
}

}
.navigationViewStyle(StackNavigationViewStyle())
.onAppear {
// Start searching nodes
trollController.startBrowser()
}
.onChange(of: rechargeDuration) { newValue in
trollController.rechargeDuration = newValue
}

// shows a privacy req dialog if needed
func showPicker() {
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
DispatchQueue.main.async {
// show picker if authorized
showingImagePicker = status == .authorized
}
}

// shows a privacy req dialog if needed
func showPicker() {
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
DispatchQueue.main.async {
// show picker if authorized
showingImagePicker = status == .authorized
}
}
}

func toggleTrollButtonTapped() {
UIImpactFeedbackGenerator(style: .medium).impactOccurred() // mmm

guard selectedPeople.values.filter({ $0 == true }).count > 0 else {
UIApplication.shared.alert(title: "No people selected", body: "Select users by tapping on them.")
return
}

func toggleTrollButtonTapped() {
UIImpactFeedbackGenerator(style: .medium).impactOccurred() // mmm

guard selectedPeople.values.filter({ $0 == true }).count > 0 else {
UIApplication.shared.alert(title: "No people selected", body: "Select users by tapping on them.")
return
}

if !trollController.isRunning {
UIApplication.shared.confirmAlert(title: "\(UIDevice.current.name)", body: "This is the current name of this device and the name people will see when receiving an AirDrop. Are you sure you want to continue?", onOK: {
if let imageURL = imageURL {
trollController.sharedURL = imageURL
}
trollController.startTrolling(shouldTrollHandler: { person in
return selectedPeople[person.node] ?? false // troll only selected people
}, eventHandler: { event in
switch event {
case .operationEvent(let event1):
if event1 == .canceled || event1 == .finished || event1 == .blocked {
totalAirDrops += 1
UISelectionFeedbackGenerator().selectionChanged()
}
case .cancelled:
if !trollController.isRunning {
UIApplication.shared.confirmAlert(title: "\(UIDevice.current.name)", body: "This is the current name of this device and the name people will see when receiving an AirDrop. Are you sure you want to continue?", onOK: {
trollController.startTrolling(shouldTrollHandler: { person in
return selectedPeople[person.node] ?? false // troll only selected people
}, eventHandler: { event in
switch event {
case .operationEvent(let event1):
if event1 == .canceled || event1 == .finished || event1 == .blocked {
totalAirDrops += 1
UISelectionFeedbackGenerator().selectionChanged()
}
}) // start trolling :troll:
trollController.isRunning.toggle()
}, noCancel: false)
} else {
trollController.stopTrollings()
case .cancelled:
totalAirDrops += 1
UISelectionFeedbackGenerator().selectionChanged()
}
}) // start trolling :troll:
trollController.isRunning.toggle()
}
}, noCancel: false)
} else {
trollController.stopTrollings()
trollController.isRunning.toggle()
}
}

struct PersonView: View {
@State var person: TrollController.Person
@Binding var selected: Bool?
@EnvironmentObject var trollController: TrollController

struct PersonView: View {
@State var person: TrollController.Person
@Binding var selected: Bool?
@EnvironmentObject var trollController: TrollController

var body: some View {
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
if selected == nil { selected = false }
selected?.toggle()
remLog("selected", selected!)
}) {
VStack {
ZStack {
Image((selected ?? false) ? "TrolledPerson" : "NonTrolledPerson")
}
Text(person.displayName ?? "Unknown")
.font(.footnote)
.multilineTextAlignment(.center)
.minimumScaleFactor(0.5)
.foregroundColor(.init(uiColor14: .label))
var body: some View {
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
if selected == nil { selected = false }
selected?.toggle()
remLog("selected", selected!)
}) {
VStack {
ZStack {
Image((selected ?? false) ? "TrolledPerson" : "NonTrolledPerson")
}
Text(person.displayName ?? "Unknown")
.font(.footnote)
.multilineTextAlignment(.center)
.minimumScaleFactor(0.5)
.foregroundColor(.init(uiColor14: .label))
}
.disabled(trollController.isRunning)
}
.disabled(trollController.isRunning)
}
}
}
struct AirSpam_Previews: PreviewProvider {
struct AirSpam_Previews: PreviewProvider {
static var previews: some View {
AirSpam()
}
}

0 comments on commit d8fe939

Please sign in to comment.