-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.Attachment.AudioPlaylist.pas
156 lines (138 loc) · 4.36 KB
/
ChatFMX.Frame.Attachment.AudioPlaylist.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
unit ChatFMX.Frame.Attachment.AudioPlaylist;
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,
System.Messaging, ChatFMX.Frame.Attachment, FMX.Effects, FMX.Ani,
VK.Entity.Common.ExtendedList, VK.Entity.Message, VK.Entity.Playlist;
type
TFrameAttachmentAudioPlaylist = class(TFrameAttachment)
LayoutText: TLayout;
LabelTitle: TLabel;
Rectangle1: TRectangle;
RectangleImage: TRectangle;
RectangleFrame: TRectangle;
RectangleBG: TRectangle;
Rectangle2: TRectangle;
Layout1: TLayout;
LabelArtist: TLabel;
Layout2: TLayout;
LabelGenre: TLabel;
LabelYear: TLabel;
VertScrollBoxPlaylist: TVertScrollBox;
CircleControl: TCircle;
PathControl: TPath;
private
FGenres: string;
FArtist: string;
FTitle: string;
FYear: Integer;
FImageUrl: string;
FImageFile: string;
procedure SetGenres(const Value: string);
procedure SetArtist(const Value: string);
procedure SetTitle(const Value: string);
procedure SetYear(const Value: Integer);
procedure FOnReadyImage(const Sender: TObject; const M: TMessage);
public
procedure SetVisibility(const Value: Boolean); override;
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
destructor Destroy; override;
procedure Fill(Item: TVkAudioPlaylist; Data: TVkEntityExtendedList<TVkMessage>); overload;
property Genres: string read FGenres write SetGenres;
property Artist: string read FArtist write SetArtist;
property Title: string read FTitle write SetTitle;
property Year: Integer read FYear write SetYear;
end;
implementation
uses
VK.Entity.Common, HGM.FMX.Image, VK.Types, VK.Entity.Profile, VK.Entity.Group,
ChatFMX.PreviewManager;
{$R *.fmx}
{ TFrameAttachmentAudioPlaylist }
constructor TFrameAttachmentAudioPlaylist.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited;
RectangleFrame.Visible := True;
Rectangle1.Visible := False;
end;
destructor TFrameAttachmentAudioPlaylist.Destroy;
begin
TPreview.Instance.Unsubscribe(FOnReadyImage);
inherited;
end;
procedure TFrameAttachmentAudioPlaylist.Fill(Item: TVkAudioPlaylist; Data: TVkEntityExtendedList<TVkMessage>);
begin
Genres := Item.Genres.ToStringNames;
var TmpArtist := '';
for var ArtistItem in Item.MainArtists do
TmpArtist := TmpArtist + ArtistItem.Name + ', ';
Artist := TmpArtist.Trim([',', ' ']);
Title := Item.Title;
Year := Item.Year;
if Assigned(Item.Photo) then
FImageUrl := Item.Photo.Photo68;
end;
procedure TFrameAttachmentAudioPlaylist.SetArtist(const Value: string);
begin
FArtist := Value;
LabelArtist.AutoSize := False;
LabelArtist.Text := FArtist;
LabelArtist.AutoSize := True;
if LabelArtist.Width > 150 then
begin
LabelArtist.AutoSize := False;
LabelArtist.Width := 150;
end;
end;
procedure TFrameAttachmentAudioPlaylist.SetGenres(const Value: string);
begin
FGenres := Value;
LabelGenre.AutoSize := False;
LabelGenre.Text := FGenres;
LabelGenre.AutoSize := True;
if LabelGenre.Width > 150 then
begin
LabelGenre.AutoSize := False;
LabelGenre.Width := 150;
end;
end;
procedure TFrameAttachmentAudioPlaylist.SetTitle(const Value: string);
begin
FTitle := Value;
LabelTitle.Text := FTitle;
end;
procedure TFrameAttachmentAudioPlaylist.SetVisibility(const Value: Boolean);
begin
inherited;
if Value then
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage)
else
RectangleImage.Fill.Bitmap.Bitmap := nil;
end;
procedure TFrameAttachmentAudioPlaylist.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
RectangleImage.Fill.Bitmap.Bitmap := nil
else
try
RectangleImage.Fill.Bitmap.Bitmap.LoadFromFile(FImageFile);
RectangleImage.Fill.Kind := TBrushKind.Bitmap;
RectangleImage.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
except
RectangleImage.Fill.Bitmap.Bitmap := nil;
end;
end;
procedure TFrameAttachmentAudioPlaylist.SetYear(const Value: Integer);
begin
FYear := Value;
LabelYear.Text := ' · ' + FYear.ToString;
end;
end.