Changeset 4 for trunk/UFormCalls.pas


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 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33__recovery
        44__history
         5OdorikApi.dproj.local
  • 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;
Note: See TracChangeset for help on using the changeset viewer.