-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.Attachment.Link.pas
151 lines (134 loc) · 4.12 KB
/
ChatFMX.Frame.Attachment.Link.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
unit ChatFMX.Frame.Attachment.Link;
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.Controls.Presentation, ChatFMX.DM.Res, FMX.Layouts, VK.API,
VK.Entity.Link, System.Messaging, ChatFMX.Frame.Attachment, FMX.Effects,
FMX.Ani;
type
TFrameAttachmentLink = class(TFrameAttachment)
RectangleFrame: TRectangle;
RectangleText: TRectangle;
LayoutActions: TLayout;
LabelTitle: TLabel;
LabelUrl: TLabel;
LayoutPreview: TLayout;
LayoutShort: TLayout;
LayoutText: TLayout;
LabelShortTitle: TLabel;
LabelShortUrl: TLabel;
LineLeft: TLine;
RectangleImage: TRectangle;
Rectangle1: TRectangle;
Rectangle2: TRectangle;
PathStar: TPath;
ShadowEffectStar: TShadowEffect;
FloatAnimationStarShadow: TFloatAnimation;
LayoutFavorite: TLayout;
procedure FrameMouseEnter(Sender: TObject);
procedure FrameMouseLeave(Sender: TObject);
private
FImageUrl: string;
FImageFile: string;
FUrl: string;
FIsFavorite: Boolean;
procedure FOnReadyImage(const Sender: TObject; const M: TMessage);
procedure SetIsFavorite(const Value: Boolean);
public
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
destructor Destroy; override;
procedure Fill(Item: TVkLink);
property IsFavorite: Boolean read FIsFavorite write SetIsFavorite;
end;
implementation
uses
ChatFMX.PreviewManager, Vk.Entity.Common;
{$R *.fmx}
{ TFrameAttachmentLink }
constructor TFrameAttachmentLink.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited;
Rectangle1.Visible := False;
end;
destructor TFrameAttachmentLink.Destroy;
begin
TPreview.Instance.Unsubscribe(FOnReadyImage);
inherited;
end;
procedure TFrameAttachmentLink.Fill(Item: TVkLink);
begin
FUrl := Item.Url;
IsFavorite := Item.IsFavorite;
if not Assigned(Item.Photo) then
begin
Height := 40;
LayoutPreview.Visible := False;
LayoutShort.Visible := True;
LabelShortTitle.Text := Item.Title;
if not Item.Caption.IsEmpty then
LabelShortUrl.Text := Item.Caption
else
LabelShortUrl.Text := Item.Url;
end
else
begin
Height := 270;
LayoutPreview.Visible := True;
LayoutShort.Visible := False;
LabelTitle.Text := Item.Title;
if not Item.Caption.IsEmpty then
LabelUrl.Text := Item.Caption
else
LabelUrl.Text := Item.Url;
FImageUrl := Item.Photo.Sizes.GetSizeUrlOrEmpty(300);
if not FImageUrl.IsEmpty then
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage);
end;
end;
procedure TFrameAttachmentLink.FOnReadyImage(const Sender: TObject; const M: TMessage);
var
Data: TMessagePreview absolute M;
begin
if Data.Value.Url <> FImageUrl then
Exit;
TPreview.Instance.Unsubscribe(FOnReadyImage);
FImageFile := Data.Value.FileName;
if not FImageFile.IsEmpty then
try
RectangleImage.Fill.Bitmap.Bitmap.LoadFromFile(FImageFile);
RectangleImage.Fill.Kind := TBrushKind.Bitmap;
RectangleImage.Fill.Bitmap.WrapMode := TWrapMode.Tile;
except
RectangleImage.Fill.Kind := TBrushKind.None;
end
else
RectangleImage.Fill.Kind := TBrushKind.None;
end;
procedure TFrameAttachmentLink.FrameMouseEnter(Sender: TObject);
begin
LabelTitle.Font.Style := LabelTitle.Font.Style + [TFontStyle.fsUnderline];
LabelShortTitle.Font.Style := LabelShortTitle.Font.Style + [TFontStyle.fsUnderline];
end;
procedure TFrameAttachmentLink.FrameMouseLeave(Sender: TObject);
begin
LabelTitle.Font.Style := LabelTitle.Font.Style - [TFontStyle.fsUnderline];
LabelShortTitle.Font.Style := LabelShortTitle.Font.Style - [TFontStyle.fsUnderline];
end;
procedure TFrameAttachmentLink.SetIsFavorite(const Value: Boolean);
begin
FIsFavorite := Value;
if FIsFavorite then
begin
PathStar.Fill.Kind := TBrushKind.Solid;
PathStar.Fill.Color := TAlphaColorRec.White;
PathStar.Stroke.Kind := TBrushKind.None;
end
else
begin
PathStar.Fill.Kind := TBrushKind.None;
PathStar.Stroke.Kind := TBrushKind.Solid;
PathStar.Stroke.Color := TAlphaColorRec.White;
end;
end;
end.