Skip to content

Commit 95f2872

Browse files
committed
Fix detail map show Stop Sharing button for another user
1 parent edd637c commit 95f2872

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

DemoApp/StreamChat/Components/CustomAttachments/LocationAttachment/LocationDetailViewController.swift

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,18 @@ class LocationDetailViewController: UIViewController, ThemeProvider {
145145
return
146146
}
147147

148-
let isSharingLiveLocation = liveLocationAttachment.stoppedSharing == false
149-
148+
let isFromCurrentUser = messageController.message?.isSentByCurrentUser == true
150149
let dateFormatter = appearance.formatters.channelListMessageTimestamp
151150
let updatedAtText = dateFormatter.format(messageController.message?.updatedAt ?? Date())
152-
locationControlBanner.configure(
153-
isSharingEnabled: isSharingLiveLocation,
154-
statusText: isSharingLiveLocation
155-
? "Location sharing is active"
156-
: "Location last updated at \(updatedAtText)"
157-
)
151+
if liveLocationAttachment.stoppedSharing == false {
152+
locationControlBanner.configure(
153+
state: isFromCurrentUser
154+
? .currentUserSharing
155+
: .anotherUserSharing(lastUpdatedAtText: updatedAtText)
156+
)
157+
} else {
158+
locationControlBanner.configure(state: .ended(lastUpdatedAtText: updatedAtText))
159+
}
158160
}
159161
}
160162

@@ -263,20 +265,30 @@ class LocationControlBannerView: UIView, ThemeProvider {
263265
@objc private func stopSharingTapped() {
264266
onStopSharingTapped?()
265267
}
266-
267-
func configure(isSharingEnabled: Bool, statusText: String) {
268-
sharingButton.isEnabled = isSharingEnabled
269-
sharingButton.setTitle(
270-
isSharingEnabled ? "Stop Sharing" : "Live location ended",
271-
for: .normal
272-
)
273268

274-
let buttonColor = appearance.colorPalette.alert
275-
sharingButton.setTitleColor(
276-
isSharingEnabled ? buttonColor : buttonColor.withAlphaComponent(0.6),
277-
for: .normal
278-
)
279-
280-
locationUpdateLabel.text = statusText
269+
enum State {
270+
case currentUserSharing
271+
case anotherUserSharing(lastUpdatedAtText: String)
272+
case ended(lastUpdatedAtText: String)
273+
}
274+
275+
func configure(state: State) {
276+
switch state {
277+
case .currentUserSharing:
278+
sharingButton.isEnabled = true
279+
sharingButton.setTitle("Stop Sharing", for: .normal)
280+
sharingButton.setTitleColor(appearance.colorPalette.alert, for: .normal)
281+
locationUpdateLabel.text = "Location sharing is active"
282+
case .anotherUserSharing(let lastUpdatedAtText):
283+
sharingButton.isEnabled = false
284+
sharingButton.setTitle("Live Location", for: .normal)
285+
sharingButton.setTitleColor(appearance.colorPalette.alert, for: .normal)
286+
locationUpdateLabel.text = "Location last updated at \(lastUpdatedAtText)"
287+
case .ended(let lastUpdatedAtText):
288+
sharingButton.isEnabled = false
289+
sharingButton.setTitle("Live location ended", for: .normal)
290+
sharingButton.setTitleColor(appearance.colorPalette.alert.withAlphaComponent(0.6), for: .normal)
291+
locationUpdateLabel.text = "Location last updated at \(lastUpdatedAtText)"
292+
}
281293
}
282294
}

0 commit comments

Comments
 (0)