Changeset 3


Ignore:
Timestamp:
Aug 24, 2019, 10:44:11 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Odorik API moved to separate unit UOdorikApi.pas.
Location:
trunk
Files:
2 added
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      Android
      Win32
      __recovery
      __history
  • trunk/OdorikApi.dpr

    r2 r3  
    66  UFormMain in 'UFormMain.pas' {FormMain},
    77  UFormSettings in 'UFormSettings.pas' {FormSettings},
    8   UFormCalls in 'UFormCalls.pas' {FormCalls};
     8  UFormCalls in 'UFormCalls.pas' {FormCalls},
     9  UOdorikApi in 'UOdorikApi.pas';
    910
    1011{$R *.res}
  • trunk/OdorikApi.dproj

    r2 r3  
    77        <Base>True</Base>
    88        <Config Condition="'$(Config)'==''">Debug</Config>
    9         <Platform Condition="'$(Platform)'==''">Android</Platform>
     9        <Platform Condition="'$(Platform)'==''">Win32</Platform>
    1010        <TargetedPlatforms>19</TargetedPlatforms>
    1111        <AppType>Application</AppType>
     
    169169            <FormType>fmx</FormType>
    170170        </DCCReference>
     171        <DCCReference Include="UOdorikApi.pas"/>
    171172        <BuildConfiguration Include="Release">
    172173            <Key>Cfg_2</Key>
     
    197198                    </Platform>
    198199                </DeployFile>
     200                <DeployFile LocalName="libeay32.dll" Configuration="Debug" Class="File">
     201                    <Platform Name="Win32">
     202                        <RemoteName>libeay32.dll</RemoteName>
     203                        <Overwrite>true</Overwrite>
     204                    </Platform>
     205                </DeployFile>
    199206                <DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_LauncherIcon_72x72.png" Configuration="Debug" Class="Android_LauncherIcon72">
    200207                    <Platform Name="Android">
     
    333340                    <Platform Name="Android">
    334341                        <RemoteName>ic_launcher.png</RemoteName>
     342                        <Overwrite>true</Overwrite>
     343                    </Platform>
     344                </DeployFile>
     345                <DeployFile LocalName="ssleay32.dll" Configuration="Debug" Class="File">
     346                    <Platform Name="Win32">
     347                        <RemoteName>ssleay32.dll</RemoteName>
    335348                        <Overwrite>true</Overwrite>
    336349                    </Platform>
  • trunk/UFormCalls.fmx

    r2 r3  
    2828      Size.Height = 48.000000000000000000
    2929      Size.PlatformDefault = False
    30       Text = 'Settings'
     30      Text = 'Calls'
    3131      TabOrder = 1
    3232    end
     
    6060      TabOrder = 0
    6161      Text = 'History'
     62      ExplicitSize.cx = 98.000000000000000000
     63      ExplicitSize.cy = 49.000000000000000000
    6264      object ListView1: TListView
    6365        ItemAppearanceClassName = 'TListItemAppearance'
     
    8789      TabOrder = 0
    8890      Text = 'Active'
     91      ExplicitSize.cx = 98.000000000000000000
     92      ExplicitSize.cy = 49.000000000000000000
    8993    end
    9094    object TabItemStatistics: TTabItem
     
    99103      TabOrder = 0
    100104      Text = 'Statistics'
     105      ExplicitSize.cx = 100.000000000000000000
     106      ExplicitSize.cy = 49.000000000000000000
    101107    end
    102108  end
  • trunk/UFormCalls.pas

    r2 r3  
    8282  IntervalTo := Now;
    8383  IntervalFrom := IntervalTo - OneHour * 24;
    84   Response := FormMain.SendGet('/calls.json', 'from=' + DateTimeToXMLTime(IntervalFrom) +
     84  Response := FormMain.OdorikApi.SendGet('/calls.json', 'from=' + DateTimeToXMLTime(IntervalFrom) +
    8585    '&to=' + DateTimeToXMLTime(IntervalTo));
    8686  LJsonResponse := TJSONObject.ParseJSONValue(Response);
  • trunk/UFormMain.fmx

    r2 r3  
    5757    end
    5858  end
     59  object Timer1: TTimer
     60    OnTimer = Timer1Timer
     61    Left = 328
     62    Top = 344
     63  end
    5964  object MultiView1: TMultiView
    6065    MasterButton = SpeedButtonMenu
     
    6469    Size.Height = 473.000000000000000000
    6570    Size.PlatformDefault = False
     71    Visible = False
    6672    TabOrder = 0
    6773    object Rectangle1: TRectangle
     
    124130    end
    125131  end
    126   object IdHTTP1: TIdHTTP
    127     IOHandler = IdSSLIOHandlerSocketOpenSSL1
    128     AllowCookies = True
    129     ProxyParams.BasicAuthentication = False
    130     ProxyParams.ProxyPort = 0
    131     Request.ContentLength = -1
    132     Request.ContentRangeEnd = -1
    133     Request.ContentRangeStart = -1
    134     Request.ContentRangeInstanceLength = -1
    135     Request.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
    136     Request.BasicAuthentication = False
    137     Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    138     Request.Ranges.Units = 'bytes'
    139     Request.Ranges = <>
    140     HTTPOptions = [hoForceEncodeParams]
    141     Left = 192
    142     Top = 336
    143   end
    144   object Timer1: TTimer
    145     OnTimer = Timer1Timer
    146     Left = 328
    147     Top = 344
    148   end
    149   object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL
    150     MaxLineAction = maException
    151     Port = 0
    152     DefaultPort = 0
    153     SSLOptions.Mode = sslmUnassigned
    154     SSLOptions.VerifyMode = []
    155     SSLOptions.VerifyDepth = 0
    156     Left = 192
    157     Top = 280
    158   end
    159132end
  • trunk/UFormMain.pas

    r2 r3  
    77  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
    88  FMX.Layouts, FMX.Objects, FMX.Controls.Presentation, FMX.MultiView, IniFiles,
    9   System.IOUtils, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
    10   IdHTTP{$IFDEF ANDROID},IdSSLOpenSSLHeaders{$endif}, IdIOHandler, IdIOHandlerSocket,
    11   IdIOHandlerStack, IdSSL, IdSSLOpenSSL;
     9  System.IOUtils, UOdorikApi;
    1210
    1311type
     
    2321    VertScrollBox2: TVertScrollBox;
    2422    LabelCredit: TLabel;
    25     IdHTTP1: TIdHTTP;
    2623    Timer1: TTimer;
    27     IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    2824    RectangleCalls: TRectangle;
    2925    Label1: TLabel;
     
    3127    procedure FormCreate(Sender: TObject);
    3228    procedure FormSaveState(Sender: TObject);
    33     procedure ButtonReloadCreditClick(Sender: TObject);
    3429    procedure Timer1Timer(Sender: TObject);
    3530    procedure FormShow(Sender: TObject);
     
    3833    { Private declarations }
    3934  public
    40     UserName: string;
    41     Password: string;
    42     ServerUrl: string;
     35    OdorikApi: TOdorikApi;
    4336    Credit: Double;
    4437    ConfigFileName: string;
     
    4639    procedure LoadConfig;
    4740    procedure SaveConfig;
    48     procedure GetCredit;
    49     function SendGet(Path: string; Parameters: string = ''): string;
    5041  end;
    5142
     
    6152  UFormSettings, UFormCalls;
    6253
    63 procedure TFormMain.ButtonReloadCreditClick(Sender: TObject);
    64 begin
    65   GetCredit;
    66 end;
    67 
    6854procedure TFormMain.FormCreate(Sender: TObject);
    6955begin
    70   {$IFDEF ANDROID}
    71   IdOpenSSLSetLibPath(System.IOUtils.TPath.GetDocumentsPath);
    72   {$ENDIF}
     56  OdorikApi := TOdorikApi.Create(nil);
    7357  ConfigFileName := TPath.Combine(TPath.GetHomePath, 'OdorikApi.ini');
    7458  LoadConfig;
     
    8569    procedure
    8670    begin
    87       GetCredit;
     71      Credit := OdorikApi.GetCredit;
    8872    end).Start;
    89 end;
    90 
    91 procedure TFormMain.GetCredit;
    92 var
    93   Response: string;
    94   Value: Extended;
    95 begin
    96   Response := SendGet('/balance');
    97   if Response <> '' then begin
    98     Response := StringReplace(Response, '.', FormatSettings.DecimalSeparator, [rfReplaceAll]);
    99     if TryStrToFloat(Response, Value) then
    100       Credit := Value
    101       else Credit := 0;
    102   end else Credit := 0;
    10373end;
    10474
     
    11080  with IniFile do
    11181  try
    112     UserName := ReadString('General', 'UserName', '');
    113     Password := ReadString('General', 'Password', '');
    114     ServerUrl := ReadString('General', 'ServerUrl', 'https://www.odorik.cz/api/v1');
     82    OdorikApi.UserName := ReadString('General', 'UserName', '');
     83    OdorikApi.Password := ReadString('General', 'Password', '');
     84    OdorikApi.ServerUrl := ReadString('General', 'ServerUrl', 'https://www.odorik.cz/api/v1');
    11585  finally
    11686    IniFile.Free;
     
    137107  with IniFile do
    138108  try
    139     WriteString('General', 'UserName', UserName);
    140     WriteString('General', 'Password', Password);
    141     WriteString('General', 'ServerUrl', ServerUrl);
     109    WriteString('General', 'UserName', OdorikApi.UserName);
     110    WriteString('General', 'Password', OdorikApi.Password);
     111    WriteString('General', 'ServerUrl', OdorikApi.ServerUrl);
    142112  finally
    143113    IniFile.Free;
     
    145115end;
    146116
    147 function TFormMain.SendGet(Path: string; Parameters: string = ''): string;
    148 var
    149   Url: string;
    150 begin
    151   if (ServerUrl <> '') and (UserName <> '') and (Password <> '') then begin
    152     Url := ServerUrl + Path + '?user=' + UserName + '&password=' + Password;
    153     if Parameters <> '' then Url := Url + '&' + Parameters;
    154     Result := IdHTTP1.Get(Url);
    155   end else Result := '';
    156 end;
    157117
    158118procedure TFormMain.Timer1Timer(Sender: TObject);
     
    160120  if ReloadPending then begin
    161121    ReloadPending := False;
    162     GetCredit;
     122    Credit := OdorikApi.GetCredit;
    163123  end;
    164124  LabelCredit.Text := 'Credit: ' + FloatToStr(Credit) + ' Kè';
  • trunk/UFormSettings.pas

    r2 r3  
    5757begin
    5858  if AResult = mrOk then
    59     FormMain.Password := AValues[0];
     59    FormMain.OdorikApi.Password := AValues[0];
    6060end;
    6161
    6262procedure TFormSettings.RectanglePasswordClick(Sender: TObject);
    6363begin
    64   TDialogService.InputQuery('Password', ['Password'], [FormMain.Password], PasswordQuery);
     64  TDialogService.InputQuery('Password', ['Password'], [FormMain.OdorikApi.Password], PasswordQuery);
    6565end;
    6666
    6767procedure TFormSettings.RectangleServerUrlClick(Sender: TObject);
    6868begin
    69   TDialogService.InputQuery('Server URL', ['Server URL'], [FormMain.ServerUrl], ServerUrlQuery);
     69  TDialogService.InputQuery('Server URL', ['Server URL'], [FormMain.OdorikApi.ServerUrl], ServerUrlQuery);
    7070end;
    7171
    7272procedure TFormSettings.RectangleUserNameClick(Sender: TObject);
    7373begin
    74   TDialogService.InputQuery('User name', ['User name'], [FormMain.UserName], UserNameQuery);
     74  TDialogService.InputQuery('User name', ['User name'], [FormMain.OdorikApi.UserName], UserNameQuery);
    7575end;
    7676
     
    7979begin
    8080  if AResult = mrOk then
    81     FormMain.ServerUrl := AValues[0];
     81    FormMain.OdorikApi.ServerUrl := AValues[0];
    8282end;
    8383
     
    9191begin
    9292  if AResult = mrOk then
    93     FormMain.UserName := AValues[0];
     93    FormMain.OdorikApi.UserName := AValues[0];
    9494end;
    9595
Note: See TracChangeset for help on using the changeset viewer.