-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dodanie skrótów do wyszukiwarki i wiadomości (#321)
* feature: search and news shortcut * chore: remove unused files
- Loading branch information
1 parent
e6c493b
commit ae1977d
Showing
9 changed files
with
102 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
BuyPolish/Pola/Manager/ApplicationShortcut/ApplicationShortcutHandling.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
protocol ApplicationShortcutHandling { | ||
func handleShortcutItem(_ item: UIApplicationShortcutItem, window: UIWindow?) -> Bool | ||
} | ||
|
||
final class ApplicationShortcutHandler: ApplicationShortcutHandling { | ||
private enum ShortcutType: String { | ||
case scanCode | ||
case writeCode | ||
case search | ||
case news | ||
|
||
static func fromShortcut(_ item: UIApplicationShortcutItem) -> ShortcutType? { | ||
guard let bundleIdentifier = Bundle.main.bundleIdentifier else { | ||
return nil | ||
} | ||
|
||
var typeString = item.type | ||
typeString.removeFirst(bundleIdentifier.count + 1) | ||
|
||
return ShortcutType(rawValue: typeString) | ||
} | ||
} | ||
|
||
func handleShortcutItem(_ item: UIApplicationShortcutItem, window: UIWindow?) -> Bool { | ||
guard let type = ShortcutType.fromShortcut(item), | ||
let rootViewController = window?.rootViewController as? RootViewController else { | ||
return false | ||
} | ||
|
||
switch type { | ||
case .scanCode: | ||
rootViewController.showScanCodeView() | ||
case .writeCode: | ||
rootViewController.showWriteCodeView() | ||
case .search: | ||
rootViewController.showSearch() | ||
case .news: | ||
rootViewController.showNews() | ||
} | ||
|
||
return true | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
BuyPolish/Pola/Manager/ApplicationShortcut/ApplicationShortcutRegistrant.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Swinject | ||
|
||
final class ApplicationShortcutRegistrant: DependencyRegistrant { | ||
func registerDependency(container: Container) { | ||
container.register(ApplicationShortcutHandling.self) { _ in | ||
ApplicationShortcutHandler() | ||
}.inObjectScope(.container) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters