-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.Attachment.PinnedMessage.pas
129 lines (113 loc) · 3.57 KB
/
ChatFMX.Frame.Attachment.PinnedMessage.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
unit ChatFMX.Frame.Attachment.PinnedMessage;
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, VK.API, VK.Entity.Message,
VK.Entity.Conversation, System.Messaging, ChatFMX.Frame.Attachment,
VK.Entity.Common.ExtendedList;
type
TFrameAttachmentPinnedMessage = class(TFrameAttachment)
LayoutContent: TLayout;
LayoutText: TLayout;
LabelText: TLabel;
LayoutFrom: TLayout;
LabelFrom: TLabel;
LabelTime: TLabel;
procedure LabelFromMouseEnter(Sender: TObject);
procedure LabelFromMouseLeave(Sender: TObject);
private
FText: string;
FIsAttachmentText: Boolean;
FFrom: string;
FDate: TDateTime;
FMessageId: Int64;
procedure SetText(const Value: string);
procedure SetIsAttachmentText(const Value: Boolean);
procedure SetFrom(const Value: string);
procedure SetDate(const Value: TDateTime);
procedure SetMessageId(const Value: Int64);
public
procedure Fill(Item: TVkMessage; Data: IExtended);
property Text: string read FText write SetText;
property From: string read FFrom write SetFrom;
property Date: TDateTime read FDate write SetDate;
property IsAttachmentText: Boolean read FIsAttachmentText write SetIsAttachmentText;
property MessageId: Int64 read FMessageId write SetMessageId;
end;
implementation
uses
VK.Types, VK.Entity.Profile, VK.Entity.Group, VK.Entity.Common,
ChatFMX.PreviewManager, ChatFMX.Utils;
{$R *.fmx}
procedure TFrameAttachmentPinnedMessage.Fill(Item: TVkMessage; Data: IExtended);
begin
FMessageId := Item.Id;
Date := Item.Date;
Text := ParseMention(PrepareForPreview(Item.Text));
From := '';
IsAttachmentText := False;
if PeerIdIsUser(Item.FromId) then
begin
var User: TVkProfile;
if Data.GetProfileById(Item.FromId, User) then
From := User.FullName;
end
else
begin
var Group: TVkGroup;
if Data.GetGroupById(Item.FromId, Group) then
From := Group.Name;
end;
if Text.IsEmpty and (Length(Item.Attachments) > 0) then
begin
var Attachment := Item.Attachments[0];
Text := AttachmentToText(Attachment.&Type);
IsAttachmentText := True;
end;
if Text.IsEmpty and Assigned(Item.Geo) then
begin
Text := 'Карта';
IsAttachmentText := True;
end;
end;
procedure TFrameAttachmentPinnedMessage.LabelFromMouseEnter(Sender: TObject);
var
Control: TLabel absolute Sender;
begin
Control.TextSettings.Font.Style := Control.TextSettings.Font.Style + [TFontStyle.fsUnderline];
end;
procedure TFrameAttachmentPinnedMessage.LabelFromMouseLeave(Sender: TObject);
var
Control: TLabel absolute Sender;
begin
Control.TextSettings.Font.Style := Control.TextSettings.Font.Style - [TFontStyle.fsUnderline];
end;
procedure TFrameAttachmentPinnedMessage.SetDate(const Value: TDateTime);
begin
FDate := Value;
LabelTime.Text := HumanDateTime(FDate, True, True);
end;
procedure TFrameAttachmentPinnedMessage.SetFrom(const Value: string);
begin
FFrom := Value;
LabelFrom.Text := FFrom;
end;
procedure TFrameAttachmentPinnedMessage.SetIsAttachmentText(const Value: Boolean);
begin
FIsAttachmentText := Value;
if FIsAttachmentText then
LabelText.FontColor := $FF71AAEB
else
LabelText.FontColor := $FFE1E3E6;
end;
procedure TFrameAttachmentPinnedMessage.SetMessageId(const Value: Int64);
begin
FMessageId := Value;
end;
procedure TFrameAttachmentPinnedMessage.SetText(const Value: string);
begin
FText := Value;
LabelText.Text := FText;
end;
end.