Skip to content

Commit 25f2013

Browse files
authored
Add files via upload
1 parent 30266a2 commit 25f2013

File tree

6 files changed

+46
-88
lines changed

6 files changed

+46
-88
lines changed

Web API Client (1.05).b4xtemplate

444 KB
Binary file not shown.

Web API Client/B4A/$APPNAME$.b4a

+8-11
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ Group=Default Group
1313
Library1=b4xpages
1414
Library2=b4xpreferencesdialog
1515
Library3=core
16-
Library4=okhttputils2
17-
Library5=xui views
18-
Library6=ime
19-
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)~\n~CreateResourceFromFile(Macro, Core.NetworkClearText) ' Comment this if using https protocol
16+
Library4=ime
17+
Library5=okhttputils2
18+
Library6=xui views
19+
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="31"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)~\n~CreateResourceFromFile(Macro, Core.NetworkClearText) ' Comment this if using https protocol
2020
Module1=|relative|..\B4XMainPage
2121
Module2=Starter
2222
NumberOfFiles=5
2323
NumberOfLibraries=6
2424
NumberOfModules=2
25-
Version=11.5
25+
Version=12.2
2626
@EndOfDesignText@
2727
#Region Project Attributes
2828
#ApplicationLabel: Web API Client
29-
#VersionCode: 4
30-
#VersionName: 1.0.3
29+
#VersionCode: 6
30+
#VersionName: 1.0.5
3131
'SupportedOrientations possible values: unspecified, landscape or portrait.
3232
#SupportedOrientations: portrait
3333
#CanInstallToExternalStorage: False
@@ -92,9 +92,6 @@ End Sub
9292
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
9393
processBA.raiseEvent(null, "create_menu", menu);
9494
return true;
95-
9695
}
9796
#End If
98-
#End Region
99-
100-
'Program code should go into B4XMainPage and other pages.
97+
#End Region

Web API Client/B4A/Starter.bas

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,25 @@ Version=9.85
1010
#End Region
1111

1212
Sub Process_Globals
13-
'These global variables will be declared once when the application starts.
14-
'These variables can be accessed from all modules.
1513

1614
End Sub
1715

1816
Sub Service_Create
19-
'This is the program entry point.
20-
'This is a good place to load resources that are not specific to a single activity.
2117

2218
End Sub
2319

2420
Sub Service_Start (StartingIntent As Intent)
25-
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
21+
Service.StopAutomaticForeground
2622
End Sub
2723

2824
Sub Service_TaskRemoved
29-
'This event will be raised when the user removes the app from the recent apps list.
25+
3026
End Sub
3127

32-
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
3328
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
3429
Return True
3530
End Sub
3631

3732
Sub Service_Destroy
3833

39-
End Sub
34+
End Sub

Web API Client/B4J/$APPNAME$.b4j

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Library1=b4xpages
1717
Library2=b4xpreferencesdialog
1818
Library3=jcore
1919
Library4=jfx
20-
Library5=xui views
21-
Library6=jokhttputils2
20+
Library5=jokhttputils2
21+
Library6=xui views
2222
Module1=|relative|..\B4XMainPage
2323
NumberOfFiles=6
2424
NumberOfLibraries=6
2525
NumberOfModules=1
26-
Version=9.5
26+
Version=9.8
2727
@EndOfDesignText@
28-
' Version 1.0.3
28+
' Version 1.0.5
2929
#Region Project Attributes
3030
#MainFormWidth: 600
3131
#MainFormHeight: 600

Web API Client/B4XMainPage.bas

+26-61
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://192.168.0.3:19800/v1/" ' Change to your Web API Server URL
17+
Private URL As String = "http://192.168.50.42:19800/v1/" ' Change to your Web API Server URL
1818
Private lblTitle As B4XView
1919
Private lblBack As B4XView
2020
Private clvRecord As CustomListView
@@ -40,7 +40,6 @@ Public Sub Initialize
4040
' B4XPages.GetManager.LogEvents = True
4141
End Sub
4242

43-
'This event will be called once, before the page becomes visible.
4443
Private Sub B4XPage_Created (Root1 As B4XView)
4544
Root = Root1
4645
Root.LoadLayout("MainPage")
@@ -71,7 +70,7 @@ Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
7170
PrefDialog3.KeyboardHeightChanged(NewHeight)
7271
End Sub
7372

74-
#If B4j
73+
#If B4J
7574
Private Sub SetScrollPaneBackgroundColor(View As CustomListView, Color As Int)
7675
Dim SP As JavaObject = View.GetBase.GetView(0)
7776
Dim V As B4XView = SP
@@ -104,7 +103,7 @@ End Sub
104103
Private Sub GetCategories
105104
Try
106105
Dim i As Long
107-
Dim sd As Object = SendData("GET", "category", Null)
106+
Dim sd As Object = SendData("GET", "categories", Null)
108107
Wait For (sd) Complete (Data As Map)
109108
If Data.Get("s") = "ok" Then
110109
Dim Items As List = Data.Get("r")
@@ -135,7 +134,7 @@ End Sub
135134

