diff --git a/WebAPIClient/B4A/Files/categoryitem.bal b/WebAPIClient/B4A/Files/categoryitem.bal deleted file mode 100644 index 9bb0c47..0000000 Binary files a/WebAPIClient/B4A/Files/categoryitem.bal and /dev/null differ diff --git a/WebAPIClient/B4A/Files/mainpage.bal b/WebAPIClient/B4A/Files/mainpage.bal deleted file mode 100644 index f54a4df..0000000 Binary files a/WebAPIClient/B4A/Files/mainpage.bal and /dev/null differ diff --git a/WebAPIClient/B4A/Files/productitem.bal b/WebAPIClient/B4A/Files/productitem.bal deleted file mode 100644 index 1cb70b7..0000000 Binary files a/WebAPIClient/B4A/Files/productitem.bal and /dev/null differ diff --git a/WebAPIClient/B4A/Files/template_category.json b/WebAPIClient/B4A/Files/template_category.json deleted file mode 100644 index d19bb22..0000000 --- a/WebAPIClient/B4A/Files/template_category.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Name", - "type": "Text", - "key": "Category Name", - "required": true - } ] -} \ No newline at end of file diff --git a/WebAPIClient/B4A/Files/template_product.json b/WebAPIClient/B4A/Files/template_product.json deleted file mode 100644 index 38f29d3..0000000 --- a/WebAPIClient/B4A/Files/template_product.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Category", - "type": "Options", - "key": "Category", - "required": true - }, - { - "title": "Name", - "type": "Text", - "key": "Product Name", - "required": true - }, - { - "title": "Code", - "type": "Text", - "key": "Product Code", - "required": true - }, - { - "title": "Price", - "type": "Text", - "key": "Product Price", - "required": true - } - ] -} \ No newline at end of file diff --git a/WebAPIClient/B4A/Objects/res/drawable/icon.png b/WebAPIClient/B4A/Objects/res/drawable/icon.png deleted file mode 100644 index 3f0e85c..0000000 Binary files a/WebAPIClient/B4A/Objects/res/drawable/icon.png and /dev/null differ diff --git a/WebAPIClient/B4A/Starter.bas b/WebAPIClient/B4A/Starter.bas deleted file mode 100644 index 8f9455e..0000000 --- a/WebAPIClient/B4A/Starter.bas +++ /dev/null @@ -1,39 +0,0 @@ -B4A=true -Group=Default Group -ModulesStructureVersion=1 -Type=Service -Version=9.85 -@EndOfDesignText@ -#Region Service Attributes - #StartAtBoot: False - #ExcludeFromLibrary: True -#End Region - -Sub Process_Globals - 'These global variables will be declared once when the application starts. - 'These variables can be accessed from all modules. - -End Sub - -Sub Service_Create - 'This is the program entry point. - 'This is a good place to load resources that are not specific to a single activity. - -End Sub - -Sub Service_Start (StartingIntent As Intent) - Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases. -End Sub - -Sub Service_TaskRemoved - 'This event will be raised when the user removes the app from the recent apps list. -End Sub - -'Return true to allow the OS default exceptions handler to handle the uncaught exception. -Sub Application_Error (Error As Exception, StackTrace As String) As Boolean - Return True -End Sub - -Sub Service_Destroy - -End Sub diff --git a/WebAPIClient/B4A/WebAPIClient.b4a b/WebAPIClient/B4A/WebAPIClient.b4a deleted file mode 100644 index b43c1f0..0000000 --- a/WebAPIClient/B4A/WebAPIClient.b4a +++ /dev/null @@ -1,100 +0,0 @@ -Build1=Default,b4a.webapi.client -File1=CategoryItem.bal -File2=MainPage.bal -File3=ProductItem.bal -File4=template_category.json -File5=template_product.json -FileGroup1=Default Group -FileGroup2=Default Group -FileGroup3=Default Group -FileGroup4=Default Group -FileGroup5=Default Group -Group=Default Group -Library1=b4xpages -Library2=b4xpreferencesdialog -Library3=core -Library4=okhttputils2 -Library5=xui views -Library6=ime -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~~\n~)~\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) -Module1=|relative|..\B4XMainPage -Module2=Starter -NumberOfFiles=5 -NumberOfLibraries=6 -NumberOfModules=2 -Version=11 -@EndOfDesignText@ -#Region Project Attributes - #ApplicationLabel: WebAPI Client - #VersionCode: 3 - #VersionName: 1.02 - 'SupportedOrientations possible values: unspecified, landscape or portrait. - #SupportedOrientations: portrait - #CanInstallToExternalStorage: False -#End Region - -#Region Activity Attributes - #FullScreen: False - #IncludeTitle: True -#End Region - -'#BridgeLogger: True - -Sub Process_Globals - Public ActionBarHomeClicked As Boolean -End Sub - -Sub Globals - Private ime As IME -End Sub - -Sub Activity_Create(FirstTime As Boolean) - ime.Initialize("IME") - ime.AddHeightChangedEvent - Dim pm As B4XPagesManager - pm.Initialize(Activity) -End Sub - -Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int) - B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "IME_HeightChanged", Array(NewHeight, OldHeight)) -End Sub - -'Template version: B4A-1.01 -#Region Delegates - -Sub Activity_ActionBarHomeClick - ActionBarHomeClicked = True - B4XPages.Delegate.Activity_ActionBarHomeClick - ActionBarHomeClicked = False -End Sub - -Sub Activity_KeyPress (KeyCode As Int) As Boolean - Return B4XPages.Delegate.Activity_KeyPress(KeyCode) -End Sub - -Sub Activity_Resume - B4XPages.Delegate.Activity_Resume -End Sub - -Sub Activity_Pause (UserClosed As Boolean) - B4XPages.Delegate.Activity_Pause -End Sub - -Sub Activity_PermissionResult (Permission As String, Result As Boolean) - B4XPages.Delegate.Activity_PermissionResult(Permission, Result) -End Sub - -Sub Create_Menu (Menu As Object) - B4XPages.Delegate.Create_Menu(Menu) -End Sub - -#if Java -public boolean _onCreateOptionsMenu(android.view.Menu menu) { - processBA.raiseEvent(null, "create_menu", menu); - return true; - -} -#End If -#End Region - -'Program code should go into B4XMainPage and other pages. \ No newline at end of file diff --git a/WebAPIClient/B4J/Files/CategoryItem.bjl b/WebAPIClient/B4J/Files/CategoryItem.bjl deleted file mode 100644 index 7ca97e0..0000000 Binary files a/WebAPIClient/B4J/Files/CategoryItem.bjl and /dev/null differ diff --git a/WebAPIClient/B4J/Files/MainPage.bjl b/WebAPIClient/B4J/Files/MainPage.bjl deleted file mode 100644 index 82c8a93..0000000 Binary files a/WebAPIClient/B4J/Files/MainPage.bjl and /dev/null differ diff --git a/WebAPIClient/B4J/Files/ProductItem.bjl b/WebAPIClient/B4J/Files/ProductItem.bjl deleted file mode 100644 index 9474123..0000000 Binary files a/WebAPIClient/B4J/Files/ProductItem.bjl and /dev/null differ diff --git a/WebAPIClient/B4J/Files/icon.png b/WebAPIClient/B4J/Files/icon.png deleted file mode 100644 index 3f0e85c..0000000 Binary files a/WebAPIClient/B4J/Files/icon.png and /dev/null differ diff --git a/WebAPIClient/B4J/Files/template_category.json b/WebAPIClient/B4J/Files/template_category.json deleted file mode 100644 index d19bb22..0000000 --- a/WebAPIClient/B4J/Files/template_category.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Name", - "type": "Text", - "key": "Category Name", - "required": true - } ] -} \ No newline at end of file diff --git a/WebAPIClient/B4J/Files/template_product.json b/WebAPIClient/B4J/Files/template_product.json deleted file mode 100644 index 38f29d3..0000000 --- a/WebAPIClient/B4J/Files/template_product.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Category", - "type": "Options", - "key": "Category", - "required": true - }, - { - "title": "Name", - "type": "Text", - "key": "Product Name", - "required": true - }, - { - "title": "Code", - "type": "Text", - "key": "Product Code", - "required": true - }, - { - "title": "Price", - "type": "Text", - "key": "Product Price", - "required": true - } - ] -} \ No newline at end of file diff --git a/WebAPIClient/B4J/WebAPIClient.b4j b/WebAPIClient/B4J/WebAPIClient.b4j deleted file mode 100644 index fc48989..0000000 --- a/WebAPIClient/B4J/WebAPIClient.b4j +++ /dev/null @@ -1,67 +0,0 @@ -AppType=JavaFX -Build1=Default,b4j.webapi.client -File1=CategoryItem.bjl -File2=icon.png -File3=MainPage.bjl -File4=ProductItem.bjl -File5=template_category.json -File6=template_product.json -FileGroup1=Default Group -FileGroup2=Default Group -FileGroup3=Default Group -FileGroup4=Default Group -FileGroup5=Default Group -FileGroup6=Default Group -Group=Default Group -Library1=b4xpages -Library2=b4xpreferencesdialog -Library3=jcore -Library4=jfx -Library5=xui views -Library6=jokhttputils2 -Module1=|relative|..\B4XMainPage -NumberOfFiles=6 -NumberOfLibraries=6 -NumberOfModules=1 -Version=9.1 -@EndOfDesignText@ -' Version 1.02 -#Region Project Attributes - #MainFormWidth: 600 - #MainFormHeight: 600 -#End Region - -Sub Process_Globals - Private fx As JFX - Private MainForm As Form -End Sub - -Sub AppStart (Form1 As Form, Args() As String) - MainForm = Form1 - MainForm.Show - Dim PagesManager As B4XPagesManager - PagesManager.Initialize(MainForm) -End Sub - -'Template version: B4J-1.0 -#Region Delegates -Sub MainForm_FocusChanged (HasFocus As Boolean) - B4XPages.Delegate.MainForm_FocusChanged(HasFocus) -End Sub - -Sub MainForm_Resize (Width As Double, Height As Double) - B4XPages.Delegate.MainForm_Resize(Width, Height) -End Sub - -Sub MainForm_Closed - B4XPages.Delegate.MainForm_Closed -End Sub - -Sub MainForm_CloseRequest (EventData As Event) - B4XPages.Delegate.MainForm_CloseRequest(EventData) -End Sub - -Public Sub MainForm_IconifiedChanged (Iconified As Boolean) - B4XPages.Delegate.MainForm_IconifiedChanged(Iconified) -End Sub -#End Region \ No newline at end of file diff --git a/WebAPIClient/B4XMainPage.bas b/WebAPIClient/B4XMainPage.bas deleted file mode 100644 index 79291d1..0000000 --- a/WebAPIClient/B4XMainPage.bas +++ /dev/null @@ -1,536 +0,0 @@ -B4A=true -Group=Default Group -ModulesStructureVersion=1 -Type=Class -Version=9.85 -@EndOfDesignText@ -#Region Shared Files -#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files" -'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True -#End Region - -'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip - -Sub Class_Globals - Private Root As B4XView - Private xui As XUI - Private URL As String = "http://172.20.10.3:19800/v1/" - Private lblTitle As B4XView - Private lblBack As B4XView - Private clvRecord As CustomListView - Private btnEdit As B4XView - Private btnDelete As B4XView - Private btnNew As B4XView - Private lblName As B4XView - Private lblCategory As B4XView - Private lblCode As B4XView - Private lblPrice As B4XView - Private lblStatus As B4XView - Private indLoading As B4XLoadingIndicator - Private PrefDialog1 As PreferencesDialog - Private PrefDialog2 As PreferencesDialog - Private PrefDialog3 As PreferencesDialog - Dim Viewing As String - Dim CategoryId As Long - Dim Category() As Category - Type Category (Id As Long, Name As String) -End Sub - -Public Sub Initialize -' B4XPages.GetManager.LogEvents = True -End Sub - -'This event will be called once, before the page becomes visible. -Private Sub B4XPage_Created (Root1 As B4XView) - Root = Root1 - Root.LoadLayout("MainPage") - B4XPages.SetTitle(Me, "WebAPI Client") - #if B4J - CallSubDelayed3(Me, "SetScrollPaneBackgroundColor", clvRecord, xui.Color_Transparent) - #End If -End Sub - -Private Sub B4XPage_CloseRequest As ResumableSub - If xui.IsB4A Then - 'back key in Android - If PrefDialog1.BackKeyPressed Then Return False - If PrefDialog2.BackKeyPressed Then Return False - If PrefDialog3.BackKeyPressed Then Return False - End If - If Viewing = "Product" Then - GetCategories - Return False - End If - Return True -End Sub - -'Don't miss the code in the Main module + manifest editor. -Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int) - PrefDialog1.KeyboardHeightChanged(NewHeight) - PrefDialog2.KeyboardHeightChanged(NewHeight) - PrefDialog3.KeyboardHeightChanged(NewHeight) -End Sub - -#If B4j -Private Sub SetScrollPaneBackgroundColor(View As CustomListView, Color As Int) - Dim SP As JavaObject = View.GetBase.GetView(0) - Dim V As B4XView = SP - V.Color = Color - Dim V As B4XView = SP.RunMethod("lookup", Array(".viewport")) - V.Color = Color -End Sub -#End If - -Private Sub B4XPage_Appear - GetCategories -End Sub - -Private Sub B4XPage_Resize(Width As Int, Height As Int) - If PrefDialog1.IsInitialized And PrefDialog1.Dialog.Visible Then PrefDialog1.Dialog.Resize(Width, Height) - If PrefDialog2.IsInitialized And PrefDialog2.Dialog.Visible Then PrefDialog2.Dialog.Resize(Width, Height) - If PrefDialog3.IsInitialized And PrefDialog3.Dialog.Visible Then PrefDialog3.Dialog.Resize(Width, Height) -End Sub - -#If B4J -Private Sub lblBack_MouseClicked (EventData As MouseEvent) - GetCategories -End Sub -#Else -Private Sub lblBack_Click - GetCategories -End Sub -#End If - -Private Sub GetCategories - Try - Dim i As Long - Dim sd As Object = SendData("GET", "category", Null) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - Dim Items As List = Data.Get("r") - Dim Category(Items.Size) As Category - For Each Item As Map In Items - Category(i).Id = Item.Get("id") - Category(i).Name = Item.Get("category_name") - i = i + 1 - Next - clvRecord.Clear - For i = 0 To Category.Length - 1 - clvRecord.Add(CreateCategoryItems(Category(i).Name, clvRecord.AsView.Width), Category(i).Id) - Next - Viewing = "Category" - lblTitle.Text = "Category" - lblBack.Visible = False - CreateDialog1 - CreateDialog2 - CreateDialog3 - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - Catch - 'Log(LastException) - xui.MsgboxAsync(LastException.Message, "Error") - End Try -End Sub - -Private Sub GetProducts - clvRecord.Clear - Dim sd As Object = SendData("GET", $"category/${CategoryId}/product"$, Null) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - If 204 = Data.Get("a") Then - xui.MsgboxAsync(Data.Get("m"), "No Product") - Else - Dim Items As List = Data.Get("r") - For Each Item As Map In Items - 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")) - Next - End If - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - Viewing = "Product" - lblTitle.Text = GetCategoryName(CategoryId) - lblBack.Visible = True -End Sub - -Private Sub GetCategoryName (Id As Long) As String - Dim i As Long - For i = 0 To Category.Length - 1 - If Category(i).Id = Id Then - Return Category(i).Name - End If - Next - Return "" -End Sub - -Private Sub GetCategoryId (Name As String) As Long - Dim i As Long - For i = 0 To Category.Length - 1 - If Category(i).Name = Name Then - Return Category(i).Id - End If - Next - Return 0 -End Sub - -Private Sub clvRecord_ItemClick (Index As Int, Value As Object) - If Viewing = "Category" Then - CategoryId = Value - GetProducts - End If -End Sub - -Private Sub btnNew_Click - If Category.Length = 0 Then Return - If Viewing = "Product" Then - Dim ProductMap As Map = CreateMap("Product Code": "", "Category": GetCategoryName(CategoryId), "Product Name": "", "Product Price": "", "id": 0) - ShowDialog2("Add", ProductMap) - Else - Dim CategoryMap As Map = CreateMap("Category Name": "", "id": 0) - ShowDialog1("Add", CategoryMap) - End If -End Sub - -Private Sub CreateCategoryItems (Name As String, Width As Double) As B4XView - Dim p As B4XView = xui.CreatePanel("") - p.SetLayoutAnimated(0, 0, 0, Width, 90dip) - p.LoadLayout("CategoryItem") - lblName.Text = Name - Return p -End Sub - -Private Sub CreateProductItems (ProductCode As String, CategoryName As String, ProductName As String, ProductPrice As String, Width As Double) As B4XView - Dim p As B4XView = xui.CreatePanel("") - p.SetLayoutAnimated(0, 0, 0, Width, 180dip) - p.LoadLayout("ProductItem") - lblCode.Text = ProductCode - lblCategory.Text = CategoryName - lblName.Text = ProductName - lblPrice.Text = ProductPrice - Return p -End Sub - -Private Sub CreateDialog1 - PrefDialog1.Initialize(Root, "Category", 300dip, 70dip) - PrefDialog1.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40) - PrefDialog1.Dialog.TitleBarHeight = 50dip - PrefDialog1.LoadFromJson(File.ReadString(File.DirAssets, "template_category.json")) -End Sub - -Private Sub CreateDialog2 - Dim categories As List - categories.Initialize - For i = 0 To Category.Length - 1 - categories.Add(Category(i).Name) - Next - PrefDialog2.Initialize(Root, "Product", 300dip, 250dip) - PrefDialog2.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40) - PrefDialog2.Dialog.TitleBarHeight = 50dip - PrefDialog2.LoadFromJson(File.ReadString(File.DirAssets, "template_product.json")) - PrefDialog2.SetOptions("Category", categories) - PrefDialog2.SetEventsListener(Me, "PrefDialog2") '<-- must add to handle events. -End Sub - -Private Sub CreateDialog3 - PrefDialog3.Initialize(Root, "Delete", 300dip, 70dip) - PrefDialog3.Theme = PrefDialog3.THEME_LIGHT - PrefDialog3.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40) - PrefDialog3.Dialog.TitleBarHeight = 50dip - PrefDialog3.Dialog.TitleBarColor = xui.Color_RGB(220, 20, 60) - PrefDialog3.AddSeparator("default") -End Sub - -Private Sub ShowDialog1 (Action As String, Item As Map) - If Action = "Add" Then - PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(50, 205, 50) - Else - PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225) - End If - PrefDialog1.Title = Action & " Category" - Dim sf As Object = PrefDialog1.ShowDialog(Item, "OK", "CANCEL") - #if B4A or B4i - PrefDialog1.Dialog.Base.Top = 100dip ' Make it lower - #Else - 'Dim sp As ScrollPane = PrefDialog1.CustomListView1.sv - 'sp.SetVScrollVisibility("NEVER") - Sleep(0) - PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip - #End If - ' Fix Linux UI (Long Text Button) - Dim btnCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel) - btnCancel.Width = btnCancel.Width + 20dip - btnCancel.Left = btnCancel.Left - 20dip - btnCancel.TextColor = xui.Color_Red - Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive) - btnOk.Left = btnOk.Left - 20dip - Wait For (sf) Complete (Result As Int) - If Result = xui.DialogResponse_Positive Then - If 0 = Item.Get("id") Then ' New row - Dim CategoryMap As Map = CreateMap("name": Item.Get("Category Name")) - Dim sd As Object = SendData("POST", "category", CategoryMap) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - Log(Data.Get("a")) ' 201 Created - Dim l As List = Data.Get("r") - Dim m As Map = l.Get(0) - xui.MsgboxAsync("New category created!", $"ID: ${m.Get("id")}"$) - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - Return - End If - Else - Dim CategoryMap As Map = CreateMap("name": Item.Get("Category Name")) - Dim sd As Object = SendData("PUT", $"category/${Item.Get("id")}"$, CategoryMap) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - xui.MsgboxAsync("Category updated!", "Edit") - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - End If - GetCategories - Else - Return - End If -End Sub - -Private Sub ShowDialog2 (Action As String, Item As Map) - If Action = "Add" Then - PrefDialog2.Dialog.TitleBarColor = xui.Color_RGB(50, 205, 50) - Else - PrefDialog2.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225) - End If - PrefDialog2.Title = Action & " Product" - Dim sf As Object = PrefDialog2.ShowDialog(Item, "OK", "CANCEL") - Sleep(0) - PrefDialog2.CustomListView1.sv.Height = PrefDialog2.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip - Wait For (sf) Complete (Result As Int) - If Result = xui.DialogResponse_Positive Then - If 0 = Item.Get("id") Then ' New row - CategoryId = GetCategoryId(Item.Get("Category")) - Dim ProductMap As Map = CreateMap("code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price")) - Dim sd As Object = SendData("POST", $"category/${CategoryId}/product"$, ProductMap) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - 'Log(Data.Get("a")) ' 201 Created - Dim l As List = Data.Get("r") - Dim m As Map = l.Get(0) - xui.MsgboxAsync("New product created!", $"ID: ${m.Get("id")}"$) - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - Else - Dim NewCategoryId As Long = GetCategoryId(Item.Get("Category")) - Dim ProductMap As Map = CreateMap("cat_id": NewCategoryId, "code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price")) - Dim sd As Object = SendData("PUT", $"category/${CategoryId}/product/${Item.Get("id")}"$, ProductMap) - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - xui.MsgboxAsync("Product updated!", "Edit") - CategoryId = NewCategoryId - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - End If - GetProducts - Else - Return - End If -End Sub - -Private Sub PrefDialog2_BeforeDialogDisplayed (Template As Object) - Try - ' Fix Linux UI (Long Text Button) - Dim btnCancel As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Cancel) - btnCancel.Width = btnCancel.Width + 20dip - btnCancel.Left = btnCancel.Left - 20dip - btnCancel.TextColor = xui.Color_Red - Dim btnOk As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Positive) - If btnOk.IsInitialized Then - btnOk.Width = btnOk.Width + 20dip - btnOk.Left = btnCancel.Left - btnOk.Width - End If - Catch - Log(LastException) - End Try -End Sub - -Private Sub ShowDialog3 (Item As Map, Id As Long) - PrefDialog3.Title = "Delete " & Viewing - Dim sf As Object = PrefDialog3.ShowDialog(Item, "OK", "CANCEL") - #if B4A or B4i - PrefDialog3.Dialog.Base.Top = 100dip ' Make it lower - #Else - ' Fix Linux UI (Long Text Button) - 'Dim sp As ScrollPane = PrefDialog3.CustomListView1.sv - 'sp.SetVScrollVisibility("NEVER") - Sleep(0) - PrefDialog3.CustomListView1.sv.Height = PrefDialog3.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip - #End If - Dim btnCancel As B4XView = PrefDialog3.Dialog.GetButton(xui.DialogResponse_Cancel) - btnCancel.Width = btnCancel.Width + 20dip - btnCancel.Left = btnCancel.Left - 20dip - btnCancel.TextColor = xui.Color_Red - Dim btnOk As B4XView = PrefDialog3.Dialog.GetButton(xui.DialogResponse_Positive) - btnOk.Left = btnOk.Left - 20dip - PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Text = Item.Get("Item") - #if b4i - PrefDialog3.CustomListView1.GetPanel(0).GetView(0).TextSize = 16 ' Text too small in ios - #else - PrefDialog3.CustomListView1.GetPanel(0).GetView(0).TextSize = 15 ' 14 - #End If - PrefDialog3.CustomListView1.GetPanel(0).GetView(0).Color = xui.Color_Transparent - PrefDialog3.CustomListView1.sv.ScrollViewInnerPanel.Color = xui.Color_Transparent - Wait For (sf) Complete (Result As Int) - If Result = xui.DialogResponse_Positive Then - If Viewing = "Product" Then - Dim sd As Object = SendData("DELETE", $"category/${CategoryId}/product/${Id}"$, Null) - Else - Dim sd As Object = SendData("DELETE", $"category/${CategoryId}"$, Null) - End If - Wait For (sd) Complete (Data As Map) - If Data.Get("s") = "ok" Then - xui.MsgboxAsync(Viewing & " deleted!", "Delete") - Else - xui.MsgboxAsync(Data.Get("e"), "Error") - End If - Else - Return - End If - If Viewing = "Product" Then - GetProducts - Else - GetCategories - End If -End Sub - -Private Sub btnEdit_Click - Dim Index As Int = clvRecord.GetItemFromView(Sender) - Dim lst As B4XView = clvRecord.GetPanel(Index) - If Viewing = "Product" Then - If CategoryId = 0 Then Return - Dim ProductId As Long = clvRecord.GetValue(Index) - Dim pnl As B4XView = lst.GetView(0) - Dim v1 As B4XView = pnl.GetView(0) - #if b4i - Dim v2 As B4XView = pnl.GetView(1).GetView(0) ' using panel - #else - Dim v2 As B4XView = pnl.GetView(1) - #End If - Dim v3 As B4XView = pnl.GetView(2) - Dim v4 As B4XView = pnl.GetView(3) - Dim ProductMap As Map = CreateMap("Product Code": v1.Text, "Category": v2.Text, "Product Name": v3.Text, "Product Price": v4.Text.Replace(",", ""), "id": ProductId) - ShowDialog2("Edit", ProductMap) - Else - CategoryId = clvRecord.GetValue(Index) - Dim pnl As B4XView = lst.GetView(0) - Dim v1 As B4XView = pnl.GetView(0) - Dim CategoryMap As Map = CreateMap("Category Name": v1.Text, "id": CategoryId) - ShowDialog1("Edit", CategoryMap) - End If -End Sub - -Private Sub btnDelete_Click - Dim Index As Int = clvRecord.GetItemFromView(Sender) - Dim Id As Long = clvRecord.GetValue(Index) - Dim lst As B4XView = clvRecord.GetPanel(Index) - Dim pnl As B4XView = lst.GetView(0) - If Viewing = "Product" Then - If CategoryId = 0 Then Return - Dim v1 As B4XView = pnl.GetView(2) - Else - CategoryId = clvRecord.GetValue(Index) - Dim v1 As B4XView = pnl.GetView(0) - End If - Dim M1 As Map - M1.Initialize - M1.Put("Item", v1.Text) - ShowDialog3(M1, Id) -End Sub - -Sub SendData (Method As String, EndPoint As String, Payload As Map) As ResumableSub - Dim j As HttpJob - Dim Data As Map - Try - Dim Link As String = $"${URL}${EndPoint}"$ - 'Log("Link:" & Link) - indLoading.Show - j.Initialize("", Me) - Select Case Method.ToUpperCase - Case "POST" - #if b4i - j.PostString(Link, Map2JSON(Payload)) ' old version of B4i - #else - j.PostString(Link, Payload.As(JSON).ToString) - #End If - Case "PUT" - #if b4i - j.PutString(Link, Map2JSON(Payload)) ' old version of B4i - #else - j.PutString(Link, Payload.As(JSON).ToString) - #End If - Case "DELETE" - j.Delete(Link) - Case Else ' GET - j.Download(Link) - End Select - Wait For (j) JobDone(j As HttpJob) - If j.Success Then - #if b4i - Data = JSON2Map(j.GetString) ' old version of B4i - #else - Data = j.GetString.As(JSON).ToMap 'ignore - #End If - Data.Put("a", j.Response.StatusCode) - #if B4J - lblStatus.Text = "Connected to " & URL - #Else - lblStatus.Text = "Connected to " & CRLF & URL - #End If - lblStatus.TextColor = xui.Color_White - Else - If j.ErrorMessage.Contains($""s": "error""$) Then - #if b4i - Data = JSON2Map(j.ErrorMessage) ' old version of B4i - #else - Data = j.ErrorMessage.As(JSON).ToMap 'ignore - #End If - Data.Put("a", j.Response.StatusCode) - Else - Data = CreateMap("s": "error", "e": j.ErrorMessage, "m": "") - Data.Put("a", j.Response.StatusCode) - #if B4J - lblStatus.Text = "Connection to " & URL & " failed" - #Else - lblStatus.Text = "Connection failed:" & CRLF & URL - #End If - lblStatus.TextColor = xui.Color_Red - End If - End If - Catch - Log(LastException.Message) - Data = CreateMap("s": "error", "e": LastException.Message, "m": "") - Data.Put("a", 0) - lblStatus.Text = "Error: " & LastException.Message - lblStatus.TextColor = xui.Color_Red - End Try - j.Release - indLoading.Hide - Return Data -End Sub - -#if b4i -Private Sub Map2JSON (Map As Map) As String - Dim gen As JSONGenerator - gen.Initialize(Map) - Return gen.ToString -End Sub - -Private Sub JSON2Map (str As String) As Map - Dim par As JSONParser - par.Initialize(str) - Dim m As Map = par.NextObject - Dim ser As B4XSerializator - Return ser.ConvertBytesToObject(ser.ConvertObjectToBytes(m)) ' convert map to writable map in B4i -End Sub -#End If \ No newline at end of file diff --git a/WebAPIClient/B4i/Files/Special/B4X_FontAwesome.otf b/WebAPIClient/B4i/Files/Special/B4X_FontAwesome.otf deleted file mode 100644 index 401ec0f..0000000 Binary files a/WebAPIClient/B4i/Files/Special/B4X_FontAwesome.otf and /dev/null differ diff --git a/WebAPIClient/B4i/Files/Special/B4X_MaterialIcons.ttf b/WebAPIClient/B4i/Files/Special/B4X_MaterialIcons.ttf deleted file mode 100644 index 7015564..0000000 Binary files a/WebAPIClient/B4i/Files/Special/B4X_MaterialIcons.ttf and /dev/null differ diff --git a/WebAPIClient/B4i/Files/Special/icon-store-1024.png b/WebAPIClient/B4i/Files/Special/icon-store-1024.png deleted file mode 100644 index 3f0e85c..0000000 Binary files a/WebAPIClient/B4i/Files/Special/icon-store-1024.png and /dev/null differ diff --git a/WebAPIClient/B4i/Files/categoryitem.bil b/WebAPIClient/B4i/Files/categoryitem.bil deleted file mode 100644 index 22ec0d6..0000000 Binary files a/WebAPIClient/B4i/Files/categoryitem.bil and /dev/null differ diff --git a/WebAPIClient/B4i/Files/mainpage.bil b/WebAPIClient/B4i/Files/mainpage.bil deleted file mode 100644 index 45724fa..0000000 Binary files a/WebAPIClient/B4i/Files/mainpage.bil and /dev/null differ diff --git a/WebAPIClient/B4i/Files/productitem.bil b/WebAPIClient/B4i/Files/productitem.bil deleted file mode 100644 index 9dffc76..0000000 Binary files a/WebAPIClient/B4i/Files/productitem.bil and /dev/null differ diff --git a/WebAPIClient/B4i/Files/template_category.json b/WebAPIClient/B4i/Files/template_category.json deleted file mode 100644 index d19bb22..0000000 --- a/WebAPIClient/B4i/Files/template_category.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Name", - "type": "Text", - "key": "Category Name", - "required": true - } ] -} \ No newline at end of file diff --git a/WebAPIClient/B4i/Files/template_product.json b/WebAPIClient/B4i/Files/template_product.json deleted file mode 100644 index 38f29d3..0000000 --- a/WebAPIClient/B4i/Files/template_product.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "Version": 1.1, - "Theme": "Light Theme", - "Items": [ - { - "title": "Category", - "type": "Options", - "key": "Category", - "required": true - }, - { - "title": "Name", - "type": "Text", - "key": "Product Name", - "required": true - }, - { - "title": "Code", - "type": "Text", - "key": "Product Code", - "required": true - }, - { - "title": "Price", - "type": "Text", - "key": "Product Price", - "required": true - } - ] -} \ No newline at end of file diff --git a/WebAPIClient/B4i/WebAPIClient.b4i b/WebAPIClient/B4i/WebAPIClient.b4i deleted file mode 100644 index cfbc8c9..0000000 --- a/WebAPIClient/B4i/WebAPIClient.b4i +++ /dev/null @@ -1,65 +0,0 @@ -Build1=Default,b4i.webapi.client -File1=CategoryItem.bil -File2=MainPage.bil -File3=ProductItem.bil -File4=template_category.json -File5=template_product.json -FileGroup1=Default Group -FileGroup2=Default Group -FileGroup3=Default Group -FileGroup4=Default Group -FileGroup5=Default Group -Group=Default Group -Library1=b4xpages -Library2=b4xpreferencesdialog -Library3=icore -Library4=ihttputils2 -Library5=xui views -Library6=ijson -Module1=|relative|..\B4XMainPage -NumberOfFiles=5 -NumberOfLibraries=6 -NumberOfModules=1 -Version=7.2 -@EndOfDesignText@ -'Code module -#Region Project Attributes - #ApplicationLabel: WebAPI Client - #Version: 1.0.2 - 'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown - #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight - #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown - #Target: iPhone, iPad - #ATSEnabled: True - #MinVersion: 8 -#End Region -#if RELEASE - #CertificateFile: ios_distribution.cer - '#ProvisionFile: b4i_webapi_client_adhoc.mobileprovision - #ProvisionFile: distribution.mobileprovision -#Else - #CertificateFile: ios_development.cer - #ProvisionFile: development.mobileprovision -#End If -Sub Process_Globals - Public App As Application - Public NavControl As NavigationController - -End Sub - -Private Sub Application_Start (Nav As NavigationController) - NavControl = Nav - Dim PagesManager As B4XPagesManager - PagesManager.Initialize(NavControl) -End Sub - -'Template version: B4i-1.0 -#Region Delegates -Private Sub Application_Background - B4XPages.Delegate.Activity_Pause -End Sub - -Private Sub Application_Foreground - B4XPages.Delegate.Activity_Resume -End Sub -#End Region