forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetailsView.cs
431 lines (367 loc) · 15.4 KB
/
DetailsView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using CoreAnimation;
using CoreGraphics;
using Foundation;
using Syncfusion.DataSource;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UIKit;
using Syncfusion.iOS.PopupLayout;
using System.Threading.Tasks;
namespace SampleBrowser
{
public class DetailsView : SampleView
{
#region Fields
UITableView tableView;
ContatsViewModel viewModel;
DataSource sfDataSource;
SfPopupLayout initialPopup;
#endregion
#region Constructor
public DetailsView()
{
tableView = new UITableView();
tableView.RowHeight = 70;
tableView.SeparatorColor = UIColor.Clear;
tableView.EstimatedRowHeight = 70;
tableView.AllowsSelection = false;
viewModel = new ContatsViewModel();
sfDataSource = new DataSource();
sfDataSource.Source = viewModel.ContactsList;
tableView.Source = new PopupTableViewSource(sfDataSource);
tableView.ContentInset = new UIEdgeInsets(-30, 0, 0 ,0);
tableView.BackgroundColor = UIColor.FromRGB(244, 244, 244);
tableView.SectionHeaderHeight = 50;
tableView.ScrollEnabled = true;
DisplayInitialPopup();
this.AddSubview(tableView);
}
private void DisplayInitialPopup()
{
initialPopup = new SfPopupLayout();
initialPopup.PopupView.AppearanceMode = AppearanceMode.OneButton;
initialPopup.PopupView.PopupStyle.HeaderBackgroundColor = UIColor.White;
initialPopup.PopupView.FooterHeight = initialPopup.PopupView.FooterHeight - 10;
initialPopup.PopupView.ShowFooter = true;
initialPopup.PopupView.ShowCloseButton = false;
initialPopup.PopupView.HeaderTitle = "Notification !";
initialPopup.PopupView.AcceptButtonText = "OK";
initialPopup.StaysOpen = true;
UILabel messageView = new UILabel();
messageView.Text = "Click on the contact tile to view the options";
messageView.TextColor = UIColor.Black;
messageView.LineBreakMode = UILineBreakMode.WordWrap;
messageView.Lines = 5;
messageView.TextAlignment = UITextAlignment.Center;
messageView.BackgroundColor = UIColor.White;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
{
initialPopup.PopupView.PopupStyle.HeaderFontSize = 14;
messageView.Font = UIFont.PreferredCaption1;
initialPopup.PopupView.Frame = new CGRect(-1, -1, (UIScreen.MainScreen.ApplicationFrame.Width / 10) * 8, 180);
}
else
{
initialPopup.PopupView.PopupStyle.HeaderFontSize = 20;
messageView.Font = UIFont.PreferredBody;
initialPopup.PopupView.Frame = new CGRect(-1, -1, -1, 200);
}
initialPopup.PopupView.ContentView = messageView;
initialPopup.Show();
}
#endregion
#region Override Methods
public override void LayoutSubviews()
{
tableView.Frame = new CGRect(0, 0, this.Frame.Width, this.Frame.Height);
base.LayoutSubviews();
}
#endregion
}
public class PopupTableViewSource : UITableViewSource
{
#region Field
DataSource dataSource;
#endregion
#region Constructor
public PopupTableViewSource(DataSource sfDataSource)
{
dataSource = sfDataSource;
}
#endregion
#region implemented abstract members of UITableViewDataSource
public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath)
{
var item = dataSource.DisplayItems[indexPath.Row];
if (item is Contacts)
{
PopupContactCell cell = tableView.DequeueReusableCell("TableCell") as PopupContactCell;
if (cell == null)
cell = new PopupContactCell();
cell.UpdateValue(item);
return cell;
}
return new UITableViewCell();
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return (nint)dataSource.DisplayItems.Count;
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return tableView.RowHeight;
}
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
var mainView = new UIView();
var view = new UILabel();
mainView.Layer.AddSublayer(new CALayer());
mainView.Layer.Frame = tableView.Frame;
mainView.Layer.Sublayers[0].BackgroundColor = UIColor.FromRGB(244, 244, 244).CGColor;
mainView.Layer.Sublayers[0].Frame = new CGRect(0, 0, 15, 50);
view.Frame = new CGRect(15, 20, tableView.Frame.Width - 15, 50);
view.BackgroundColor = UIColor.FromRGB(244, 244, 244);
view.Text = "Today";
view.TextColor = UIColor.FromRGB(0, 0, 0);
mainView.AddSubview(view);
return mainView;
}
#endregion
}
public class PopupContactCell : UITableViewCell
{
#region Field
private UIImageView imageView1;
private UIImageView imageView2;
private UILabel Label1;
private UILabel Label2;
private UILabel Label3;
private UILabel Label4;
internal static UILabel currentLabel;
UILabel overlayTags;
SfPopupLayout detailsPopup;
#endregion
#region Constructor
public PopupContactCell()
{
this.AutosizesSubviews = false;
this.BackgroundColor = UIColor.FromRGB(255, 255, 255);
Label1 = CreateLabel(Label1);
Label1.Font = UIFont.FromName("Helvetica Neue", 15);
Label2 = CreateLabel(Label2);
Label2.TextColor = UIColor.LightGray;
imageView1 = new UIImageView();
imageView2 = new UIImageView() { Alpha = 0.54f };
Label3 = new UILabel() { BackgroundColor = UIColor.FromRGB(244, 244, 244) };
Label4 = new UILabel() { BackgroundColor = UIColor.FromRGB(244, 244, 244) };
SelectionStyle = UITableViewCellSelectionStyle.Blue;
this.AddSubviews(new UIView[] { Label3, imageView1, Label1, Label2, imageView2, Label4 });
this.Layer.AddSublayer(new CALayer());
}
#endregion
#region Private Method
private UILabel CreateLabel(UILabel label)
{
label = new UILabel();
label.TextColor = UIColor.Black;
label.TextAlignment = UITextAlignment.Left;
label.LineBreakMode = UILineBreakMode.CharacterWrap;
label.Font = UIFont.FromName("Helvetica Neue", 11);
return label;
}
Random r = new Random();
public void UpdateValue(object obj)
{
var contact = obj as Contacts;
Label1.Text = contact.ContactName;
Label2.Text = contact.ContactNumber;
imageView1.Image = UIImage.FromBundle("Images/PopupImage" + r.Next(1, 10) + ".png");
imageView2.Image = UIImage.FromBundle("Images/Popup_CallerImage.png");
}
#endregion
#region override
public override void LayoutSubviews()
{
this.Layer.Frame = this.Frame;
this.Layer.Sublayers[0].BackgroundColor = UIColor.FromRGB(244, 244, 244).CGColor;
this.Layer.Sublayers[0].Frame = new CGRect(0, 0, this.Frame.Width, 10);
nfloat y = 0;
foreach (var subview in this.Subviews)
{
if (subview is UILabel && !(subview == imageView1) && subview != Label3 && subview != Label4)
{
subview.Frame = new CoreGraphics.CGRect(imageView1.Frame.Right + 20, y + 20, (this.Frame.Width - imageView1.Frame.Right - 85), this.Frame.Height / 3);
y += subview.Frame.Height;
}
else if (subview == imageView1)
{
subview.Frame = new CGRect(Label3.Frame.Right + 10, 23, 33, 35);
}
else if (subview is UIImageView && subview == imageView2)
{
subview.Frame = new CoreGraphics.CGRect(Label1.Frame.Right + 20, 28, 25, this.Frame.Height - 48);
}
else if (subview == Label3)
{
subview.Frame = new CGRect(0, 0, 10, this.Frame.Height);
}
else if (subview == Label4)
{
subview.Frame = new CGRect(imageView2.Frame.Right + 10, 0, 16, this.Frame.Height);
}
}
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);
foreach (var view in this.Subviews)
{
if (view == Label1)
{
currentLabel = Label1;
break;
}
}
DisplayDetailsPopup();
}
private void DisplayDetailsPopup()
{
detailsPopup = new SfPopupLayout();
detailsPopup.PopupView.BackgroundColor = UIColor.FromRGB(255, 255, 255);
detailsPopup.PopupView.PopupStyle.BorderThickness = 5;
detailsPopup.PopupView.ShowHeader = false;
detailsPopup.PopupView.ShowFooter = false;
detailsPopup.PopupView.Frame = new CGRect(-1, -1, this.Frame.Width - Label4.Frame.Width - 5, 150);
detailsPopup.PopupView.ContentView = GetCustomPopupView();
// In iPhone the parent is directly UITableView but in iPOD and iPAD the immedidate super view is not UITableView. Hence checked superview based on condition.
if ((this.Frame.Bottom + detailsPopup.PopupView.Frame.Height) -
(UIDevice.CurrentDevice.Model == "iPhone" ?
(this.Superview as UITableView).ContentOffset.Y :
(this.Superview.Superview as UITableView).ContentOffset.Y) +10 <= this.Superview.Frame.Bottom)
{
detailsPopup.ShowRelativeToView(this, RelativePosition.AlignBottom, 10, 0);
}
else
{
detailsPopup.ShowRelativeToView(this, RelativePosition.AlignTop, 10, 0);
}
}
private UIView GetCustomPopupView()
{
UIImageView imageView1;
UIImageView imageView2;
UIImageView imageView3;
UILabel label1;
UILabel label2;
UILabel label3;
UIView view1;
UIView view2;
UIView view3;
UIView mainView;
var height = detailsPopup.PopupView.Frame.Height / 3;
imageView1 = new UIImageView();
imageView1.Image = UIImage.FromBundle("Images/Popup_SendMessage.png");
imageView1.Alpha = 0.54f;
imageView1.Frame = new CGRect(10, 15, 20, 20);
label1 = new UILabel();
label1.Text = "Send Message";
var tapGesture1 = new UITapGestureRecognizer(DisplayToast) { NumberOfTapsRequired = 1 };
label1.AddGestureRecognizer(tapGesture1);
label1.TextColor = UIColor.FromRGB(0, 0, 0);
label1.Alpha = 0.54f;
label1.Tag = 11;
label1.UserInteractionEnabled = true;
label1.Frame = new CGRect(50, 13, this.Frame.Width, 20);
view1 = new UIView();
view1.AddSubview(imageView1);
view1.AddSubview(label1);
view1.Frame = new CGRect(10, 0, this.Frame.Width, height);
imageView2 = new UIImageView();
imageView2.Image = UIImage.FromBundle("Images/Popup_BlockContact.png");
imageView2.Alpha = 0.54f;
imageView2.Frame = new CGRect(10, 13, 22, 22);
label2 = new UILabel();
label2.Text = "Block/report contact";
label2.TextColor = UIColor.FromRGB(0, 0, 0);
label2.UserInteractionEnabled = true;
var tapGesture2 = new UITapGestureRecognizer(DisplayToast) { NumberOfTapsRequired = 1 };
label2.AddGestureRecognizer(tapGesture2);
label2.Alpha = 0.54f;
label2.Tag = 22;
label2.Frame = new CGRect(50, 13, this.Frame.Width, 20);
view2 = new UIView();
view2.AddSubview(imageView2);
view2.AddSubview(label2);
view2.Frame = new CGRect(10, height, this.Frame.Width, height);
imageView3 = new UIImageView();
imageView3.Image = UIImage.FromBundle("Images/Popup_ContactInfo.png");
imageView3.Alpha = 0.54f;
imageView3.Frame = new CGRect(10, 13, 22, 22);
label3 = new UILabel();
label3.Text = "Contact Details";
label3.UserInteractionEnabled = true;
label3.TextColor = UIColor.FromRGB(0, 0, 0);
var tapGesture3 = new UITapGestureRecognizer(DisplayToast) { NumberOfTapsRequired = 1 };
label3.AddGestureRecognizer(tapGesture3);
label3.Alpha = 0.54f;
label3.Tag = 33;
label3.Frame = new CGRect(50, 13, this.Frame.Width, 20);
view3 = new UIView();
view3.AddSubview(imageView3);
view3.AddSubview(label3);
view3.Frame = new CGRect(10, height * 2, this.Frame.Width, height);
mainView = new UIView();
mainView.BackgroundColor = UIColor.FromRGB(255, 255, 255);
mainView.AddSubview(view1);
mainView.AddSubview(view2);
mainView.AddSubview(view3);
return mainView;
}
async void DisplayToast(UITapGestureRecognizer tasture)
{
overlayTags = new UILabel();
overlayTags.Hidden = false;
if(tasture.View.Tag == 11)
overlayTags.Text = "Message sent";
else if(tasture.View.Tag == 22)
overlayTags.Text = "Contact blocked";
else if(tasture.View.Tag == 33)
overlayTags.Text = "No outgoing call history";
overlayTags.Layer.CornerRadius = 20f;
overlayTags.TextColor = UIColor.White;
overlayTags.TextAlignment = UITextAlignment.Center;
overlayTags.ClipsToBounds = true;
//overlayTags.Alpha = 0.0f;
overlayTags.Font = UIFont.SystemFontOfSize(14);
overlayTags.BackgroundColor = UIColor.FromRGB(101.0f / 255.0f, 101.0f / 255.0f, 101.0f / 255.0f);
overlayTags.Layer.ZPosition = 1000;
UIApplication.SharedApplication.KeyWindow.RootViewController.View.AddSubview(overlayTags);
overlayTags.Frame = new CGRect((UIScreen.MainScreen.Bounds.Width / 2) - 100, UIScreen.MainScreen.Bounds.Height - 70, 200, 40);
UIView.Animate(0.5, 0, UIViewAnimationOptions.CurveLinear, () =>
{
overlayTags.Alpha = 1.0f;
},
() =>
{
UIView.Animate(3.0, () =>
{
overlayTags.Alpha = 0.0f;
});
}
);
detailsPopup.IsOpen = false;
await Task.Delay(700);
overlayTags.RemoveFromSuperview();
}
#endregion
}
}