Skip to content

Commit 6223da9

Browse files
Merge pull request #520 from Adamant-im/dev/trello.com/c/44KDaoe5
[trello.com/c/44KDaoe5] Rebuilt Notification screen
2 parents 7e44adc + d92831c commit 6223da9

17 files changed

+314
-718
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
2621AB372C60E74A00046D7A /* NotificationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2621AB362C60E74A00046D7A /* NotificationsView.swift */; };
1111
2621AB392C60E7AE00046D7A /* NotificationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2621AB382C60E7AE00046D7A /* NotificationsViewModel.swift */; };
1212
2621AB3B2C613C8100046D7A /* NotificationsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2621AB3A2C613C8100046D7A /* NotificationsFactory.swift */; };
13-
2657A0C92C7078750021E7E6 /* NotificationSoundsPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2657A0C82C7078750021E7E6 /* NotificationSoundsPickerView.swift */; };
1413
2657A0CA2C707D780021E7E6 /* notification.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E9A174B820587B83003667CD /* notification.mp3 */; };
1514
2657A0CB2C707D7B0021E7E6 /* so-proud-notification.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 4198D57A28C8B7DA009337F2 /* so-proud-notification.mp3 */; };
1615
2657A0CC2C707D7E0021E7E6 /* relax-message-tone.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 4198D57C28C8B7F9009337F2 /* relax-message-tone.mp3 */; };
@@ -158,7 +157,6 @@
158157
4164A9D928F17DA700EEF16D /* AdamantChatTransactionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4164A9D828F17DA700EEF16D /* AdamantChatTransactionService.swift */; };
159158
416F5EA4290162EB00EF0400 /* SocketIO in Frameworks */ = {isa = PBXBuildFile; productRef = 416F5EA3290162EB00EF0400 /* SocketIO */; };
160159
4177E5E12A52DA7100C089FE /* AdvancedContextMenuKit in Frameworks */ = {isa = PBXBuildFile; productRef = 4177E5E02A52DA7100C089FE /* AdvancedContextMenuKit */; };
161-
417BA7F428BF894F00DF94C5 /* NotificationSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 417BA7F328BF894F00DF94C5 /* NotificationSoundsViewController.swift */; };
162160
4184F16E2A33023A00D7B8B9 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4184F16D2A33023A00D7B8B9 /* GoogleService-Info.plist */; };
163161
4184F1712A33044E00D7B8B9 /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = 4184F1702A33044E00D7B8B9 /* FirebaseCrashlytics */; };
164162
4184F1732A33102800D7B8B9 /* AdamantCrashlysticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4184F1722A33102800D7B8B9 /* AdamantCrashlysticsService.swift */; };
@@ -485,7 +483,6 @@
485483
E90847372196FEA80095825D /* Chatroom+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90847292196FEA80095825D /* Chatroom+CoreDataProperties.swift */; };
486484
E90847392196FEF50095825D /* BaseTransaction+TransactionDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90847382196FEF50095825D /* BaseTransaction+TransactionDetails.swift */; };
487485
E908473B219707200095825D /* AccountViewController+StayIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = E908473A219707200095825D /* AccountViewController+StayIn.swift */; };
488-
E908473D219713300095825D /* NotificationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E908473C219713300095825D /* NotificationsViewController.swift */; };
489486
E90A4943204C5ED6009F6A65 /* EurekaPassphraseRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90A4942204C5ED6009F6A65 /* EurekaPassphraseRow.swift */; };
490487
E90A4945204C6204009F6A65 /* PassphraseCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E90A4944204C5F60009F6A65 /* PassphraseCell.xib */; };
491488
E90A494B204D9EB8009F6A65 /* AdamantAuthentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90A494A204D9EB8009F6A65 /* AdamantAuthentication.swift */; };
@@ -706,7 +703,6 @@
706703
2621AB362C60E74A00046D7A /* NotificationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsView.swift; sourceTree = "<group>"; };
707704
2621AB382C60E7AE00046D7A /* NotificationsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsViewModel.swift; sourceTree = "<group>"; };
708705
2621AB3A2C613C8100046D7A /* NotificationsFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsFactory.swift; sourceTree = "<group>"; };
709-
2657A0C82C7078750021E7E6 /* NotificationSoundsPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSoundsPickerView.swift; sourceTree = "<group>"; };
710706
265AA1612B74E6B900CF98B0 /* ChatPreservation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatPreservation.swift; sourceTree = "<group>"; };
711707
269B830F2C74A2FF002AA1D7 /* note.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = note.mp3; sourceTree = "<group>"; };
712708
269B83122C74B4EA002AA1D7 /* handoff.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = handoff.mp3; sourceTree = "<group>"; };
@@ -833,7 +829,6 @@
833829
416380E02A51765F00F90E6D /* ChatReactionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatReactionsView.swift; sourceTree = "<group>"; };
834830
4164A9D628F17D4000EEF16D /* ChatTransactionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTransactionService.swift; sourceTree = "<group>"; };
835831
4164A9D828F17DA700EEF16D /* AdamantChatTransactionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantChatTransactionService.swift; sourceTree = "<group>"; };
836-
417BA7F328BF894F00DF94C5 /* NotificationSoundsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSoundsViewController.swift; sourceTree = "<group>"; };
837832
4184F16D2A33023A00D7B8B9 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
838833
4184F1722A33102800D7B8B9 /* AdamantCrashlysticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantCrashlysticsService.swift; sourceTree = "<group>"; };
839834
4184F1742A33106200D7B8B9 /* CrashlysticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashlysticsService.swift; sourceTree = "<group>"; };
@@ -1123,7 +1118,6 @@
11231118
E90847292196FEA80095825D /* Chatroom+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Chatroom+CoreDataProperties.swift"; sourceTree = "<group>"; };
11241119
E90847382196FEF50095825D /* BaseTransaction+TransactionDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BaseTransaction+TransactionDetails.swift"; sourceTree = "<group>"; };
11251120
E908473A219707200095825D /* AccountViewController+StayIn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountViewController+StayIn.swift"; sourceTree = "<group>"; };
1126-
E908473C219713300095825D /* NotificationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsViewController.swift; sourceTree = "<group>"; };
11271121
E90A4942204C5ED6009F6A65 /* EurekaPassphraseRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EurekaPassphraseRow.swift; sourceTree = "<group>"; };
11281122
E90A4944204C5F60009F6A65 /* PassphraseCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PassphraseCell.xib; sourceTree = "<group>"; };
11291123
E90A494A204D9EB8009F6A65 /* AdamantAuthentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantAuthentication.swift; sourceTree = "<group>"; };
@@ -1395,24 +1389,22 @@
13951389
2621AB352C60E52900046D7A /* Notifications */ = {
13961390
isa = PBXGroup;
13971391
children = (
1398-
2657A0C72C7078630021E7E6 /* Helpers */,
1392+
26F7EF3E2C9118E700E16A94 /* NotificationSounds */,
13991393
2621AB362C60E74A00046D7A /* NotificationsView.swift */,
14001394
2621AB382C60E7AE00046D7A /* NotificationsViewModel.swift */,
14011395
2621AB3A2C613C8100046D7A /* NotificationsFactory.swift */,
1402-
417BA7F328BF894F00DF94C5 /* NotificationSoundsViewController.swift */,
1403-
269B83362C74D1F9002AA1D7 /* NotificationSoundsView.swift */,
1404-
269B83392C74D4AA002AA1D7 /* NotificationSoundsViewModel.swift */,
1405-
269B833C2C74E661002AA1D7 /* NotificationSoundsFactory.swift */,
14061396
);
14071397
path = Notifications;
14081398
sourceTree = "<group>";
14091399
};
1410-
2657A0C72C7078630021E7E6 /* Helpers */ = {
1400+
26F7EF3E2C9118E700E16A94 /* NotificationSounds */ = {
14111401
isa = PBXGroup;
14121402
children = (
1413-
2657A0C82C7078750021E7E6 /* NotificationSoundsPickerView.swift */,
1403+
269B83362C74D1F9002AA1D7 /* NotificationSoundsView.swift */,
1404+
269B83392C74D4AA002AA1D7 /* NotificationSoundsViewModel.swift */,
1405+
269B833C2C74E661002AA1D7 /* NotificationSoundsFactory.swift */,
14141406
);
1415-
path = Helpers;
1407+
path = NotificationSounds;
14161408
sourceTree = "<group>";
14171409
};
14181410
3A20D9392AE7F305005475A6 /* Models */ = {
@@ -2684,7 +2676,6 @@
26842676
E9942B7F203C058C00C163AF /* QRGeneratorViewController.swift */,
26852677
E9484B7E2285C016008E10F0 /* PKGeneratorViewController.swift */,
26862678
E9484B7C2285BAD8008E10F0 /* PrivateKeyGenerator.swift */,
2687-
E908473C219713300095825D /* NotificationsViewController.swift */,
26882679
);
26892680
path = Settings;
26902681
sourceTree = "<group>";
@@ -3318,7 +3309,6 @@
33183309
E987024920C2B1F700E393F4 /* AdamantChatsProvider+fakeMessages.swift in Sources */,
33193310
934FD9B02C78481500336841 /* InfoServiceApiError.swift in Sources */,
33203311
6403F5E222723F7500D58779 /* DashWallet.swift in Sources */,
3321-
2657A0C92C7078750021E7E6 /* NotificationSoundsPickerView.swift in Sources */,
33223312
26A975FF2B7E843E0095C367 /* SelectTextView.swift in Sources */,
33233313
93294B822AAD0BB400911109 /* BtcWalletFactory.swift in Sources */,
33243314
648DD7A42237DB9E00B811FD /* DogeWalletService+Send.swift in Sources */,
@@ -3410,7 +3400,6 @@
34103400
645FEB34213E72C100D6BA2D /* OnboardViewController.swift in Sources */,
34113401
E9B3D39A201F90570019EB36 /* AccountsProvider.swift in Sources */,
34123402
4186B338294200E8006594A3 /* DogeWalletService+DynamicConstants.swift in Sources */,
3413-
417BA7F428BF894F00DF94C5 /* NotificationSoundsViewController.swift in Sources */,
34143403
3A96E37C2AED27F8001F5A52 /* PartnerQRService.swift in Sources */,
34153404
E950652320404C84008352E5 /* AdamantUriTools.swift in Sources */,
34163405
3A41938F2A580C57006A6B22 /* AdamantRichTransactionReactService.swift in Sources */,
@@ -3592,7 +3581,6 @@
35923581
E993302221354BC300CD5200 /* EthWalletFactory.swift in Sources */,
35933582
418FDE502A25CA340055E3CD /* ChatMenuManager.swift in Sources */,
35943583
E90055F520EBF5DA00D0CB2D /* AboutViewController.swift in Sources */,
3595-
E908473D219713300095825D /* NotificationsViewController.swift in Sources */,
35963584
E908472E2196FEA80095825D /* BaseTransaction+CoreDataClass.swift in Sources */,
35973585
64D059FF20D3116B003AD655 /* NodesListViewController.swift in Sources */,
35983586
E91E5BF220DAF05500B06B3C /* NodeCell.swift in Sources */,

Adamant/App/DI/AppAssembly.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ struct AppAssembly: Assembly {
5353

5454
// MARK: Notifications
5555
container.register(NotificationsService.self) { r in
56-
AdamantNotificationsService(securedStore: r.resolve(SecuredStore.self)!)
56+
AdamantNotificationsService(
57+
securedStore: r.resolve(SecuredStore.self)!,
58+
vibroService: r.resolve(VibroService.self)!
59+
)
5760
}.initCompleted { (r, c) in // Weak reference
5861
Task { @MainActor in
5962
guard let service = c as? AdamantNotificationsService else { return }
6063
service.accountService = r.resolve(AccountService.self)
64+
service.chatsProvider = r.resolve(ChatsProvider.self)
6165
}
6266
}.inObjectScope(.container)
6367

Adamant/Modules/ScreensFactory/AdamantScreensFactory.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ struct AdamantScreensFactory: ScreensFactory {
2929
private let partnerQRFactory: PartnerQRFactory
3030
private let coinsNodesListFactory: CoinsNodesListFactory
3131
private let chatSelectTextFactory: ChatSelectTextViewFactory
32-
private let notificasionsFactory: NotificationsFactory
33-
private let notificationSounds: NotificationSoundsFactory
32+
private let notificationsFactory: NotificationsFactory
33+
private let notificationSoundsFactory: NotificationSoundsFactory
3434
private let storageUsageFactory: StorageUsageFactory
3535

3636
init(assembler: Assembler) {
@@ -49,8 +49,8 @@ struct AdamantScreensFactory: ScreensFactory {
4949
partnerQRFactory = .init(parent: assembler)
5050
coinsNodesListFactory = .init(parent: assembler)
5151
chatSelectTextFactory = .init()
52-
notificasionsFactory = .init(parent: assembler)
53-
notificationSounds = .init(parent: assembler)
52+
notificationsFactory = .init(parent: assembler)
53+
notificationSoundsFactory = .init(parent: assembler)
5454
storageUsageFactory = .init(parent: assembler)
5555

5656
walletFactoryCompose = AdamantWalletFactoryCompose(
@@ -165,11 +165,11 @@ struct AdamantScreensFactory: ScreensFactory {
165165
}
166166

167167
func makeNotifications() -> UIViewController {
168-
notificasionsFactory.makeViewController(screensFactory: self)
168+
notificationsFactory.makeViewController()
169169
}
170170

171171
func makeNotificationSounds(target: NotificationTarget) -> NotificationSoundsView {
172-
notificationSounds.makeView(target: target)
172+
notificationSoundsFactory.makeView(target: target)
173173
}
174174

175175
func makeVisibleWallets() -> UIViewController {

Adamant/Modules/Settings/Notifications/Helpers/NotificationSoundsPickerView.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Adamant/Modules/Settings/Notifications/NotificationSoundsFactory.swift renamed to Adamant/Modules/Settings/Notifications/NotificationSounds/NotificationSoundsFactory.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ import Swinject
1010
import SwiftUI
1111

1212
struct NotificationSoundsFactory {
13-
private let assembler: Assembler
13+
private let parent: Assembler
14+
private let assemblies = [NotificationSoundAssembly()]
1415

1516
init(parent: Assembler) {
16-
assembler = .init([NotificationSoundAssembly()], parent: parent)
17+
self.parent = parent
1718
}
1819

1920
@MainActor
2021
func makeView(target: NotificationTarget) -> NotificationSoundsView {
21-
let viewModel = assembler.resolve(NotificationSoundsViewModel.self)!
22-
viewModel.setup(notificationTarget: target)
22+
let assembler = Assembler(assemblies, parent: parent)
23+
let viewModel = {
24+
assembler.resolver.resolve(NotificationSoundsViewModel.self, argument: target)!
25+
}
26+
2327
let view = NotificationSoundsView(viewModel: viewModel)
2428

2529
return view
@@ -28,11 +32,12 @@ struct NotificationSoundsFactory {
2832

2933
private struct NotificationSoundAssembly: Assembly {
3034
func assemble(container: Container) {
31-
container.register(NotificationSoundsViewModel.self) { r in
35+
container.register(NotificationSoundsViewModel.self) { (r, target: NotificationTarget) in
3236
NotificationSoundsViewModel(
3337
notificationsService: r.resolve(NotificationsService.self)!,
34-
target: .baseMessage
38+
target: target,
39+
dialogService: r.resolve(DialogService.self)!
3540
)
36-
}
41+
}.inObjectScope(.transient)
3742
}
3843
}

Adamant/Modules/Settings/Notifications/NotificationSoundsView.swift renamed to Adamant/Modules/Settings/Notifications/NotificationSounds/NotificationSoundsView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import SwiftUI
1010
import CommonKit
1111

1212
struct NotificationSoundsView: View {
13-
@ObservedObject var viewModel: NotificationSoundsViewModel
13+
@StateObject var viewModel: NotificationSoundsViewModel
1414

1515
@Environment(\.dismiss) var dismiss
1616

17+
init(viewModel: @escaping () -> NotificationSoundsViewModel) {
18+
_viewModel = .init(wrappedValue: viewModel())
19+
}
20+
1721
var body: some View {
1822
GeometryReader { _ in
1923
Form {
@@ -102,7 +106,7 @@ private extension NotificationSoundsView {
102106
Spacer()
103107
if viewModel.selectedSound == sound {
104108
Image(systemName: "checkmark")
105-
.foregroundColor(.black)
109+
.foregroundColor(Color(uiColor: .adamant.textColor))
106110
.frame(width: 30, height: 30)
107111
}
108112
}

Adamant/Modules/Settings/Notifications/NotificationSoundsViewModel.swift renamed to Adamant/Modules/Settings/Notifications/NotificationSounds/NotificationSoundsViewModel.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import AVFoundation
1515
final class NotificationSoundsViewModel: ObservableObject {
1616
private let notificationsService: NotificationsService
1717
private var notificationTarget: NotificationTarget
18+
private let dialogService: DialogService
1819

19-
private(set) var dismissAction = PassthroughSubject<Void,Never>()
20+
let dismissAction = PassthroughSubject<Void,Never>()
2021
@Published var isPresented: Bool = false
2122
@Published var selectedSound: NotificationSound = .inputDefault
2223
@Published var sounds: [NotificationSound] = [.none, .noteDefault, .inputDefault, .proud, .relax, .success, .note, .antic, .cheers, .chord, .droplet, .handoff, .milestone, .passage, .portal, .rattle, .rebound, .slide, .welcome]
@@ -25,10 +26,12 @@ final class NotificationSoundsViewModel: ObservableObject {
2526

2627
nonisolated init(
2728
notificationsService: NotificationsService,
28-
target: NotificationTarget
29+
target: NotificationTarget,
30+
dialogService: DialogService
2931
) {
3032
self.notificationsService = notificationsService
3133
self.notificationTarget = target
34+
self.dialogService = dialogService
3235

3336
Task { @MainActor in
3437
switch notificationTarget {
@@ -59,27 +62,33 @@ final class NotificationSoundsViewModel: ObservableObject {
5962
}
6063

6164
func playSound(_ sound: NotificationSound) {
62-
switch sound {
63-
case .none:
64-
break
65-
default:
66-
playSound(by: sound.fileName)
67-
}
65+
switch sound {
66+
case .none:
67+
break
68+
default:
69+
playSound(by: sound.fileName)
6870
}
69-
70-
private func playSound(by fileName: String) {
71+
}
72+
}
73+
74+
private extension NotificationSoundsViewModel {
75+
func playSound(by fileName: String) {
7176
guard let url = Bundle.main.url(forResource: fileName.replacingOccurrences(of: ".mp3", with: ""), withExtension: "mp3") else {
7277
return
7378
}
74-
79+
7580
do {
7681
try AVAudioSession.sharedInstance().setCategory(.playback)
7782
try AVAudioSession.sharedInstance().setActive(true)
7883
audioPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
7984
audioPlayer?.volume = 1.0
8085
audioPlayer?.play()
81-
} catch let error as NSError {
82-
print("error: \(error.localizedDescription)")
86+
} catch {
87+
dialogService.showError(
88+
withMessage: error.localizedDescription,
89+
supportEmail: true,
90+
error: error
91+
)
8392
}
8493
}
8594
}

0 commit comments

Comments
 (0)