136135
Private Sub GetProducts
137136
clvRecord.Clear
138-
Dim sd As Object = SendData("GET", $"category/${CategoryId}/product"$, Null)
137+
Dim sd As Object = SendData("GET", $"find/product/cid/${CategoryId}"$, Null)
139138
Wait For (sd) Complete (Data As Map)
140139
If Data.Get("s") = "ok" Then
141140
If 204 = Data.Get("a") Then
@@ -146,8 +145,6 @@ Private Sub GetProducts
146145
clvRecord.Add(CreateProductItems(Item.Get("product_code"), GetCategoryName(Item.Get("category_id")), Item.Get("product_name"), NumberFormat2(Item.Get("product_price"), 1, 2, 2, True), clvRecord.AsView.Width), Item.Get("id"))
147146
Next
148147
End If
149-
Else
150-
xui.MsgboxAsync(Data.Get("e"), "Error")
151148
End If
152149
Viewing = "Product"
153150
lblTitle.Text = GetCategoryName(CategoryId)
@@ -268,10 +265,10 @@ Private Sub ShowDialog1 (Action As String, Item As Map)
268265
If Result = xui.DialogResponse_Positive Then
269266
If 0 = Item.Get("id") Then ' New row
270267
Dim CategoryMap As Map = CreateMap("name": Item.Get("Category Name"))
271-
Dim sd As Object = SendData("POST", "category", CategoryMap)
268+
Dim sd As Object = SendData("POST", "categories", CategoryMap)
272269
Wait For (sd) Complete (Data As Map)
273270
If Data.Get("s") = "ok" Then
274-
Log(Data.Get("a")) ' 201 Created
271+
'Log(Data.Get("a")) ' 201 Created
275272
Dim l As List = Data.Get("r")
276273
Dim m As Map = l.Get(0)
277274
xui.MsgboxAsync("New category created!", $"ID: ${m.Get("id")}"$)
@@ -281,7 +278,7 @@ Private Sub ShowDialog1 (Action As String, Item As Map)
281278
End If
282279
Else
283280
Dim CategoryMap As Map = CreateMap("name": Item.Get("Category Name"))
284-
Dim sd As Object = SendData("PUT", $"category/${Item.Get("id")}"$, CategoryMap)
281+
Dim sd As Object = SendData("PUT", $"categories/${Item.Get("id")}"$, CategoryMap)
285282
Wait For (sd) Complete (Data As Map)
286283
If Data.Get("s") = "ok" Then
287284
xui.MsgboxAsync("Category updated!", "Edit")
@@ -309,8 +306,8 @@ Private Sub ShowDialog2 (Action As String, Item As Map)
309306
If Result = xui.DialogResponse_Positive Then
310307
If 0 = Item.Get("id") Then ' New row
311308
CategoryId = GetCategoryId(Item.Get("Category"))
312-
Dim ProductMap As Map = CreateMap("code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price"))
313-
Dim sd As Object = SendData("POST", $"category/${CategoryId}/product"$, ProductMap)
309+
Dim ProductMap As Map = CreateMap("cat_id": CategoryId, "code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price"))
310+
Dim sd As Object = SendData("POST", $"products"$, ProductMap)
314311
Wait For (sd) Complete (Data As Map)
315312
If Data.Get("s") = "ok" Then
316313
'Log(Data.Get("a")) ' 201 Created
@@ -323,7 +320,7 @@ Private Sub ShowDialog2 (Action As String, Item As Map)
323320
Else
324321
Dim NewCategoryId As Long = GetCategoryId(Item.Get("Category"))
325322
Dim ProductMap As Map = CreateMap("cat_id": NewCategoryId, "code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price"))
326-
Dim sd As Object = SendData("PUT", $"category/${CategoryId}/product/${Item.Get("id")}"$, ProductMap)
323+
Dim sd As Object = SendData("PUT", $"products/${Item.Get("id")}"$, ProductMap)
327324
Wait For (sd) Complete (Data As Map)
328325
If Data.Get("s") = "ok" Then
329326
xui.MsgboxAsync("Product updated!", "Edit")
@@ -340,16 +337,16 @@ End Sub
340337

