From 12a2936a46c80465364cdff2738d6df8685c4b22 Mon Sep 17 00:00:00 2001 From: cpilaszewicz <cezipil@fu-berlin.de> Date: Wed, 25 Mar 2020 12:43:49 +0100 Subject: [PATCH] Small code improvements --- enzevalos_iphone/AppDelegate.swift | 2 - enzevalos_iphone/BadgeCaseView.swift | 60 ++----------------- .../SwiftUI/Inbox/InboxCoordinator.swift | 8 ++- 3 files changed, 10 insertions(+), 60 deletions(-) diff --git a/enzevalos_iphone/AppDelegate.swift b/enzevalos_iphone/AppDelegate.swift index 1b89fe94..2969dac0 100644 --- a/enzevalos_iphone/AppDelegate.swift +++ b/enzevalos_iphone/AppDelegate.swift @@ -132,8 +132,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func showBadgeCase() { - // self.window?.rootViewController = UIHostingController(rootView: BadgeCaseView()) - // return guard let vc = self.window?.rootViewController as? UINavigationController else { fatalError("No rootViewController!") } diff --git a/enzevalos_iphone/BadgeCaseView.swift b/enzevalos_iphone/BadgeCaseView.swift index b2c29512..8ffed648 100644 --- a/enzevalos_iphone/BadgeCaseView.swift +++ b/enzevalos_iphone/BadgeCaseView.swift @@ -12,17 +12,8 @@ struct BadgeCaseView: View { init() { UITableView.appearance().separatorStyle = .none } - let badges: [Badge] = GamificationData.sharedInstance.badges.map { Badge(type: $0.type, description: $0.displayName, imageOn: $0.onName, imageOff: $0.offName, isActive: $0.isAchieved()) } - var userRecord: KeyRecord { - get { - let keyID = UserManager.loadUserValue(Attribute.prefSecretKeyID) as? String - let addr = UserManager.loadUserValue(Attribute.userAddr) as! String - return DataHandler.handler.getKeyRecord(addr: addr, keyID: keyID) - } - } - var body: some View { NavigationView { VStack { @@ -37,56 +28,15 @@ struct BadgeCaseView: View { } }.navigationBarTitle(Text(NSLocalizedString("Gamification.Overview.HeaderTitle", comment:"Badge Case Navigation Title" )), displayMode: .inline).navigationBarItems(leading: Button(action: goBack, label: { Text("Back") - } - )) - } - } - - private func goBack() { - if let win = AppDelegate.getAppDelegate().window { - if let root = win.rootViewController { - print("Appdelegates current root: \(root.debugDescription)") - if let navi = root.navigationController { - navi.popViewController(animated: true) - } - else if let root = root as? UINavigationController { - print("Root is a UINavigationController -> we can pop!") - root.popViewController(animated: true) - } - else { - if let coord = AppDelegate.getAppDelegate().inboxCoordinator { - print("Inbox coord root: \(coord.root.topViewController.debugDescription)") - coord.root.popViewController(animated: true) - } - } - } + })) } } - - - private var titleIcon: some View { - HStack{ - Image("verschluesseltOn") - .resizable() - .scaledToFit() - .frame(width: 40,height: 40) - .padding(10) + + func goBack() { + if let coord = AppDelegate.getAppDelegate().inboxCoordinator { + coord.goBack() } } - private var backButton: some View { - VStack { - Button(action: goBack) { - Text("< My ID") - } - } - } - /* - func goBack() { - if let coord = AppDelegate.getAppDelegate().inboxCoordinator { - coord.pushInbox() - } - } - */ } struct Badge: Identifiable { diff --git a/enzevalos_iphone/SwiftUI/Inbox/InboxCoordinator.swift b/enzevalos_iphone/SwiftUI/Inbox/InboxCoordinator.swift index f1e3b56b..f168e8b4 100644 --- a/enzevalos_iphone/SwiftUI/Inbox/InboxCoordinator.swift +++ b/enzevalos_iphone/SwiftUI/Inbox/InboxCoordinator.swift @@ -22,6 +22,10 @@ class InboxCoordinator { mainStoryboard = UIStoryboard(name: self.mainStoryboardName, bundle: nil) } + func goBack() { + root.popViewController(animated: true) + } + func pushInbox(){ try? AppDelegate.getAppDelegate().mailHandler.startIMAPIdleIfSupported() AppDelegate.getAppDelegate().mailHandler.updateFolder(folder: Folder.inbox, completionCallback: {_ in @@ -31,9 +35,7 @@ class InboxCoordinator { if let vc = inbox { if root.viewControllers.contains(vc) { - while root.topViewController != vc { - root.popViewController(animated: true) - } + root.popToViewController(vc, animated: false) } else { root.pushViewController(vc, animated: true) } -- GitLab