chore: update haptic feedback for status interaction

This commit is contained in:
CMK 2021-08-05 16:54:00 +08:00
parent 6ee38d7d11
commit f7f248b6e9
1 changed files with 18 additions and 20 deletions

View File

@ -260,7 +260,7 @@ extension StatusProviderFacade {
// haptic feedback generator // haptic feedback generator
let generator = UIImpactFeedbackGenerator(style: .light) let generator = UIImpactFeedbackGenerator(style: .light)
let responseFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium) let responseFeedbackGenerator = UINotificationFeedbackGenerator()
status status
.compactMap { status -> (NSManagedObjectID, Mastodon.API.Favorites.FavoriteKind)? in .compactMap { status -> (NSManagedObjectID, Mastodon.API.Favorites.FavoriteKind)? in
@ -284,13 +284,13 @@ extension StatusProviderFacade {
.eraseToAnyPublisher() .eraseToAnyPublisher()
.switchToLatest() .switchToLatest()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.handleEvents { _ in .handleEvents(receiveSubscription: { _ in
generator.prepare() generator.prepare()
responseFeedbackGenerator.prepare() }, receiveOutput: { _, favoriteKind in
} receiveOutput: { _, favoriteKind in
generator.impactOccurred() generator.impactOccurred()
os_log("%{public}s[%{public}ld], %{public}s: [Like] update local status like status to: %s", ((#file as NSString).lastPathComponent), #line, #function, favoriteKind == .create ? "like" : "unlike") os_log("%{public}s[%{public}ld], %{public}s: [Like] update local status like status to: %s", ((#file as NSString).lastPathComponent), #line, #function, favoriteKind == .create ? "like" : "unlike")
} receiveCompletion: { completion in }, receiveCompletion: { completion in
responseFeedbackGenerator.prepare()
switch completion { switch completion {
case .failure: case .failure:
// TODO: handle error // TODO: handle error
@ -298,7 +298,7 @@ extension StatusProviderFacade {
case .finished: case .finished:
break break
} }
} })
.map { statusID, favoriteKind in .map { statusID, favoriteKind in
return context.apiService.favorite( return context.apiService.favorite(
statusID: statusID, statusID: statusID,
@ -309,14 +309,13 @@ extension StatusProviderFacade {
.switchToLatest() .switchToLatest()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak provider] completion in .sink { [weak provider] completion in
guard let provider = provider else { return } guard let _ = provider else { return }
if provider.view.window != nil {
responseFeedbackGenerator.impactOccurred()
}
switch completion { switch completion {
case .failure(let error): case .failure(let error):
responseFeedbackGenerator.notificationOccurred(.error)
os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
case .finished: case .finished:
responseFeedbackGenerator.notificationOccurred(.success)
os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request success", ((#file as NSString).lastPathComponent), #line, #function) os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request success", ((#file as NSString).lastPathComponent), #line, #function)
} }
} receiveValue: { response in } receiveValue: { response in
@ -370,7 +369,7 @@ extension StatusProviderFacade {
// haptic feedback generator // haptic feedback generator
let generator = UIImpactFeedbackGenerator(style: .light) let generator = UIImpactFeedbackGenerator(style: .light)
let responseFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium) let responseFeedbackGenerator = UINotificationFeedbackGenerator()
status status
.compactMap { status -> (NSManagedObjectID, Mastodon.API.Reblog.ReblogKind)? in .compactMap { status -> (NSManagedObjectID, Mastodon.API.Reblog.ReblogKind)? in
@ -394,10 +393,9 @@ extension StatusProviderFacade {
.eraseToAnyPublisher() .eraseToAnyPublisher()
.switchToLatest() .switchToLatest()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.handleEvents { _ in .handleEvents(receiveSubscription: { _ in
generator.prepare() generator.prepare()
responseFeedbackGenerator.prepare() }, receiveOutput: { _, reblogKind in
} receiveOutput: { _, reblogKind in
generator.impactOccurred() generator.impactOccurred()
switch reblogKind { switch reblogKind {
case .reblog: case .reblog:
@ -405,7 +403,8 @@ extension StatusProviderFacade {
case .undoReblog: case .undoReblog:
os_log("%{public}s[%{public}ld], %{public}s: [Reblog] update local status reblog status to: %s", ((#file as NSString).lastPathComponent), #line, #function, "unreblog") os_log("%{public}s[%{public}ld], %{public}s: [Reblog] update local status reblog status to: %s", ((#file as NSString).lastPathComponent), #line, #function, "unreblog")
} }
} receiveCompletion: { completion in }, receiveCompletion: { completion in
responseFeedbackGenerator.prepare()
switch completion { switch completion {
case .failure: case .failure:
// TODO: handle error // TODO: handle error
@ -413,7 +412,7 @@ extension StatusProviderFacade {
case .finished: case .finished:
break break
} }
} })
.map { statusID, reblogKind in .map { statusID, reblogKind in
return context.apiService.reblog( return context.apiService.reblog(
statusID: statusID, statusID: statusID,
@ -424,14 +423,13 @@ extension StatusProviderFacade {
.switchToLatest() .switchToLatest()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak provider] completion in .sink { [weak provider] completion in
guard let provider = provider else { return } guard let _ = provider else { return }
if provider.view.window != nil {
responseFeedbackGenerator.impactOccurred()
}
switch completion { switch completion {
case .failure(let error): case .failure(let error):
responseFeedbackGenerator.notificationOccurred(.error)
os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
case .finished: case .finished:
responseFeedbackGenerator.notificationOccurred(.success)
os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request success", ((#file as NSString).lastPathComponent), #line, #function) os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request success", ((#file as NSString).lastPathComponent), #line, #function)
} }
} receiveValue: { response in } receiveValue: { response in