-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHGI.View.Item.pas
228 lines (202 loc) · 6.38 KB
/
HGI.View.Item.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
unit HGI.View.Item;
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.Effects, FMX.Menus;
{$SCOPEDENUMS ON}
type
TItemAction = (Install, Download, Uninstall, OpenUrl, CommandLine);
TOnItemAction = procedure(Sender: TObject; const ItemId: string; Action: TItemAction) of object;
TFramePackageItem = class(TFrame)
RectangleBG: TRectangle;
Layout1: TLayout;
Layout2: TLayout;
Layout3: TLayout;
RectangleImage: TRectangle;
ButtonInstall: TButton;
LabelTitle: TLabel;
LabelDesc: TLabel;
LabelInfo: TLabel;
LayoutOS: TLayout;
PathWindows: TPath;
PathIOS: TPath;
PathAndroid: TPath;
PathLinux: TPath;
PathMacOS: TPath;
LabelLicense: TLabel;
ButtonInstallOpt: TButton;
ImagePers: TImage;
Line1: TLine;
PopupMenuOpt: TPopupMenu;
MenuItemDownload: TMenuItem;
MenuItemWebSite: TMenuItem;
MenuItemShowCommand: TMenuItem;
PathGutHub: TPath;
procedure RectangleBGClick(Sender: TObject);
procedure ButtonInstallClick(Sender: TObject);
procedure ButtonInstallOptClick(Sender: TObject);
procedure MenuItemDownloadClick(Sender: TObject);
procedure MenuItemWebSiteClick(Sender: TObject);
procedure MenuItemShowCommandClick(Sender: TObject);
private
FItem: TGetItPackage;
FOnAction: TOnItemAction;
FIsInstalled: Boolean;
function FormatSize(const Value: string): string;
procedure SetOnAction(const Value: TOnItemAction);
function GetId: string;
procedure SetIsInstalled(const Value: Boolean);
public
procedure Fill(Item: TGetItPackage; Installed: Boolean);
property OnAction: TOnItemAction read FOnAction write SetOnAction;
constructor Create(AOwner: TComponent); override;
property Id: string read GetId;
property IsInstalled: Boolean read FIsInstalled write SetIsInstalled;
property Item: TGetItPackage read FItem;
destructor Destroy; override;
end;
implementation
uses
HGM.FMX.Image, System.Math, HGI.View.ItemFull, HGI.GetItAPI;
{$R *.fmx}
{ TFramePackageItem }
procedure TFramePackageItem.ButtonInstallClick(Sender: TObject);
begin
if Assigned(FOnAction) then
if FIsInstalled then
FOnAction(Self, FItem.Id, TItemAction.Uninstall)
else
FOnAction(Self, FItem.Id, TItemAction.Install);
end;
procedure TFramePackageItem.ButtonInstallOptClick(Sender: TObject);
begin
var Pt := Application.MainForm.ClientToScreen(ButtonInstall.AbsoluteRect.TopLeft);
PopupMenuOpt.Popup(Pt.X, Pt.Y + ButtonInstall.Height);
end;
constructor TFramePackageItem.Create(AOwner: TComponent);
begin
inherited;
Name := '';
FItem := nil;
end;
destructor TFramePackageItem.Destroy;
begin
if Assigned(FItem) then
FItem.Free;
inherited;
end;
function TFramePackageItem.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;
function TFramePackageItem.GetId: string;
begin
if Assigned(FItem) then
Result := Fitem.Id
else
Result := '';
end;
procedure TFramePackageItem.MenuItemDownloadClick(Sender: TObject);
begin
if Assigned(FItem) and Assigned(FOnAction) then
FOnAction(Self, FItem.Id, TItemAction.Download);
end;
procedure TFramePackageItem.MenuItemShowCommandClick(Sender: TObject);
begin
if Assigned(FItem) and Assigned(FOnAction) then
FOnAction(Self, FItem.Id, TItemAction.CommandLine);
end;
procedure TFramePackageItem.MenuItemWebSiteClick(Sender: TObject);
begin
if Assigned(FItem) and Assigned(FOnAction) then
FOnAction(Self, FItem.LibProjectUrl, TItemAction.OpenUrl);
end;
procedure TFramePackageItem.Fill(Item: TGetItPackage; Installed: Boolean);
begin
if Assigned(FItem) then
FItem.Free;
FItem := Item;
LabelTitle.Text := Item.Name;
LabelDesc.Text := Item.Description;
LabelInfo.Text := Item.Version + ' (' + TGetIt.ParseDate(Item.Modified) + ')' + #13#10 + 'by ' + Item.Vendor;
LabelLicense.Text := Item.LibLicenseName;
ButtonInstall.TagString := Item.LibUrl;
IsInstalled := Installed;
ButtonInstall.StylesData['bg.Padding.Right'] := ButtonInstallOpt.Width + 5;
MenuItemDownload.Enabled := not Item.LibUrl.IsEmpty;
MenuItemWebSite.Enabled := not Item.LibProjectUrl.IsEmpty;
PathGutHub.Visible := Item.LibProjectUrl.ToLower.Contains('github.com') or Item.LibProjectUrl.ToLower.Contains('gitlab.com');
//1 delphi
//5 all
//2 cpp
//6 ?
if (Item.LibCode = '1') then
begin
ImagePers.Bitmap.LoadFromResource('delphi');
ImagePers.Hint := 'Delphi only';
end
else if Item.LibCode = '2' then
begin
ImagePers.Bitmap.LoadFromResource('cpp');
ImagePers.Hint := 'C++ only';
end
else
begin
ImagePers.Bitmap.LoadFromResource('rad');
ImagePers.Hint := 'For RAD Studio';
end;
PathWindows.Visible := False;
PathLinux.Visible := False;
PathMacOS.Visible := False;
PathAndroid.Visible := False;
PathIOS.Visible := False;
for var OS in Item.LibOSes do
begin
if OS.Id = '1' then
PathWindows.Visible := True
else if OS.Id = '2' then
PathMacOs.Visible := True
else if OS.Id = '3' then
PathIOS.Visible := True
else if OS.Id = '4' then
PathAndroid.Visible := True
else if OS.Id = '5' then
PathLinux.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);
end;
procedure TFramePackageItem.RectangleBGClick(Sender: TObject);
begin
var Frame := TFramePackageItemFull.Create(Self);
Frame.Parent := Application.MainForm;
Frame.Fill(FItem, FIsInstalled);
Frame.RecalcSize;
Frame.OnAction := OnAction;
end;
procedure TFramePackageItem.SetIsInstalled(const Value: Boolean);
begin
FIsInstalled := Value;
if not FIsInstalled then
ButtonInstall.Text := 'INSTALL' + FormatSize(FItem.LibSize)
else
ButtonInstall.Text := 'UNINSTALL';
end;
procedure TFramePackageItem.SetOnAction(const Value: TOnItemAction);
begin
FOnAction := Value;
end;
end.