-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathChatFMX.Frame.Attachment.Gift.pas
158 lines (140 loc) · 4.34 KB
/
ChatFMX.Frame.Attachment.Gift.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
unit ChatFMX.Frame.Attachment.Gift;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
VK.API, FMX.Objects, VK.Types, System.Messaging, VK.Entity.Video, FMX.Layouts,
FMX.Controls.Presentation, VK.Entity.Gift, VK.Entity.Message,
ChatFMX.Frame.Attachment;
type
TFrameAttachmentGift = class(TFrameAttachment)
LayoutCaption: TLayout;
PathGift: TPath;
LabelGift: TLabel;
LabelText: TLabel;
FlowLayoutButtons: TFlowLayout;
RectangleMy: TRectangle;
LabelMy: TLabel;
RectangleMore: TRectangle;
LabelMore: TLabel;
RectangleSend: TRectangle;
LabelSend: TLabel;
LayoutGift: TLayout;
Rectangle1: TRectangle;
RectangleGift: TRectangle;
procedure LabelTextResize(Sender: TObject);
procedure FrameResize(Sender: TObject);
private
FImageUrl: string;
FImageFile: string;
FStickersProductId: Integer;
FIsMini: Boolean;
procedure FOnReadyImage(const Sender: TObject; const M: TMessage);
procedure SetStickersProductId(const Value: Integer);
procedure SetIsMini(const Value: Boolean);
public
procedure SetVisibility(const Value: Boolean); override;
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
destructor Destroy; override;
procedure Fill(Gift: TVkGift; Msg: TVkMessage; CanAnswer: Boolean);
property StickersProductId: Integer read FStickersProductId write SetStickersProductId;
property IsMini: Boolean read FIsMini write SetIsMini;
end;
implementation
uses
ChatFMX.PreviewManager, HGm.Common.DateUtils, System.Threading,
VK.Entity.Common, VK.Video;
{$R *.fmx}
{ TFrameAttachmentPhoto }
procedure TFrameAttachmentGift.SetVisibility(const Value: Boolean);
begin
inherited;
if Value then
begin
if not FImageUrl.IsEmpty then
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage);
end
else
begin
RectangleGift.Fill.Bitmap.Bitmap := nil;
end;
end;
constructor TFrameAttachmentGift.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited;
IsMini := False;
end;
destructor TFrameAttachmentGift.Destroy;
begin
TPreview.Instance.Unsubscribe(FOnReadyImage);
inherited;
end;
procedure TFrameAttachmentGift.Fill(Gift: TVkGift; Msg: TVkMessage; CanAnswer: Boolean);
begin
LabelText.Text := Msg.Text;
LabelText.Visible := not LabelText.Text.IsEmpty;
FImageUrl := Gift.Thumb256;
StickersProductId := Gift.StickersProductId;
RectangleMy.Visible := Msg.FromId <> VK.UserId;
RectangleMore.Visible := CanAnswer and (Msg.FromId = VK.UserId);
RectangleSend.Visible := CanAnswer and (Msg.FromId <> VK.UserId);
end;
procedure TFrameAttachmentGift.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 FImageFile.IsEmpty then
begin
RectangleGift.Fill.Kind := TBrushKind.Solid;
end
else
try
RectangleGift.Fill.Bitmap.Bitmap.LoadFromFile(FImageFile);
RectangleGift.Fill.Kind := TBrushKind.Bitmap;
RectangleGift.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
except
RectangleGift.Fill.Kind := TBrushKind.Solid;
end;
end;
procedure TFrameAttachmentGift.FrameResize(Sender: TObject);
begin
var Sz: Single := 0;
for var Control in Controls do
if Control.IsVisible then
Sz := Sz + Control.Height + Control.Margins.Top + Control.Margins.Bottom;
Height := Sz + 20;
end;
procedure TFrameAttachmentGift.LabelTextResize(Sender: TObject);
begin
FrameResize(nil);
end;
procedure TFrameAttachmentGift.SetIsMini(const Value: Boolean);
begin
FIsMini := Value;
LayoutCaption.Visible := not FIsMini;
case FIsMini of
True:
begin
RectangleGift.Align := TAlignLayout.Left;
Height := 360;
FlowLayoutButtons.Justify := TFlowJustify.Left;
FlowLayoutButtons.JustifyLastLine := TFlowJustify.Left;
end;
False:
begin
RectangleGift.Align := TAlignLayout.Center;
Height := 410;
FlowLayoutButtons.Justify := TFlowJustify.Center;
FlowLayoutButtons.JustifyLastLine := TFlowJustify.Center;
end;
end;
end;
procedure TFrameAttachmentGift.SetStickersProductId(const Value: Integer);
begin
FStickersProductId := Value;
end;
end.