@@ -145,16 +145,18 @@ class LocationDetailViewController: UIViewController, ThemeProvider {
145
145
return
146
146
}
147
147
148
- let isSharingLiveLocation = liveLocationAttachment. stoppedSharing == false
149
-
148
+ let isFromCurrentUser = messageController. message? . isSentByCurrentUser == true
150
149
let dateFormatter = appearance. formatters. channelListMessageTimestamp
151
150
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
+ }
158
160
}
159
161
}
160
162
@@ -263,20 +265,30 @@ class LocationControlBannerView: UIView, ThemeProvider {
263
265
@objc private func stopSharingTapped( ) {
264
266
onStopSharingTapped ? ( )
265
267
}
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
- )
273
268
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
+ }
281
293
}
282
294
}
0 commit comments