1 | unit UFormMain;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
|
---|
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
|
---|
8 | FMX.Layouts, FMX.Objects, FMX.Controls.Presentation, FMX.MultiView, IniFiles,
|
---|
9 | System.IOUtils, UOdorikApi;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TFormMain = class(TForm)
|
---|
13 | MultiView1: TMultiView;
|
---|
14 | Layout1: TLayout;
|
---|
15 | ToolBar1: TToolBar;
|
---|
16 | SpeedButtonMenu: TSpeedButton;
|
---|
17 | Rectangle1: TRectangle;
|
---|
18 | VertScrollBox1: TVertScrollBox;
|
---|
19 | RectangleSettings: TRectangle;
|
---|
20 | LabelSettings: TLabel;
|
---|
21 | VertScrollBox2: TVertScrollBox;
|
---|
22 | LabelCredit: TLabel;
|
---|
23 | Timer1: TTimer;
|
---|
24 | RectangleCalls: TRectangle;
|
---|
25 | Label1: TLabel;
|
---|
26 | procedure RectangleSettingsClick(Sender: TObject);
|
---|
27 | procedure FormCreate(Sender: TObject);
|
---|
28 | procedure FormSaveState(Sender: TObject);
|
---|
29 | procedure Timer1Timer(Sender: TObject);
|
---|
30 | procedure FormShow(Sender: TObject);
|
---|
31 | procedure RectangleCallsClick(Sender: TObject);
|
---|
32 | private
|
---|
33 | { Private declarations }
|
---|
34 | public
|
---|
35 | OdorikApi: TOdorikApi;
|
---|
36 | Credit: Double;
|
---|
37 | ConfigFileName: string;
|
---|
38 | ReloadPending: Boolean;
|
---|
39 | procedure LoadConfig;
|
---|
40 | procedure SaveConfig;
|
---|
41 | end;
|
---|
42 |
|
---|
43 | var
|
---|
44 | FormMain: TFormMain;
|
---|
45 |
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | {$R *.fmx}
|
---|
50 |
|
---|
51 | uses
|
---|
52 | UFormSettings, UFormCalls;
|
---|
53 |
|
---|
54 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
55 | begin
|
---|
56 | OdorikApi := TOdorikApi.Create(nil);
|
---|
57 | ConfigFileName := TPath.Combine(TPath.GetHomePath, 'OdorikApi.ini');
|
---|
58 | LoadConfig;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | procedure TFormMain.FormSaveState(Sender: TObject);
|
---|
62 | begin
|
---|
63 | SaveConfig;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
67 | begin
|
---|
68 | TThread.CreateAnonymousThread(
|
---|
69 | procedure
|
---|
70 | begin
|
---|
71 | Credit := OdorikApi.GetCredit;
|
---|
72 | end).Start;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure TFormMain.LoadConfig;
|
---|
76 | var
|
---|
77 | IniFile: TIniFile;
|
---|
78 | begin
|
---|
79 | IniFile := TIniFile.Create(ConfigFileName);
|
---|
80 | with IniFile do
|
---|
81 | try
|
---|
82 | OdorikApi.UserName := ReadString('General', 'UserName', '');
|
---|
83 | OdorikApi.Password := ReadString('General', 'Password', '');
|
---|
84 | OdorikApi.ServerUrl := ReadString('General', 'ServerUrl', 'https://www.odorik.cz/api/v1');
|
---|
85 | finally
|
---|
86 | IniFile.Free;
|
---|
87 | end;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure TFormMain.RectangleCallsClick(Sender: TObject);
|
---|
91 | begin
|
---|
92 | MultiView1.HideMaster;
|
---|
93 | FormCalls.Show;
|
---|
94 | end;
|
---|
95 |
|
---|
96 | procedure TFormMain.RectangleSettingsClick(Sender: TObject);
|
---|
97 | begin
|
---|
98 | MultiView1.HideMaster;
|
---|
99 | FormSettings.Show;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | procedure TFormMain.SaveConfig;
|
---|
103 | var
|
---|
104 | IniFile: TIniFile;
|
---|
105 | begin
|
---|
106 | IniFile := TIniFile.Create(ConfigFileName);
|
---|
107 | with IniFile do
|
---|
108 | try
|
---|
109 | WriteString('General', 'UserName', OdorikApi.UserName);
|
---|
110 | WriteString('General', 'Password', OdorikApi.Password);
|
---|
111 | WriteString('General', 'ServerUrl', OdorikApi.ServerUrl);
|
---|
112 | finally
|
---|
113 | IniFile.Free;
|
---|
114 | end;
|
---|
115 | end;
|
---|
116 |
|
---|
117 |
|
---|
118 | procedure TFormMain.Timer1Timer(Sender: TObject);
|
---|
119 | begin
|
---|
120 | if ReloadPending then begin
|
---|
121 | ReloadPending := False;
|
---|
122 | Credit := OdorikApi.GetCredit;
|
---|
123 | end;
|
---|
124 | LabelCredit.Text := 'Credit: ' + FloatToStr(Credit) + ' Kè';
|
---|
125 | end;
|
---|
126 |
|
---|
127 | end.
|
---|