unit ShareFileAction;
interface
uses System.Classes, System.Actions, System.Messaging, FMX.Types, FMX.MediaLibrary, FMX.ActnList, FMX.StdActns, FMX.Consts,
FMX.Graphics, FMX.Controls;
type
{ TShowShareSheetAction }
TShowShareSheetAction =
class(TSysCommonAction)
strict private
FSharingService: IFMXShareSheetActionsService;
FBitmap: TBitmap;
FMessage:
string;
FOnBeforeExecute: TNotifyEvent;
private
procedure SetBitmap(
const Value: TBitmap);
protected
procedure DoBeforeExecute;
procedure CustomTextChanged;
override;
function IsSupportedInterface: Boolean;
override;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
function HandlesTarget(Target: TObject): Boolean;
override;
procedure ExecuteTarget(Target: TObject);
override;
published
property Bitmap: TBitmap
read FBitmap
write SetBitmap;
property TextMessage:
string read FMessage
write FMessage;
property OnBeforeExecute: TNotifyEvent
read FOnBeforeExecute
write FOnBeforeExecute;
end;
implementation
uses
System.SysUtils, FMX.
Platform, System.Types;
constructor TShowShareSheetAction.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMessage := '
';
FBitmap := TBitmap.Create(0, 0);
TPlatformServices.Current.SupportsPlatformService(IFMXShareSheetActionsService, FSharingService);
end;
procedure TShowShareSheetAction.CustomTextChanged;
begin
Text := GetDefaultText(SOpenStandartServices);
end;
destructor TShowShareSheetAction.Destroy;
begin
FSharingService :=
nil;
FreeAndNil(FBitmap);
inherited Destroy;
end;
procedure TShowShareSheetAction.DoBeforeExecute;
begin
if Assigned(FOnBeforeExecute)
then
FOnBeforeExecute(Self);
end;
procedure TShowShareSheetAction.ExecuteTarget(Target: TObject);
var
TargetControl: TControl;
begin
DoBeforeExecute;
inherited ExecuteTarget(Target);
if Target
is TControl
then
TargetControl := TControl(Target)
else if ActionComponent
is TControl
then
TargetControl := TControl(ActionComponent)
else
TargetControl :=
nil;
if (Bitmap <>
nil)
and (FSharingService <>
nil)
then
FSharingService.Share(TargetControl, TextMessage, Bitmap);
//<<<-------------- ICH WILL WISSEN WAS DA PASSIERT
end;
function TShowShareSheetAction.HandlesTarget(Target: TObject): Boolean;
begin
Result := Supported;
end;
function TShowShareSheetAction.IsSupportedInterface: Boolean;
begin
Result := FSharingService <>
nil;
end;
procedure TShowShareSheetAction.SetBitmap(
const Value: TBitmap);
begin
FBitmap.Assign(Value);
end;
end.