-
Notifications
You must be signed in to change notification settings - Fork 6
/
HGI.View.ItemFull.pas
257 lines (231 loc) · 7.06 KB
/
HGI.View.ItemFull.pas
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
unit HGI.View.ItemFull;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Layouts, FMX.Controls.Presentation, HGI.Item,
FMX.Filter.Effects, FMX.Edit, HGI.View.Item;
type
TFramePackageItemFull = class(TFrame)
RectangleShd: TRectangle;
RectangleBG: TRectangle;
Layout1: TLayout;
RectangleImage: TRectangle;
LabelInfo: TLabel;
Layout3: TLayout;
LayoutOS: TLayout;
LabelLicense: TLabel;
Layout4: TLayout;
ButtonInstall: TButton;
ButtonWebSite: TButton;
Layout2: TLayout;
LabelTitle: TLabel;
VertScrollBoxText: TVertScrollBox;
LabelDesc: TLabel;
Label1: TLabel;
LabelDate: TLabel;
Label2: TLabel;
LabelTags: TLabel;
ButtonBuy: TButton;
Path1: TPath;
Label3: TLabel;
FlowLayoutPlatforms: TFlowLayout;
LayoutPfWin: TLayout;
PathAndroid: TPath;
PathIOS: TPath;
PathLinux: TPath;
PathMacOS: TPath;
PathWindows: TPath;
LayoutPfLin: TLayout;
LayoutPfAndr: TLayout;
LayoutPfIOS: TLayout;
LayoutPfMac: TLayout;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
ButtonClose: TButton;
Path2: TPath;
Label10: TLabel;
EditId: TEdit;
ButtonDownload: TButton;
Path3: TPath;
Label9: TLabel;
EditLibUrl: TEdit;
CircleGitHub: TCircle;
PathGutHub: TPath;
procedure FlowLayoutPlatformsResize(Sender: TObject);
procedure RectangleBGResize(Sender: TObject);
procedure ButtonCloseClick(Sender: TObject);
procedure ButtonWebSiteClick(Sender: TObject);
procedure ButtonBuyClick(Sender: TObject);
procedure ButtonDownloadClick(Sender: TObject);
procedure ButtonInstallClick(Sender: TObject);
private
FLibUrl: string;
FLibProjectUrl: string;
FLibId: string;
FLibSize: string;
FPurchaseUrl: string;
FOnAction: TOnItemAction;
FIsInstalled: Boolean;
function FormatSize(const Value: string): string;
procedure SetOnAction(const Value: TOnItemAction);
procedure SetIsInstalled(const Value: Boolean);
public
procedure Fill(Item: TGetItPackage; Installed: Boolean);
property OnAction: TOnItemAction read FOnAction write SetOnAction;
procedure Close;
constructor Create(AOwner: TComponent); override;
property IsInstalled: Boolean read FIsInstalled write SetIsInstalled;
destructor Destroy; override;
end;
implementation
uses
HGM.FMX.Image, System.Math, FMX.Ani, HGI.GetItAPI;
{$R *.fmx}
{ TFramePackageItem }
procedure TFramePackageItemFull.ButtonWebSiteClick(Sender: TObject);
begin
if Assigned(FOnAction) then
FOnAction(Self, FLibProjectUrl, TItemAction.OpenUrl);
end;
procedure TFramePackageItemFull.Close;
begin
Release;
end;
procedure TFramePackageItemFull.ButtonBuyClick(Sender: TObject);
begin
if Assigned(FOnAction) then
FOnAction(Self, FPurchaseUrl, TItemAction.OpenUrl);
end;
procedure TFramePackageItemFull.ButtonCloseClick(Sender: TObject);
begin
Close;
end;
procedure TFramePackageItemFull.ButtonDownloadClick(Sender: TObject);
begin
if Assigned(FOnAction) then
FOnAction(Self, FLibUrl, TItemAction.OpenUrl);
end;
procedure TFramePackageItemFull.ButtonInstallClick(Sender: TObject);
begin
if Assigned(FOnAction) then
if FIsInstalled then
FOnAction(Self, FLibId, TItemAction.Uninstall)
else
FOnAction(Self, FLibId, TItemAction.Install);
end;
constructor TFramePackageItemFull.Create(AOwner: TComponent);
begin
inherited;
Name := '';
VertScrollBoxText.AniCalculations.Animation := True;
end;
destructor TFramePackageItemFull.Destroy;
begin
inherited;
end;
function TFramePackageItemFull.FormatSize(const Value: string): string;
begin
var F: Single;
if TryStrToFloat(Value.Replace(',', FormatSettings.DecimalSeparator).Replace('.', FormatSettings.DecimalSeparator), F) then
Result := ' ' + Max(1, Round(F)).ToString + 'MB'
else
Result := '';
end;
procedure TFramePackageItemFull.Fill(Item: TGetItPackage; Installed: Boolean);
begin
IsInstalled := Installed;
FLibUrl := Item.LibUrl;
FLibProjectUrl := Item.LibProjectUrl;
FLibId := Item.Id;
FLibSize := Item.LibSize;
FPurchaseUrl := Item.PurchaseUrl;
EditId.Text := Item.Id;
EditLibUrl.Text := Item.LibUrl;
LabelTitle.Text := Item.Name;
LabelDesc.Text := Item.Description;
LabelInfo.Text := Item.Version + #13#10 + 'by ' + Item.Vendor + #13#10 + Item.VendorUrl;
LabelLicense.Text := Item.LibLicenseName;
LayoutPfWin.Visible := False;
LayoutPfLin.Visible := False;
LayoutPfMac.Visible := False;
LayoutPfAndr.Visible := False;
LayoutPfIOS.Visible := False;
ButtonDownload.Visible := not Item.LibUrl.IsEmpty;
ButtonWebSite.Visible := not Item.LibProjectUrl.IsEmpty;
CircleGitHub.Visible := Item.LibProjectUrl.ToLower.Contains('github.com') or Item.LibProjectUrl.ToLower.Contains('gitlab.com');
ButtonBuy.Visible := not Item.PurchaseUrl.IsEmpty;
LabelTags.Text := Item.Tags;
if LabelTags.Text.IsEmpty then
LabelTags.Text := 'Empty';
LabelDate.Text := 'Updated ' + TGetIt.ParseDate(Item.Modified);
for var OS in Item.LibOSes do
begin
if OS.Id = '1' then
LayoutPfWin.Visible := True
else if OS.Id = '2' then
LayoutPfMac.Visible := True
else if OS.Id = '3' then
LayoutPfIOS.Visible := True
else if OS.Id = '4' then
LayoutPfAndr.Visible := True
else if OS.Id = '5' then
LayoutPfLin.Visible := True;
end;
RectangleImage.Fill.Bitmap.Bitmap.LoadFromUrlAsync(RectangleImage, Item.Image, False,
procedure(Success: Boolean)
begin
if Success then
begin
RectangleImage.Fill.Kind := TBrushKind.Bitmap;
RectangleImage.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
end;
end);
Opacity := 0;
TAnimator.AnimateFloat(Self, 'Opacity', 1);
FlowLayoutPlatformsResize(nil);
end;
procedure TFramePackageItemFull.FlowLayoutPlatformsResize(Sender: TObject);
begin
var H: Single := 0;
for var Control in FlowLayoutPlatforms.Controls do
H := Max(H, Control.Position.Y + Control.Height);
FlowLayoutPlatforms.Height := H;
end;
procedure TFramePackageItemFull.RectangleBGResize(Sender: TObject);
begin
if (Width < 600) or (Height < 600) then
begin
RectangleBG.Align := TAlignLayout.Client;
RectangleBG.Margins.Rect := TRectF.Create(0, 0, 0, 0);
RectangleBG.Corners := [];
end
else
begin
if RectangleBG.Align <> TAlignLayout.Fit then
begin
RectangleBG.Align := TAlignLayout.None;
RectangleBG.Margins.Rect := TRectF.Create(50, 50, 50, 50);
RectangleBG.Corners := AllCorners;
RectangleBG.Width := 513;
RectangleBG.Height := 634;
RectangleBG.Align := TAlignLayout.Fit;
end;
end;
end;
procedure TFramePackageItemFull.SetIsInstalled(const Value: Boolean);
begin
FIsInstalled := Value;
if not FIsInstalled then
ButtonInstall.Text := 'INSTALL' + FormatSize(FLibSize)
else
ButtonInstall.Text := 'UNINSTALL';
end;
procedure TFramePackageItemFull.SetOnAction(const Value: TOnItemAction);
begin
FOnAction := Value;
end;
end.