Skip to content

Commit 88f8fee

Browse files
committed
pr and design suggestions
1 parent a686eef commit 88f8fee

File tree

17 files changed

+206
-180
lines changed

17 files changed

+206
-180
lines changed

ElementX/Resources/Localizations/en-US.lproj/Localizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
"common_empty_file" = "Empty file";
227227
"common_encryption" = "Encryption";
228228
"common_encryption_enabled" = "Encryption enabled";
229-
"common_ends_in_time_ios" = "Ends %1$@";
229+
"common_ends_at" = "Ends at %1$@";
230230
"common_enter_your_pin" = "Enter your PIN";
231231
"common_error" = "Error";
232232
"common_everyone" = "Everyone";

ElementX/Resources/Localizations/en.lproj/Localizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
"common_empty_file" = "Empty file";
227227
"common_encryption" = "Encryption";
228228
"common_encryption_enabled" = "Encryption enabled";
229-
"common_ends_in_time_ios" = "Ends %1$@";
229+
"common_ends_at" = "Ends at %1$@";
230230
"common_enter_your_pin" = "Enter your PIN";
231231
"common_error" = "Error";
232232
"common_everyone" = "Everyone";

ElementX/Sources/Generated/Strings.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ internal enum L10n {
500500
internal static var commonEncryption: String { return L10n.tr("Localizable", "common_encryption") }
501501
/// Encryption enabled
502502
internal static var commonEncryptionEnabled: String { return L10n.tr("Localizable", "common_encryption_enabled") }
503-
/// Ends %1$@
504-
internal static func commonEndsInTimeIos(_ p1: Any) -> String {
505-
return L10n.tr("Localizable", "common_ends_in_time_ios", String(describing: p1))
503+
/// Ends at %1$@
504+
internal static func commonEndsAt(_ p1: Any) -> String {
505+
return L10n.tr("Localizable", "common_ends_at", String(describing: p1))
506506
}
507507
/// Enter your PIN
508508
internal static var commonEnterYourPin: String { return L10n.tr("Localizable", "common_enter_your_pin") }

ElementX/Sources/Other/Extensions/Date.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ extension Date {
3434
}
3535
}
3636

37+
/// The date of an expiration formatted with the minimal necessary units given how long in the future it is.
38+
func formattedExpiration() -> String {
39+
let calendar = Calendar.current
40+
let now = Date.now
41+
42+
guard let tomorrow = calendar.date(byAdding: .hour, value: 24, to: now),
43+
let oneYearFromNow = calendar.date(byAdding: .year, value: 1, to: now) else {
44+
return formatted(date: .omitted, time: .shortened)
45+
}
46+
47+
if self < tomorrow {
48+
return formatted(date: .omitted, time: .shortened)
49+
} else if self < oneYearFromNow {
50+
return formatted(.dateTime.day().month())
51+
} else {
52+
return formatted(.dateTime.year())
53+
}
54+
}
55+
3756
/// Similar to ``formattedMinimal`` but returning "Today" instead of the time and
3857
/// including the year when it the date is from a previous year (rather than over a year ago).
3958
func formattedDateSeparator() -> String {
@@ -60,14 +79,15 @@ extension Date {
6079
formatted(date: .omitted, time: .shortened)
6180
}
6281

63-
/// A fixed date used for mocks, previews etc.
64-
static var mock: Date {
65-
DateComponents(calendar: .current, year: 2007, month: 1, day: 9, hour: 9, minute: 41).date ?? .now
82+
/// A fixed date representing today at 4:20 AM, used for mocks and previews.
83+
static var mockToday420: Date {
84+
// swiftlint:disable:next force_unwrap
85+
Calendar.current.date(bySettingHour: 4, minute: 20, second: 0, of: .now)!
6686
}
6787

6888
/// A fixed date used for mocks, previews etc.
69-
static var inOneMinute: Date {
70-
Date.now.addingTimeInterval(60)
89+
static var mock: Date {
90+
DateComponents(calendar: .current, year: 2007, month: 1, day: 9, hour: 9, minute: 41).date ?? .now
7191
}
7292
}
7393

ElementX/Sources/Other/SwiftUI/PreviewScrollView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import SwiftUI
99

10+
/// Only use in Previews! This useful scroll view allows you to still have a scroll view when previewing in Xcode
11+
/// but ignores it when running the tests, which allows you to still use it's content directly in preview tests
12+
/// and render the preview with `sizeThatFits` layout.
1013
struct PreviewScrollView<Content: View>: View {
1114
var content: () -> Content
1215

ElementX/Sources/Other/SwiftUI/Views/LocationMarkerView.swift

Lines changed: 45 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,91 +9,11 @@
99
import Compound
1010
import SwiftUI
1111

12-
enum LocationMarkerKind {
13-
case pin
14-
case staticUser(UserProfileProxy)
15-
case liveUser(UserProfileProxy)
16-
case placeholder
17-
18-
var id: String {
19-
switch self {
20-
case .pin, .placeholder:
21-
UUID().uuidString
22-
case .staticUser(let profile), .liveUser(let profile):
23-
profile.userID
24-
}
25-
}
26-
27-
var displayName: String? {
28-
switch self {
29-
case .pin, .placeholder:
30-
nil
31-
case .staticUser(let profile), .liveUser(let profile):
32-
profile.displayName
33-
}
34-
}
35-
36-
var userProfile: UserProfileProxy? {
37-
switch self {
38-
case .pin, .placeholder:
39-
nil
40-
case .staticUser(let profile), .liveUser(let profile):
41-
profile
42-
}
43-
}
44-
}
45-
4612
struct LocationMarkerView: View {
4713
var kind: LocationMarkerKind
48-
49-
var fillColor: Color {
50-
switch kind {
51-
case .pin, .staticUser:
52-
.compound.bgCanvasDefault
53-
case .liveUser:
54-
.compound.iconAccentPrimary
55-
case .placeholder:
56-
.compound.bgSubtleSecondary
57-
}
58-
}
59-
60-
var externalStrokeColor: Color {
61-
switch kind {
62-
case .pin, .staticUser:
63-
.compound.iconSecondaryAlpha
64-
case .liveUser:
65-
.compound.iconAccentPrimary
66-
case .placeholder:
67-
.compound.iconDisabled
68-
}
69-
}
70-
71-
var internalStrokeColor: Color {
72-
switch kind {
73-
case .pin, .staticUser:
74-
.compound.iconSecondaryAlpha
75-
case .liveUser:
76-
.compound.bgCanvasDefault
77-
case .placeholder:
78-
.compound.iconDisabled
79-
}
80-
}
81-
82-
var dotColor: Color {
83-
switch kind {
84-
case .placeholder:
85-
.compound.iconDisabled
86-
default:
87-
.compound.iconPrimary
88-
}
89-
}
90-
9114
@ScaledMetric var size: CGFloat = 42
9215
var mediaProvider: MediaProviderProtocol?
9316

94-
private let circleCenter = CGPoint(x: 21, y: 21) // in SVG space
95-
private let circleRadius: CGFloat = 6 // in SVG space
96-
9717
var body: some View {
9818
// Generated from the SVG
9919
Canvas { context, canvasSize in
@@ -163,6 +83,51 @@ struct LocationMarkerView: View {
16383
dimensions[.bottom]
16484
}
16585
}
86+
87+
private let circleCenter = CGPoint(x: 21, y: 21) // in SVG space
88+
private let circleRadius: CGFloat = 6 // in SVG space
89+
90+
private var fillColor: Color {
91+
switch kind {
92+
case .pin, .staticUser:
93+
.compound.bgCanvasDefault
94+
case .liveUser:
95+
.compound.iconAccentPrimary
96+
case .placeholder:
97+
.compound.bgSubtleSecondary
98+
}
99+
}
100+
101+
private var externalStrokeColor: Color {
102+
switch kind {
103+
case .pin, .staticUser:
104+
.compound.iconSecondaryAlpha
105+
case .liveUser:
106+
.compound.iconAccentPrimary
107+
case .placeholder:
108+
.compound.iconDisabled
109+
}
110+
}
111+
112+
private var internalStrokeColor: Color {
113+
switch kind {
114+
case .pin, .staticUser:
115+
.compound.iconSecondaryAlpha
116+
case .liveUser:
117+
.compound.bgCanvasDefault
118+
case .placeholder:
119+
.compound.iconDisabled
120+
}
121+
}
122+
123+
private var dotColor: Color {
124+
switch kind {
125+
case .placeholder:
126+
.compound.iconDisabled
127+
default:
128+
.compound.iconPrimary
129+
}
130+
}
166131
}
167132

168133
struct LocationMarkerView_Previews: PreviewProvider, TestablePreview {

ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct LocationSharingScreenViewState: BindableState {
3434
self.mapURLBuilder = mapURLBuilder
3535
self.showLiveLocationSharingButton = showLiveLocationSharingButton
3636
self.ownUserID = ownUserID
37+
3738
userProfile = switch interactionMode {
3839
case .viewStatic(let locationData):
3940
.init(sender: locationData.sender)
@@ -51,6 +52,7 @@ struct LocationSharingScreenViewState: BindableState {
5152
let mapURLBuilder: MapTilerURLBuilderProtocol
5253
let showLiveLocationSharingButton: Bool
5354
let ownUserID: String
55+
var userProfile: UserProfileProxy
5456

5557
var isOwnUser: Bool {
5658
userProfile.userID == ownUserID
@@ -101,8 +103,6 @@ struct LocationSharingScreenViewState: BindableState {
101103
}
102104
}
103105

104-
var userProfile: UserProfileProxy
105-
106106
var locationMarkerKind: LocationMarkerKind {
107107
switch interactionMode {
108108
case .picker:
@@ -170,3 +170,37 @@ extension AlertInfo where T == LocationSharingViewError {
170170
}
171171
}
172172
}
173+
174+
enum LocationMarkerKind {
175+
case pin
176+
case staticUser(UserProfileProxy)
177+
case liveUser(UserProfileProxy)
178+
case placeholder
179+
180+
var id: String {
181+
switch self {
182+
case .pin, .placeholder:
183+
UUID().uuidString
184+
case .staticUser(let profile), .liveUser(let profile):
185+
profile.userID
186+
}
187+
}
188+
189+
var displayName: String? {
190+
switch self {
191+
case .pin, .placeholder:
192+
nil
193+
case .staticUser(let profile), .liveUser(let profile):
194+
profile.displayName
195+
}
196+
}
197+
198+
var userProfile: UserProfileProxy? {
199+
switch self {
200+
case .pin, .placeholder:
201+
nil
202+
case .staticUser(let profile), .liveUser(let profile):
203+
profile
204+
}
205+
}
206+
}

ElementX/Sources/Screens/Timeline/View/Style/TimelineItemBubbledStylerView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ private extension EventBasedTimelineItemProtocol {
272272
properties.replyDetails != nil ||
273273
properties.isThreaded ? defaultInsets : .zero
274274
case let liveLocationTimelineItem as LiveLocationRoomTimelineItem:
275-
return liveLocationTimelineItem.content.lastLocation?.geoURI == nil ||
276-
properties.replyDetails != nil ||
275+
return properties.replyDetails != nil ||
277276
properties.isThreaded ? defaultInsets : .zero
278277
default:
279278
return defaultInsets

ElementX/Sources/Screens/Timeline/View/Style/TimelineItemSendInfoLabel.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,10 @@ private extension TimelineItemSendInfo {
193193

194194
private extension LiveLocationRoomTimelineItem {
195195
var layout: TimelineItemSendInfo.LayoutType {
196-
if content.lastLocation != nil {
197-
if content.isLive, isOutgoing {
198-
.hidden
199-
} else {
200-
.overlay(capsuleStyle: true)
201-
}
196+
if content.isLive, isOutgoing {
197+
.hidden
202198
} else {
203-
.horizontal()
199+
.overlay(capsuleStyle: true)
204200
}
205201
}
206202
}

0 commit comments

Comments
 (0)