Android Question B4XPages] jRDC2

Timm

Member

Hello, thank you for your great job. Please can you implement clv with jrdc(instead of static listview) to populate the drawer item. Please i want such code idea Thanks

 

aeric

Expert
Licensed User
Longtime User
Something like this?

1610436359616-png.106033


B4X:
Sub LoadSlideMenu
    CLVL.Clear
    If Main.gLogin = 0 Then
        CLVL.Add(CreateMenu(Chr(0xF090), "Log in"), "Log in")
        CLVL.Add(CreateMenu(Chr(0xF234), "Register"), "Register")
    Else
        CLVL.Add(CreateMenu(Chr(0xF05A), "About Me"), "About Me")
        CLVL.Add(CreateMenu(Chr(0xF013), "Change Password"), "Change Password")
        CLVL.Add(CreateMenu(Chr(0xF08B), "Log out"), "Log out")
    End If
End Sub

Private Sub CreateMenu (MenuIcon As String, MenuText As String) As B4XView
    Dim Height As Int = 60dip
    Dim Width As Int = CLVL.AsView.Width
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("MenuItem")
    lblMenuIcon.Text = MenuIcon
    lblMenuText.Text = MenuText
    Return p
End Sub

The example project is quite old but you can use it as a reference.

 
Upvote 0

Timm

Member
Thank you very much for your time. Am sorry, this is static drawer population I still desire it to come from jrdc that is, from mysql. Thanks
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think in most cases the menu is fixed.

Why we need to load the items from a database?

I am not saying it is impossible or difficult to do.

Just not make sense to me in term of design.

If I am free later, I could write an example for you.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
MySQL:
CREATE TABLE `menus` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `menu` varchar(50) NOT NULL,
  `islogin` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `menus` (`id`, `menu`, `islogin`) VALUES
(1,    'Log in',    0),
(2,    'Register',    0),
(3,    'About Me',    1),
(4,    'Change Password',    1),
(5,    'Log out',    1);

Add the query to jRDC2 config.properties
config.properties:
sql.getMenus= SELECT menu FROM B4X.menus WHERE islogin = ?

Client app
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Drawer.Initialize(Me, "Drawer", Root, 400dip)
    Drawer.LeftPanel.LoadLayout("LeftMenu")
    LoadSlideMenu(1)
End Sub

Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, Main.rdcLink)
    Return req
End Sub

Sub CreateCommand (Name As String, Parameters() As Object) As DBCommand
    Dim command As DBCommand
    command.Initialize
    command.Name = Name
    If Parameters <> Null Then command.Parameters = Parameters
    Return command
End Sub

Private Sub CreateMenu(MenuText As String) As B4XView
    Dim Height As Int = 60dip
    Dim Width As Int = clvLeftMenu.AsView.Width
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("MenuItem")
    lblMenu.Text = MenuText
    Return p
End Sub

Sub LoadSlideMenu (isLogin As Int)
    Dim req As DBRequestManager = CreateRequest
    Dim com As DBCommand = CreateCommand("getMenus", Array As Object(isLogin))
    Wait For (req.ExecuteQuery(com, 0, Null)) JobDone (job As HttpJob)
    If job.Success Then
        req.HandleJobAsync(job, "req")
        Wait For (req) req_Result (res As DBResult)
        'req.PrintTable(res)
        clvLeftMenu.Clear
        For Each row() As Object In res.Rows
            clvLeftMenu.Add(CreateMenu(row(0)), row(0))
        Next
    Else
        xui.MsgboxAsync(job.ErrorMessage, "Error")
    End If
    job.Release
    Log("Left Menu populated")
End Sub

Private Sub clvLeftMenu_ItemClick (Index As Int, Value As Object)
    Log(Value)
End Sub

1714839272626.png
 

Attachments

  • Menu.zip
    17.6 KB · Views: 89
Upvote 0

Timm

Member
Sorry the below error pop up when compiling in debug mode
 

Attachments

  • Screenshot_20240508-095123.png
    Screenshot_20240508-095123.png
    110.4 KB · Views: 53
Upvote 0

Timm

Member
I want to achieve the menuitem as above on the drawer but have nothing at all except the curly brazes,( please don't mind the test labels).
I want to achieve it inside Josejar crud+login code as below
 
Upvote 0

Timm

Member
Drawer menuitems from jrdc:
Private Sub CreateSideMenu(MenuText As Object) As B4XView
    Dim Height As Int = 60dip
    Dim Width As Int = clvLeftMenu.AsView.Width
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("MenuItemm")
    lblMenu.Text = MenuText
    Return p
End Sub

Sub LoadSlideMenu (isLogin As Int)
    clvLeftMenu.Clear
    Dim rs As DBResult
    '    B4XLoadingIndicator1.Show
    Dim Paremeters() As String = Array As String(isLogin) ', B4XPages.MainPage.KVS.Get("id_user"))
    Wait For(B4XPages.MainPage.jRDC.GetRecord("getMenus", Paremeters)) Complete (Answer As Map)
    If Answer.Get("Success") Then
        Dim mapData As Map
        '        Log(Answer)
        rs = Answer.Get("Data")
        Log(rs)
        For Each row() As Object In rs.Rows
'            Dim i As Int = 0
            mapData.Initialize
            '            For Each record As Object In row
            '                'We will make a map to pass to B4XPreferencesDialo. The map keys must suit to the db name fields
            '                'Construimos un mapa para pasarlo a B4XPreferencesDialog. Las claves del mapa deben coincidir con los nombres de las columnas de la bd
            '                mapData.Put(rs.Columns.GetKeyAt(i), record)
            '                i = i + 1
            '            Next
            Dim p As B4XView = CreateSideMenu(mapData)
            clvLeftMenu.Add(p, mapData)
            Log(p)
        Next
    Else
        xui.MsgboxAsync("There was an error getting the data. Check your server: " & Answer.Get("Error"), "Error")
        Log("No data")   
    End If
'    Answer.Release
    Log("Left Menu populated")
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Your question is about Map.
You need to know row() is an array of object.
For menu, usually it is simple that you don't need to use Map.
Otherwise, you need to let us know how you want to build the menu.
Do you want to add fontawesome beside the label and return different value from the label?
You can add more columns to the table.
In the query, select the columns you want.
jRDC2 should return the item array according to the order.
Then construct the Map with key and value.
 
Upvote 0

Timm

Member
Thank you for your reply, yes I want to implement the kind of authorized menu for different users( like web menu coming from the server). I want to have edit and delete font awesome icon beside each drawer menuitems
 
Upvote 0

Timm

Member
But be integrated to josejad crud code since I have tried to understand the rest of the code how they fetch from the server. Thanks
 
Upvote 0
Top