-
Notifications
You must be signed in to change notification settings - Fork 204
/
PullToRefreshDemo.cs
143 lines (118 loc) · 4.29 KB
/
PullToRefreshDemo.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
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. 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 System;
using System.Collections.Generic;
using CoreGraphics;
using Foundation;
using SampleBrowser;
using Syncfusion.SfPullToRefresh;
using UIKit;
using System.Threading.Tasks;
namespace SampleBrowser
{
public class PullToRefreshDemo: SampleView
{
internal SfPullToRefresh pullToRefresh;
PullableContentView mainView;
internal BaseView baseView;
CustomScroll scrollView;
UILabel label;
public override void LayoutSubviews()
{
this.Superview.SendSubviewToBack(this);
pullToRefresh.Frame = new CGRect(0, 0, Frame.Width, Frame.Height);
}
public PullToRefreshDemo()
{
load();
mainView = new PullableContentView(baseView, scrollView, label);
pullToRefresh = new SfPullToRefresh();
pullToRefresh.RefreshContentThreshold = 0;
mainView.BackgroundColor = UIColor.FromRGBA(0.012f,0.608f,0.898f,1);
AddSubview(pullToRefresh);
pullToRefresh.Refreshing += PullToRefresh_Refreshing;
pullToRefresh.PullableContent = mainView;
this.OptionView = new Options(pullToRefresh);
}
private void PullToRefresh_Refreshing(object sender, RefreshingEventArgs e)
{
NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(3), new Action<NSTimer>(delegate {
baseView.model.Temp = (NSString)new Random().Next(10, 40).ToString();
baseView.updateBaseView();
baseView.selectedView.selectView();
baseView.selectedView.updateTemp();
e.Refreshed = true;
}));
}
void load()
{
scrollView = new CustomScroll();
scrollView.BackgroundColor = UIColor.FromRGBA(0, 0.478f, 0.667f, 1);
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.ShowsVerticalScrollIndicator = false;
int x = 0;
List<WeatherModel> array = addPopulationData();
baseView = new BaseView();
baseView.model = array[0];
baseView.updateBaseView();
for (int i = 0; i < array.Count; i++)
{
WeatherView button = new WeatherView(new CGRect(x, 20, 100, 100));
button.model = array[i];
button.baseView = baseView;
button.drawView();
if (i == 0)
{
baseView.selectedView = button;
button.selectView();
}
scrollView.AddSubview(button);
x += (int)button.Frame.Width;
}
scrollView.ContentSize = new CGSize(x, 0);
label = new UILabel();
label.Text = @"MorrisVille";
label.TextColor = UIColor.White;
label.Font = UIFont.SystemFontOfSize(14);
label.TextAlignment = UITextAlignment.Center;
}
List<WeatherModel> addPopulationData()
{
List<WeatherModel> array = new List<WeatherModel>();
NSDate now = NSDate.Now;
string[] imagesArray = new string[] { "Cloudy.png", "Humid.png", "Rainy.png", "Warm.png", "Windy.png", "Cloudy.png", "Humid.png" };
for (int i = 0; i < 7; i++)
{
int daysToAdd = i;
NSDateComponents components = new NSDateComponents();
components.Day = daysToAdd;
NSCalendar gregorian = NSCalendar.CurrentCalendar;
NSDate newDate2 = gregorian.DateByAddingComponents(components, now, NSCalendarOptions.None);
NSDateFormatter dateFormatter = new NSDateFormatter();
dateFormatter.DateFormat = "EEEE, MMMM dd";
NSDateFormatter dateFormatter1 = new NSDateFormatter();
dateFormatter1.DateFormat = "EEEE";
array.Add(new WeatherModel((NSString)dateFormatter.StringFor(newDate2), (NSString)imagesArray[i], (NSString)new Random().Next(10, 40).ToString(), (NSString)dateFormatter1.StringFor(newDate2)));
}
return array;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (pullToRefresh != null)
{
pullToRefresh.Refreshing -= PullToRefresh_Refreshing;
pullToRefresh.Dispose();
pullToRefresh = null;
}
}
base.Dispose(disposing);
}
}
}