Skip to content

Commit 96afe9f

Browse files
authored
Add files via upload
1 parent 61acd60 commit 96afe9f

File tree

1 file changed

+79
-19
lines changed

1 file changed

+79
-19
lines changed

WebAPIClient/B4XMainPage.bas

+79-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Version=9.85
1414
Sub Class_Globals
1515
Private Root As B4XView
1616
Private xui As XUI
17-
Private URL As String = "http://172.20.10.6:19800/v1/" ' "https://api.puterise.com:19900/v1/"
17+
Private URL As String = "http://172.20.10.3:19800/v1/"
1818
Private lblTitle As B4XView
1919
Private lblBack As B4XView
2020
Private clvRecord As CustomListView
@@ -50,6 +50,27 @@ Private Sub B4XPage_Created (Root1 As B4XView)
5050
#End If
5151
End Sub
5252

53+
Private Sub B4XPage_CloseRequest As ResumableSub
54+
If xui.IsB4A Then
55+
'back key in Android
56+
If PrefDialog1.BackKeyPressed Then Return False
57+
If PrefDialog2.BackKeyPressed Then Return False
58+
If PrefDialog3.BackKeyPressed Then Return False
59+
End If
60+
If Viewing = "Product" Then
61+
GetCategories
62+
Return False
63+
End If
64+
Return True
65+
End Sub
66+
67+
'Don't miss the code in the Main module + manifest editor.
68+
Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
69+
PrefDialog1.KeyboardHeightChanged(NewHeight)
70+
PrefDialog2.KeyboardHeightChanged(NewHeight)
71+
PrefDialog3.KeyboardHeightChanged(NewHeight)
72+
End Sub
73+
5374
#If B4j
5475
Private Sub SetScrollPaneBackgroundColor(View As CustomListView, Color As Int)
5576
Dim SP As JavaObject = View.GetBase.GetView(0)
@@ -64,12 +85,10 @@ Private Sub B4XPage_Appear
6485
GetCategories
6586
End Sub
6687

67-
Private Sub B4XPage_CloseRequest As ResumableSub
68-
If Viewing = "Product" Then
69-
GetCategories
70-
Return False
71-
End If
72-
Return True
88+
Private Sub B4XPage_Resize(Width As Int, Height As Int)
89+
If PrefDialog1.IsInitialized And PrefDialog1.Dialog.Visible Then PrefDialog1.Dialog.Resize(Width, Height)
90+
If PrefDialog2.IsInitialized And PrefDialog2.Dialog.Visible Then PrefDialog2.Dialog.Resize(Width, Height)
91+
If PrefDialog3.IsInitialized And PrefDialog3.Dialog.Visible Then PrefDialog3.Dialog.Resize(Width, Height)
7392
End Sub
7493

7594
#If B4J
@@ -200,16 +219,17 @@ Private Sub CreateDialog1
200219
End Sub
201220

202221
Private Sub CreateDialog2
203-
Dim options As List
204-
options.Initialize
222+
Dim categories As List
223+
categories.Initialize
205224
For i = 0 To Category.Length - 1
206-
options.Add(Category(i).Name)
225+
categories.Add(Category(i).Name)
207226
Next
208227
PrefDialog2.Initialize(Root, "Product", 300dip, 250dip)
209228
PrefDialog2.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40)
210229
PrefDialog2.Dialog.TitleBarHeight = 50dip
211230
PrefDialog2.LoadFromJson(File.ReadString(File.DirAssets, "template_product.json"))
212-
PrefDialog2.SetOptions("Category", options)
231+
PrefDialog2.SetOptions("Category", categories)
232+
PrefDialog2.SetEventsListener(Me, "PrefDialog2") '<-- must add to handle events.
213233
End Sub
214234

215235
Private Sub CreateDialog3
@@ -219,7 +239,7 @@ Private Sub CreateDialog3
219239
PrefDialog3.Dialog.TitleBarHeight = 50dip
220240
PrefDialog3.Dialog.TitleBarColor = xui.Color_RGB(220, 20, 60)
221241
PrefDialog3.AddSeparator("default")
222-
End Sub
242+
End Sub
223243

