Changeset 4 for trunk


Ignore:
Timestamp:
Aug 24, 2019, 12:56:52 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Moved call history loading to API class.
Location:
trunk
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33__recovery
        44__history
         5OdorikApi.dproj.local
  • trunk/UFormCalls.fmx

    r3 r4  
    6262      ExplicitSize.cx = 98.000000000000000000
    6363      ExplicitSize.cy = 49.000000000000000000
    64       object ListView1: TListView
    65         ItemAppearanceClassName = 'TListItemAppearance'
    66         ItemEditAppearanceClassName = 'TListItemShowCheckAppearance'
    67         HeaderAppearanceClassName = 'TListHeaderObjects'
    68         FooterAppearanceClassName = 'TListHeaderObjects'
     64      object ListBox1: TListBox
    6965        Align = Client
    70         Margins.Left = 10.000000000000000000
    71         Margins.Top = 10.000000000000000000
    72         Margins.Right = 10.000000000000000000
    73         Margins.Bottom = 10.000000000000000000
    74         Size.Width = 276.000000000000000000
    75         Size.Height = 317.000000000000000000
     66        Size.Width = 296.000000000000000000
     67        Size.Height = 337.000000000000000000
    7668        Size.PlatformDefault = False
    7769        TabOrder = 0
     70        DisableFocusEffect = True
     71        DefaultItemStyles.ItemStyle = ''
     72        DefaultItemStyles.GroupHeaderStyle = ''
     73        DefaultItemStyles.GroupFooterStyle = ''
     74        Viewport.Width = 296.000000000000000000
     75        Viewport.Height = 337.000000000000000000
    7876      end
    7977    end
  • trunk/UFormCalls.pas

    r3 r4  
    88  FMX.ListView.Types, FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
    99  FMX.ListView, FMX.TabControl, FMX.StdCtrls, FMX.Controls.Presentation,
    10   System.DateUtils, System.TimeSpan, System.JSON;
     10  System.DateUtils, System.TimeSpan, System.JSON, Generics.Collections,
     11  UOdorikApi, FMX.Layouts, FMX.ListBox;
    1112
    1213type
     
    1920    TabItemActive: TTabItem;
    2021    TabItemStatistics: TTabItem;
    21     ListView1: TListView;
     22    ListBox1: TListBox;
    2223    procedure SpeedButtonBackClick(Sender: TObject);
    2324    procedure TabControl1Change(Sender: TObject);
     
    5051end;
    5152
    52 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
    53 const
    54   Neg: array[Boolean] of string = ('+', '-');
    55 var
    56   Bias: Integer;
    57 begin
    58   Result := FormatDateTime('yyyy''-''mm''-''dd''T''hh'':''nn'':''ss''.''zzz', Value); { Do not localize }
    59   Bias := Trunc(TTimeZone.Local.GetUtcOffset(Value).TotalMinutes);
    60   if (Bias <> 0) and ApplyLocalBias then
    61   begin
    62     Result := Format('%s%s%.2d:%.2d', [Result, Neg[Bias > 0],                         { Do not localize }
    63                                        Abs(Bias) div MinsPerHour,
    64                                        Abs(Bias) mod MinsPerHour]);
    65   end else
    66     Result := Result + 'Z'; { Do not localize }
    67 end;
    68 
    6953procedure TFormCalls.TabControl1Change(Sender: TObject);
    7054var
    71   Response: string;
    7255  IntervalFrom: TDateTime;
    7356  IntervalTo: TDateTime;
    7457  ListViewItem: TListViewItem;
    75   Lines: TArray<string>;
    76   I: Integer;
    77   LJsonResponse: TJSONValue;
    78   jv: TJSONValue;
    79   joName: TJSONObject;
     58  Call: TCall;
     59  CallHistory: TList<TCall>;
    8060begin
    8161  ListView1.Items.Clear;
    8262  IntervalTo := Now;
    8363  IntervalFrom := IntervalTo - OneHour * 24;
    84   Response := FormMain.OdorikApi.SendGet('/calls.json', 'from=' + DateTimeToXMLTime(IntervalFrom) +
    85     '&to=' + DateTimeToXMLTime(IntervalTo));
    86   LJsonResponse := TJSONObject.ParseJSONValue(Response);
    87   for jv in LJsonResponse as TJSONArray do begin
    88     joName := jv as TJSONObject;
     64  CallHistory := FormMain.OdorikApi.GetCallHistory(IntervalFrom, IntervalTo);
     65  for Call in CallHistory do begin
    8966    ListViewItem := ListView1.Items.Add;
    90     ListViewItem.Text := joName.Get('source_number').JSONValue.Value;
     67    ListViewItem.Text := Call.SourceNumber;
    9168  end;
    9269end;
  • trunk/UOdorikApi.pas

    r3 r4  
    44
    55uses
    6   System.SysUtils, System.Types, System.Classes, IdHTTP
     6  System.SysUtils, System.Types, System.Classes, Generics.Collections, IdHTTP
    77  {$IFDEF ANDROID},IdSSLOpenSSLHeaders{$endif}, IdIOHandler, IdIOHandlerSocket,
    8   IdIOHandlerStack, IdSSL, IdSSLOpenSSL;
     8  IdIOHandlerStack, IdSSL, IdSSLOpenSSL, System.DateUtils, System.TimeSpan,
     9  System.JSON;
    910
    1011type
     12  TCall = class
     13    Oid: Integer;
     14    RedirectionParentId: Integer;
     15    Date: TDateTime;
     16    Direction: string;
     17    SourceNumber: string;
     18    DestinatioNumber: string;
     19    DestinationName: string;
     20    Length: Integer;
     21    RingingLength: Integer;
     22    Status: string;
     23    Price: Currency;
     24    PricePerMinute: Currency;
     25    BalanceAfter: Currency;
     26    Line: Integer;
     27    Recording: string;
     28  end;
     29
    1130  TOdorikApi = class(TComponent)
    1231  private
     
    1736    Password: string;
    1837    ServerUrl: string;
    19     function GetCredit: Double;
     38    function GetCredit: Currency;
    2039    function SendGet(Path: string; Parameters: string = ''): string;
     40    function GetCallHistory(TimeFrom, TimeTo: TDateTime): TList<TCall>;
    2141    constructor Create(AOwner: TComponent); override;
    2242    destructor Destroy; override;
     
    5373end;
    5474
    55 function TOdorikApi.GetCredit: Double;
     75function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
     76const
     77  Neg: array[Boolean] of string = ('+', '-');
     78var
     79  Bias: Integer;
     80begin
     81  Result := FormatDateTime('yyyy''-''mm''-''dd''T''hh'':''nn'':''ss''.''zzz', Value); { Do not localize }
     82  Bias := Trunc(TTimeZone.Local.GetUtcOffset(Value).TotalMinutes);
     83  if (Bias <> 0) and ApplyLocalBias then
     84  begin
     85    Result := Format('%s%s%.2d:%.2d', [Result, Neg[Bias > 0],                         { Do not localize }
     86                                       Abs(Bias) div MinsPerHour,
     87                                       Abs(Bias) mod MinsPerHour]);
     88  end else
     89    Result := Result + 'Z'; { Do not localize }
     90end;
     91
     92function TOdorikApi.GetCallHistory(TimeFrom, TimeTo: TDateTime): TList<TCall>;
     93var
     94  Response: string;
     95  LJsonResponse: TJSONValue;
     96  jv: TJSONValue;
     97  joName: TJSONObject;
     98  Call: TCall;
     99begin
     100  Result := TList<TCall>.Create;
     101  Response := SendGet('/calls.json', 'from=' + DateTimeToXMLTime(TimeFrom) +
     102    '&to=' + DateTimeToXMLTime(TimeTo));
     103  LJsonResponse := TJSONObject.ParseJSONValue(Response);
     104  for jv in LJsonResponse as TJSONArray do begin
     105    joName := jv as TJSONObject;
     106    Call := TCall.Create;
     107    Call.SourceNumber := joName.Get('source_number').JSONValue.Value;
     108    Call.DestinatioNumber := joName.Get('destination_number').JSONValue.Value;
     109    Result.Add(Call);
     110  end;
     111end;
     112
     113function TOdorikApi.GetCredit: Currency;
    56114var
    57115  Response: string;
Note: See TracChangeset for help on using the changeset viewer.