341338
Private Sub PrefDialog2_BeforeDialogDisplayed (Template As Object)
342339
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
340+
' Fix Linux UI (Long Text Button)
341+
Dim btnCancel As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Cancel)
342+
btnCancel.Width = btnCancel.Width + 20dip
343+
btnCancel.Left = btnCancel.Left - 20dip
344+
btnCancel.TextColor = xui.Color_Red
345+
Dim btnOk As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Positive)
346+
If btnOk.IsInitialized Then
347+
btnOk.Width = btnOk.Width + 20dip
348+
btnOk.Left = btnCancel.Left - btnOk.Width
349+
End If
353350
Catch
354351
Log(LastException)
355352
End Try
@@ -374,19 +371,19 @@ Private Sub ShowDialog3 (Item As Map, Id As Long)
374371
Dim btnOk As B4XView = PrefDialog3.Dialog.GetButton(xui.DialogResponse_Positive)
375372
btnOk.Left = btnOk.Left - 20dip
376373
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Text = Item.Get("Item")
377-
#if b4i
374+
#If B4i
378375
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).TextSize = 16 ' Text too small in ios
379-
#else
376+
#Else
380377
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).TextSize = 15 ' 14
381378
#End If
382379
PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Color = xui.Color_Transparent
383380
PrefDialog3.CustomListView1.sv.ScrollViewInnerPanel.Color = xui.Color_Transparent
384381
Wait For (sf) Complete (Result As Int)
385382
If Result = xui.DialogResponse_Positive Then
386383
If Viewing = "Product" Then
387-
Dim sd As Object = SendData("DELETE", $"category/${CategoryId}/product/${Id}"$, Null)
384+
Dim sd As Object = SendData("DELETE", $"products/${Id}"$, Null)
388385
Else
389-
Dim sd As Object = SendData("DELETE", $"category/${CategoryId}"$, Null)
386+
Dim sd As Object = SendData("DELETE", $"categories/${CategoryId}"$, Null)
390387
End If
391388
Wait For (sd) Complete (Data As Map)
392389
If Data.Get("s") = "ok" Then
@@ -456,31 +453,19 @@ Sub SendData (Method As String, EndPoint As String, Payload As Map) As Resumable
456453
'Log("Link:" & Link)
457454
indLoading.Show
458455
j.Initialize("", Me)
459-
Select Case Method.ToUpperCase
456+
Select Method.ToUpperCase
460457
Case "POST"
461-
#if b4i
462-
j.PostString(Link, Map2JSON(Payload)) ' old version of B4i
463-
#else
464458
j.PostString(Link, Payload.As(JSON).ToString)
465-
#End If
466459
Case "PUT"
467-
#if b4i
468-
j.PutString(Link, Map2JSON(Payload)) ' old version of B4i
469-
#else
470460
j.PutString(Link, Payload.As(JSON).ToString)
471-
#End If
472461
Case "DELETE"
473462
j.Delete(Link)
474463
Case Else ' GET
475464
j.Download(Link)
476465
End Select
477466
Wait For (j) JobDone(j As HttpJob)
478467
If j.Success Then
479-
#if b4i
480-
Data = JSON2Map(j.GetString) ' old version of B4i
481-
#else
482468
Data = j.GetString.As(JSON).ToMap 'ignore
483-
#End If
484469
Data.Put("a", j.Response.StatusCode)
485470
#if B4J
486471
lblStatus.Text = "Connected to " & URL
@@ -490,11 +475,7 @@ Sub SendData (Method As String, EndPoint As String, Payload As Map) As Resumable
490475
lblStatus.TextColor = xui.Color_White
491476
Else
492477
If j.ErrorMessage.Contains($""s": "error""$) Then
493-
#if b4i
494-
Data = JSON2Map(j.ErrorMessage) ' old version of B4i
495-
#else
496478
Data = j.ErrorMessage.As(JSON).ToMap 'ignore
497-
#End If
498479
Data.Put("a", j.Response.StatusCode)
499480
Else
500481
Data = CreateMap("s": "error", "e": j.ErrorMessage, "m": "")
@@ -517,20 +498,4 @@ Sub SendData (Method As String, EndPoint As String, Payload As Map) As Resumable
517498
j.Release
518499
indLoading.Hide
519500
Return Data
520-
End Sub
521-
522-
#if b4i
523-
Private Sub Map2JSON (Map As Map) As String
524-
Dim gen As JSONGenerator
525-
gen.Initialize(Map)
526-
Return gen.ToString
527-
End Sub
528-
529-
Private Sub JSON2Map (str As String) As Map
530-
Dim par As JSONParser
531-
par.Initialize(str)
532-
Dim m As Map = par.NextObject
533-
Dim ser As B4XSerializator
534-
Return ser.ConvertBytesToObject(ser.ConvertObjectToBytes(m)) ' convert map to writable map in B4i
535-
End Sub
536-
#End If
501+
End Sub

Web API Client/B4i/$APPNAME$.b4i

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ Library1=b4xpages
1414
Library2=b4xpreferencesdialog
1515
Library3=icore
1616
Library4=ihttputils2
17-
Library5=xui views
18-
Library6=ijson
17+
Library5=ijson
18+
Library6=xui views
1919
Module1=|relative|..\B4XMainPage
2020
NumberOfFiles=5
2121
NumberOfLibraries=6
2222
NumberOfModules=1
23-
Version=7.8
23+
Version=8.1
2424
@EndOfDesignText@
2525
'Code module
2626
#Region Project Attributes
2727
#ApplicationLabel: Web API Client
28-
#Version: 1.0.3
28+
#Version: 1.0.5
2929
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
3030
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
3131
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
@@ -40,6 +40,7 @@ Version=7.8
4040
#CertificateFile: ios_development.cer
4141
#ProvisionFile: development.mobileprovision
4242
#End If
43+
4344
Sub Process_Globals
4445
Public App As Application
4546
Public NavControl As NavigationController

0 commit comments

Comments
 (0)