@@ -34,6 +34,15 @@ open class FunChatMessageLocationCell: FunChatMessageBaseCell {
34
34
} ( )
35
35
36
36
public var mapViewLeft : UIView ?
37
+
38
+ public var mapImageViewLeft : UIImageView = {
39
+ let imageView = UIImageView ( )
40
+ imageView. translatesAutoresizingMaskIntoConstraints = false
41
+ imageView. contentMode = . scaleAspectFill
42
+ imageView. clipsToBounds = true
43
+ return imageView
44
+ } ( )
45
+
37
46
let backgroundViewLeft = UIView ( )
38
47
39
48
// Right
@@ -64,8 +73,31 @@ open class FunChatMessageLocationCell: FunChatMessageBaseCell {
64
73
} ( )
65
74
66
75
public var mapViewRight : UIView ?
76
+
77
+ public var mapImageViewRight : UIImageView = {
78
+ let imageView = UIImageView ( )
79
+ imageView. translatesAutoresizingMaskIntoConstraints = false
80
+ imageView. contentMode = . scaleAspectFill
81
+ imageView. clipsToBounds = true
82
+ return imageView
83
+ } ( )
84
+
67
85
let backgroundViewRight = UIView ( )
68
86
87
+ lazy var pointImageRight : UIImageView = {
88
+ let image = UIImageView ( )
89
+ image. translatesAutoresizingMaskIntoConstraints = false
90
+ image. image = coreLoader. loadImage ( " location_point " )
91
+ return image
92
+ } ( )
93
+
94
+ lazy var pointImageLeft : UIImageView = {
95
+ let image = UIImageView ( )
96
+ image. translatesAutoresizingMaskIntoConstraints = false
97
+ image. image = coreLoader. loadImage ( " location_point " )
98
+ return image
99
+ } ( )
100
+
69
101
override public init ( style: UITableViewCell . CellStyle , reuseIdentifier: String ? ) {
70
102
super. init ( style: style, reuseIdentifier: reuseIdentifier)
71
103
commonUI ( )
@@ -122,33 +154,26 @@ open class FunChatMessageLocationCell: FunChatMessageBaseCell {
122
154
subTitleLabelLeft. topAnchor. constraint ( equalTo: titleLabelLeft. bottomAnchor, constant: 4 ) ,
123
155
] )
124
156
125
- if let map = NEChatKitClient . instance. delegate? . getCellMapView ? ( ) as? UIView {
126
- mapViewLeft = map
127
- backgroundViewLeft. addSubview ( map)
128
- map. translatesAutoresizingMaskIntoConstraints = false
129
- NSLayoutConstraint . activate ( [
130
- map. leftAnchor. constraint ( equalTo: backgroundViewLeft. leftAnchor) ,
131
- map. bottomAnchor. constraint ( equalTo: backgroundViewLeft. bottomAnchor) ,
132
- map. rightAnchor. constraint ( equalTo: backgroundViewLeft. rightAnchor) ,
133
- map. topAnchor. constraint ( equalTo: subTitleLabelLeft. bottomAnchor, constant: 4 ) ,
134
- ] )
135
-
136
- let pointImage = UIImageView ( )
137
- pointImage. translatesAutoresizingMaskIntoConstraints = false
138
- pointImage. image = coreLoader. loadImage ( " location_point " )
139
- map. addSubview ( pointImage)
140
- NSLayoutConstraint . activate ( [
141
- pointImage. centerXAnchor. constraint ( equalTo: map. centerXAnchor) ,
142
- pointImage. bottomAnchor. constraint ( equalTo: map. bottomAnchor, constant: - 30 ) ,
143
- ] )
144
- } else {
145
- backgroundViewLeft. addSubview ( emptyLabelLeft)
146
- NSLayoutConstraint . activate ( [
147
- emptyLabelLeft. leftAnchor. constraint ( equalTo: backgroundViewLeft. leftAnchor) ,
148
- emptyLabelLeft. rightAnchor. constraint ( equalTo: backgroundViewLeft. rightAnchor) ,
149
- emptyLabelLeft. bottomAnchor. constraint ( equalTo: backgroundViewLeft. bottomAnchor, constant: - 40 ) ,
150
- ] )
151
- }
157
+ backgroundViewLeft. addSubview ( mapImageViewLeft)
158
+ NSLayoutConstraint . activate ( [
159
+ mapImageViewLeft. leftAnchor. constraint ( equalTo: backgroundViewLeft. leftAnchor) ,
160
+ mapImageViewLeft. bottomAnchor. constraint ( equalTo: backgroundViewLeft. bottomAnchor) ,
161
+ mapImageViewLeft. rightAnchor. constraint ( equalTo: backgroundViewLeft. rightAnchor) ,
162
+ mapImageViewLeft. topAnchor. constraint ( equalTo: subTitleLabelLeft. bottomAnchor, constant: 4 ) ,
163
+ ] )
164
+
165
+ mapImageViewLeft. addSubview ( pointImageLeft)
166
+ NSLayoutConstraint . activate ( [
167
+ pointImageLeft. centerXAnchor. constraint ( equalTo: mapImageViewLeft. centerXAnchor) ,
168
+ pointImageLeft. bottomAnchor. constraint ( equalTo: mapImageViewLeft. bottomAnchor, constant: - 30 ) ,
169
+ ] )
170
+
171
+ backgroundViewLeft. addSubview ( emptyLabelLeft)
172
+ NSLayoutConstraint . activate ( [
173
+ emptyLabelLeft. leftAnchor. constraint ( equalTo: backgroundViewLeft. leftAnchor) ,
174
+ emptyLabelLeft. rightAnchor. constraint ( equalTo: backgroundViewLeft. rightAnchor) ,
175
+ emptyLabelLeft. bottomAnchor. constraint ( equalTo: backgroundViewLeft. bottomAnchor, constant: - 40 ) ,
176
+ ] )
152
177
}
153
178
154
179
open func commonUIRight( ) {
@@ -192,33 +217,26 @@ open class FunChatMessageLocationCell: FunChatMessageBaseCell {
192
217
subTitleLabelRight. topAnchor. constraint ( equalTo: titleLabelRight. bottomAnchor, constant: 4 ) ,
193
218
] )
194
219
195
- if let map = NEChatKitClient . instance. delegate? . getCellMapView ? ( ) as? UIView {
196
- mapViewRight = map
197
- backgroundViewRight. addSubview ( map)
198
- map. translatesAutoresizingMaskIntoConstraints = false
199
- NSLayoutConstraint . activate ( [
200
- map. leftAnchor. constraint ( equalTo: backgroundViewRight. leftAnchor) ,
201
- map. bottomAnchor. constraint ( equalTo: backgroundViewRight. bottomAnchor) ,
202
- map. rightAnchor. constraint ( equalTo: backgroundViewRight. rightAnchor) ,
203
- map. topAnchor. constraint ( equalTo: subTitleLabelRight. bottomAnchor, constant: 4 ) ,
204
- ] )
205
-
206
- let pointImage = UIImageView ( )
207
- pointImage. translatesAutoresizingMaskIntoConstraints = false
208
- pointImage. image = coreLoader. loadImage ( " location_point " )
209
- map. addSubview ( pointImage)
210
- NSLayoutConstraint . activate ( [
211
- pointImage. centerXAnchor. constraint ( equalTo: map. centerXAnchor) ,
212
- pointImage. bottomAnchor. constraint ( equalTo: map. bottomAnchor, constant: - 30 ) ,
213
- ] )
214
- } else {
215
- backgroundViewRight. addSubview ( emptyLabelRight)
216
- NSLayoutConstraint . activate ( [
217
- emptyLabelRight. leftAnchor. constraint ( equalTo: backgroundViewRight. leftAnchor) ,
218
- emptyLabelRight. rightAnchor. constraint ( equalTo: backgroundViewRight. rightAnchor) ,
219
- emptyLabelRight. bottomAnchor. constraint ( equalTo: backgroundViewRight. bottomAnchor, constant: - 40 ) ,
220
- ] )
221
- }
220
+ backgroundViewRight. addSubview ( mapImageViewRight)
221
+ NSLayoutConstraint . activate ( [
222
+ mapImageViewRight. leftAnchor. constraint ( equalTo: backgroundViewRight. leftAnchor) ,
223
+ mapImageViewRight. bottomAnchor. constraint ( equalTo: backgroundViewRight. bottomAnchor) ,
224
+ mapImageViewRight. rightAnchor. constraint ( equalTo: backgroundViewRight. rightAnchor) ,
225
+ mapImageViewRight. topAnchor. constraint ( equalTo: subTitleLabelRight. bottomAnchor, constant: 4 ) ,
226
+ ] )
227
+
228
+ mapImageViewRight. addSubview ( pointImageRight)
229
+ NSLayoutConstraint . activate ( [
230
+ pointImageRight. centerXAnchor. constraint ( equalTo: mapImageViewRight. centerXAnchor) ,
231
+ pointImageRight. bottomAnchor. constraint ( equalTo: mapImageViewRight. bottomAnchor, constant: - 30 ) ,
232
+ ] )
233
+
234
+ backgroundViewRight. addSubview ( emptyLabelRight)
235
+ NSLayoutConstraint . activate ( [
236
+ emptyLabelRight. leftAnchor. constraint ( equalTo: backgroundViewRight. leftAnchor) ,
237
+ emptyLabelRight. rightAnchor. constraint ( equalTo: backgroundViewRight. rightAnchor) ,
238
+ emptyLabelRight. bottomAnchor. constraint ( equalTo: backgroundViewRight. bottomAnchor, constant: - 40 ) ,
239
+ ] )
222
240
}
223
241
224
242
override open func showLeftOrRight( showRight: Bool ) {
@@ -233,14 +251,26 @@ open class FunChatMessageLocationCell: FunChatMessageBaseCell {
233
251
let subTitleLabel = isSend ? subTitleLabelRight : subTitleLabelLeft
234
252
let mapView = isSend ? mapViewRight : mapViewLeft
235
253
let bubbleW = isSend ? bubbleWRight : bubbleWLeft
254
+ let mapImageView = isSend ? mapImageViewRight : mapImageViewLeft
236
255
237
256
bubbleW? . constant = kScreenWidth <= 320 ? 222 : 242 // 适配小屏幕
238
257
258
+ let emptyLabel = isSend ? emptyLabelRight : emptyLabelLeft
259
+ let pointImage = isSend ? pointImageRight : pointImageLeft
260
+
239
261
if let m = model as? MessageLocationModel {
240
262
titleLabel. text = m. title
241
263
subTitleLabel. text = m. subTitle
242
- if let lat = m. lat, let lng = m. lng, let map = mapView {
243
- NEChatKitClient . instance. delegate? . setMapviewLocation ? ( lat: lat, lng: lng, mapview: map)
264
+ if let lat = m. lat, let lng = m. lng {
265
+ if let url = NEChatKitClient . instance. delegate? . getMapImageUrl ? ( lat: lat, lng: lng) {
266
+ NELog . infoLog ( className ( ) , desc: #function + " location image url = \( url) " )
267
+ mapImageView. sd_setImage ( with: URL ( string: url) , placeholderImage: coreLoader. loadImage ( " chat_map_default " ) )
268
+ emptyLabel. isHidden = true
269
+ pointImage. isHidden = false
270
+ } else {
271
+ emptyLabel. isHidden = false
272
+ pointImage. isHidden = true
273
+ }
244
274
}
245
275
}
246
276
}
0 commit comments