224244
Private Sub ShowDialog1 (Action As String, Item As Map)
225245
If Action = "Add" Then
@@ -229,14 +249,29 @@ Private Sub ShowDialog1 (Action As String, Item As Map)
229249
End If
230250
PrefDialog1.Title = Action & " Category"
231251
Dim sf As Object = PrefDialog1.ShowDialog(Item, "OK", "CANCEL")
252+
#if B4A or B4i
253+
PrefDialog1.Dialog.Base.Top = 100dip ' Make it lower
254+
#Else
255+
'Dim sp As ScrollPane = PrefDialog1.CustomListView1.sv
256+
'sp.SetVScrollVisibility("NEVER")
257+
Sleep(0)
258+
PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
259+
#End If
260+
' Fix Linux UI (Long Text Button)
261+
Dim btnCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
262+
btnCancel.Width = btnCancel.Width + 20dip
263+
btnCancel.Left = btnCancel.Left - 20dip
264+
btnCancel.TextColor = xui.Color_Red
265+
Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
266+
btnOk.Left = btnOk.Left - 20dip
232267
Wait For (sf) Complete (Result As Int)
233268
If Result = xui.DialogResponse_Positive Then
234269
If 0 = Item.Get("id") Then ' New row
235270
Dim CategoryMap As Map = CreateMap("name": Item.Get("Category Name"))
236271
Dim sd As Object = SendData("POST", "category", CategoryMap)
237272
Wait For (sd) Complete (Data As Map)
238273
If Data.Get("s") = "ok" Then
239-
'Log(Data.Get("a")) ' 201 Created
274+
Log(Data.Get("a")) ' 201 Created
240275
Dim l As List = Data.Get("r")
241276
Dim m As Map = l.Get(0)
242277
xui.MsgboxAsync("New category created!", $"ID: ${m.Get("id")}"$)
@@ -268,6 +303,8 @@ Private Sub ShowDialog2 (Action As String, Item As Map)
268303
End If
269304
PrefDialog2.Title = Action & " Product"
270305
Dim sf As Object = PrefDialog2.ShowDialog(Item, "OK", "CANCEL")
306+
Sleep(0)
307+
PrefDialog2.CustomListView1.sv.Height = PrefDialog2.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
271308
Wait For (sf) Complete (Result As Int)
272309
If Result = xui.DialogResponse_Positive Then
273310
If 0 = Item.Get("id") Then ' New row
@@ -301,19 +338,42 @@ Private Sub ShowDialog2 (Action As String, Item As Map)
301338
End If
302339
End Sub
303340

341+
Private Sub PrefDialog2_BeforeDialogDisplayed (Template As Object)
342+
Try
343+
' Fix Linux UI (Long Text Button)
344+
Dim btnCancel As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Cancel)
345+
btnCancel.Width = btnCancel.Width + 20dip
346+
btnCancel.Left = btnCancel.Left - 20dip
347+
btnCancel.TextColor = xui.Color_Red
348+
Dim btnOk As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Positive)
349+
If btnOk.IsInitialized Then
350+
btnOk.Width = btnOk.Width + 20dip
351+
btnOk.Left = btnCancel.Left - btnOk.Width
352+
End If
353+
Catch
354+
Log(LastException)
355+
End Try
356+
End Sub
357+
304358
Private Sub ShowDialog3 (Item As Map, Id As Long)
305359
PrefDialog3.Title = "Delete " & Viewing
306360
Dim sf As Object = PrefDialog3.ShowDialog(Item, "OK", "CANCEL")
307361
#if B4A or B4i
308-
PrefDialog3.Dialog.Base.Top = 200dip ' Make it lower
362+
PrefDialog3.Dialog.Base.Top = 100dip ' Make it lower
309363
#Else
310-
Dim sp As ScrollPane = PrefDialog3.CustomListView1.sv
311-
sp.SetVScrollVisibility("NEVER")
312-
'sp.Pannable = False ' <-- still can scroll :)
364+
' Fix Linux UI (Long Text Button)
365+
'Dim sp As ScrollPane = PrefDialog3.CustomListView1.sv
366+
'sp.SetVScrollVisibility("NEVER")
367+
Sleep(0)
368+
PrefDialog3.CustomListView1.sv.Height = PrefDialog3.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
313369
#End If
370+
Dim btnCancel As B4XView = PrefDialog3.Dialog.GetButton(xui.DialogResponse_Cancel)
371+
btnCancel.Width = btnCancel.Width + 20dip
372+
btnCancel.Left = btnCancel.Left - 20dip
373+
btnCancel.TextColor = xui.Color_Red
374+
Dim btnOk As B4XView = PrefDialog3.Dialog.GetButton(xui.DialogResponse_Positive)
375+
btnOk.Left = btnOk.Left - 20dip
314376
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Text = Item.Get("Item")
315-
'PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Text = " " & Item.Get("Item")
316-
'PrefDialog3.CustomListView1.GetPanel(0).GetView(0).SetTextAlignment("CENTER", "LEFT")
317377
#if b4i
318378
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).TextSize = 16 ' Text too small in ios
319379
#else

0 commit comments

Comments
 (0)