-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.Attachment.Audio.pas
247 lines (216 loc) · 6.74 KB
/
ChatFMX.Frame.Attachment.Audio.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
unit ChatFMX.Frame.Attachment.Audio;
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.Controls.Presentation, FMX.Objects, FMX.Layouts, VK.API,
VK.Entity.AudioMessage, VK.Entity.Audio, ChatFMX.DM.Res,
ChatFMX.Frame.Attachment;
type
TFrameAttachmentAudio = class(TFrameAttachment)
LayoutControl: TLayout;
CircleControl: TCircle;
PathControl: TPath;
LayoutTrackInfo: TLayout;
LabelArtist: TLabel;
LabelDef: TLabel;
LabelTitle: TLabel;
RectangleOver: TRectangle;
LayoutActions: TLayout;
ButtonPlayNext: TButton;
ButtonOptions: TButton;
LayoutTrackBar: TLayout;
RectangleTrackFill: TRectangle;
RectangleTrackPosition: TRectangle;
CirclePos: TCircle;
LabelTime: TLabel;
LayoutVolume: TLayout;
RectangleVolume: TRectangle;
RectangleVolumePos: TRectangle;
CircleVolumePos: TCircle;
procedure CircleControlClick(Sender: TObject);
procedure LabelArtistResize(Sender: TObject);
procedure LabelArtistMouseLeave(Sender: TObject);
procedure LabelArtistMouseEnter(Sender: TObject);
procedure FrameMouseEnter(Sender: TObject);
procedure FrameMouseLeave(Sender: TObject);
procedure RectangleTrackFillMouseEnter(Sender: TObject);
procedure RectangleTrackFillMouseLeave(Sender: TObject);
procedure LayoutVolumeMouseEnter(Sender: TObject);
procedure LayoutVolumeMouseLeave(Sender: TObject);
private
FIsPlay: Boolean;
FDuration: Int64;
FIsPause: Boolean;
FDurationPlayed: Int64;
FTitle: string;
FArtist: string;
FMouseFrame: Boolean;
FIsActive: Boolean;
procedure SetIsPlay(const Value: Boolean);
procedure SetDuration(const Value: Int64);
procedure SetIsPause(const Value: Boolean);
procedure SetDurationPlayed(const Value: Int64);
procedure UpdateTime;
procedure SetArtist(const Value: string);
procedure SetTitle(const Value: string);
procedure SetMouseFrame(const Value: Boolean);
procedure SetIsActive(const Value: Boolean);
procedure UpdateControls;
property MouseFrame: Boolean read FMouseFrame write SetMouseFrame;
public
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
procedure Fill(Audio: TVkAudio);
property IsPlay: Boolean read FIsPlay write SetIsPlay;
property IsPause: Boolean read FIsPause write SetIsPause;
property Duration: Int64 read FDuration write SetDuration;
property DurationPlayed: Int64 read FDurationPlayed write SetDurationPlayed;
property Artist: string read FArtist write SetArtist;
property Title: string read FTitle write SetTitle;
property IsActive: Boolean read FIsActive write SetIsActive;
end;
const
PlayPath = 'm 2.5 0.5 v 9 l 7 -4.5 Z';
PausePath = 'M224,435.8V76.1c0-6.7-5.4-12.1-12.2-12.1h-71.6c-6.8,0-12.2,5.4-12.2,12.1v359.7c0,6.7,5.4,12.2,12.2,12.2h71.6 C218.6,448,224,442.6,224,435.8z'#13#10 +
'M371.8,64h-71.6c-6.7,0-12.2,5.4-12.2,12.1v359.7c0,6.7,5.4,12.2,12.2,12.2h71.6c6.7,0,12.2-5.4,12.2-12.2V76.1 C384,69.4,378.6,64,371.8,64z';
implementation
uses
System.Math, HGM.Common.DateUtils;
{$R *.fmx}
procedure TFrameAttachmentAudio.CircleControlClick(Sender: TObject);
begin
IsPlay := not IsPlay;
end;
constructor TFrameAttachmentAudio.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited;
CirclePos.Visible := False;
CircleVolumePos.Visible := False;
MouseFrame := False;
IsActive := False;
end;
procedure TFrameAttachmentAudio.Fill(Audio: TVkAudio);
begin
Artist := Audio.Artist;
Title := Audio.Title;
Duration := Audio.Duration;
DurationPlayed := 0; //Duration div 2;
end;
procedure TFrameAttachmentAudio.FrameMouseEnter(Sender: TObject);
begin
MouseFrame := True;
end;
procedure TFrameAttachmentAudio.FrameMouseLeave(Sender: TObject);
begin
MouseFrame := False;
end;
procedure TFrameAttachmentAudio.LabelArtistMouseEnter(Sender: TObject);
var
Item: TLabel absolute Sender;
begin
Item.TextSettings.Font.Style := Item.TextSettings.Font.Style + [TFontStyle.fsUnderline];
FrameMouseEnter(nil);
end;
procedure TFrameAttachmentAudio.LabelArtistMouseLeave(Sender: TObject);
var
Item: TLabel absolute Sender;
begin
Item.TextSettings.Font.Style := Item.TextSettings.Font.Style - [TFontStyle.fsUnderline];
FrameMouseLeave(nil);
end;
procedure TFrameAttachmentAudio.LabelArtistResize(Sender: TObject);
begin
if LabelArtist.Width > 130 then
begin
LabelArtist.AutoSize := False;
LabelArtist.Width := 130;
end
else
LabelArtist.AutoSize := True;
end;
procedure TFrameAttachmentAudio.LayoutVolumeMouseEnter(Sender: TObject);
begin
CircleVolumePos.Visible := True;
FrameMouseEnter(nil);
end;
procedure TFrameAttachmentAudio.LayoutVolumeMouseLeave(Sender: TObject);
begin
CircleVolumePos.Visible := False;
FrameMouseLeave(nil);
end;
procedure TFrameAttachmentAudio.RectangleTrackFillMouseEnter(Sender: TObject);
begin
CirclePos.Visible := True;
FrameMouseEnter(nil);
end;
procedure TFrameAttachmentAudio.RectangleTrackFillMouseLeave(Sender: TObject);
begin
CirclePos.Visible := False;
FrameMouseLeave(nil);
end;
procedure TFrameAttachmentAudio.SetIsActive(const Value: Boolean);
begin
FIsActive := Value;
UpdateControls;
end;
procedure TFrameAttachmentAudio.SetIsPause(const Value: Boolean);
begin
FIsPause := Value;
end;
procedure TFrameAttachmentAudio.SetIsPlay(const Value: Boolean);
begin
FIsPlay := Value;
if FIsPlay then
begin
PathControl.Data.Data := PausePath;
IsActive := True;
end
else
begin
PathControl.Data.Data := PlayPath;
IsActive := False;
end;
end;
procedure TFrameAttachmentAudio.UpdateControls;
begin
LayoutTrackBar.Visible := FIsActive;
LayoutVolume.Visible := FIsActive;
ButtonPlayNext.Visible := FMouseFrame and (not FIsActive);
RectangleOver.Visible := FMouseFrame or FIsActive;
ButtonOptions.Visible := FMouseFrame;
LabelTime.Visible := not FMouseFrame;
UpdateTime;
end;
procedure TFrameAttachmentAudio.SetMouseFrame(const Value: Boolean);
begin
FMouseFrame := Value;
UpdateControls;
end;
procedure TFrameAttachmentAudio.SetArtist(const Value: string);
begin
FArtist := Value;
LabelArtist.Text := FArtist;
end;
procedure TFrameAttachmentAudio.SetTitle(const Value: string);
begin
FTitle := Value;
LabelTitle.Text := FTitle;
end;
procedure TFrameAttachmentAudio.SetDuration(const Value: Int64);
begin
FDuration := Value;
UpdateTime;
end;
procedure TFrameAttachmentAudio.SetDurationPlayed(const Value: Int64);
begin
FDurationPlayed := Value;
UpdateTime;
end;
procedure TFrameAttachmentAudio.UpdateTime;
begin
if not FIsActive then
LabelTime.Text := SecondsToMinFormat(FDuration)
else
LabelTime.Text := SecondsToMinFormat(FDurationPlayed - FDuration);
end;
end.