Wish Adapt B4XPreferences Forms to load into a B4XPage instead into a Dialog

josejad

Expert
Licensed User
Longtime User
Hi:

Just thinking, it could be interesting to create the form with the form builder and load it in a B4XPage instead of a dialog. Then you could have a form B4XPage and call it with different forms when you need it.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I thought to experiment with this idea. It works pretty well with the standard B4XPreferenceDialog.
It was possible to hide the dialog completely and make the form respond to the B4XPAge_CloseRequest, instead of OK.

Before closing, the validity of answers can be checked and if not valid the dialog shows again without closing the form.

Screenshot.png


B4X:
'B4XMainPage
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dim ex1 As ExampleForm
    ex1.Initialize
    B4XPages.AddPageAndCreate("ex1", ex1)
    Sleep(0)
    B4XPages.ShowPage("ex1")
End Sub

'Example Form
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private prefdialog As PreferencesDialog
    Public AllData As Map
    Private pdia As Object
End Sub

Public Sub Initialize As Object
    Return Me
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    prefdialog.Initialize(Root, "", 500, 300)
    prefdialog.CustomListView1.sv.As(ScrollPane).SetVScrollVisibility("NEVER")
    prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "example1.json"))
    prefdialog.Dialog.BorderWidth = 0
    prefdialog.SeparatorBackgroundColor = xui.Color_Transparent
End Sub

Private Sub B4XPage_Appear
    AllData = CreateMap()
    pdia = prefdialog.ShowDialog(AllData, "", "")
    prefdialog.CustomListView1.sv.ScrollViewInnerPanel.Color = xui.Color_Transparent
    For i = 0 To prefdialog.CustomListView1.Size - 1
        Dim pnl As B4XView = prefdialog.CustomListView1.GetPanel(i)
        For j = 0 To pnl.NumberOfViews - 1
            Dim bv As B4XView = pnl.GetView(j)
            If bv Is Label Then
                If bv.text = "*" Then
                    bv.Width = 50
                    bv.TextColor = xui.Color_Red
                    bv.Text = "Required!"
                End If
            End If
        Next
    Next
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    prefdialog.Dialog.Close(xui.DialogResponse_Positive)
    Wait For (pdia) Complete (Result As Int)
    Dim isValid As Boolean = True
    For Each kw As String In AllData.Keys
        Log(kw & TAB & AllData.Get(kw))         'proceed    False,     today    1674622800000
    Next
    If isValid Then
        Return True
    Else
        B4XPage_Appear
        Return False
    End If
End Sub
 

Attachments

  • PrefForms.zip
    32.8 KB · Views: 150

josejad

Expert
Licensed User
Longtime User
That's great!
What about attach the B4XPreferenceDialog views to the panel of the B4XPage in order to get the form full screen? Or it would be easier initializing the B4XPreferenceDialog to the same heigth and width of the screen?
 

William Lancee

Well-Known Member
Licensed User
Longtime User
A combination of the two works. Easy enough to try various things.
I have attached the .zip to #2

B4X:
    Dim pnl As B4XView = xui.CreatePanel("")
    Root.AddView(pnl, 100, 200, 400, 400)
    prefdialog.Initialize(pnl, "", 400, 400)
 

josejad

Expert
Licensed User
Longtime User
It works.
I was thinking in phone apps, I don't use too much B4X.
What would be the equivalent to ScrollPane in this line? (I've tried with Panel, and B4XView)

B4X:
prefdialog.CustomListView1.sv.As(ScrollPane).SetVScrollVisibility("NEVER")
 

William Lancee

Well-Known Member
Licensed User
Longtime User
In B4A comment out that line. I don't know offhand how to make the scrollbar disappear in B4A.
You could probably hide it with a superimposed skinny panel. Let me know if you succeed.

I would try it but my tablet wasn't plugged in, and is now out of juice.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Just tested it and the scrollbar doesn't show in B4A if the CLV in not overflowing.
I noticed that you may need to change the fontsize or the label height of the 'required' field.

B4X:
#If B4J
    prefdialog.CustomListView1.sv.As(ScrollPane).SetVScrollVisibility("NEVER")
#End If
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I worked on it little more. The Dark Theme required some modification. The validity checking sequence required some work.
I am close to something that others might find useful.

@José J. Aguilar should I post version 2 here or post it as a separate tutorial? It does require some instructions.
 

josejad

Expert
Licensed User
Longtime User
Hi William!

Thanks for your time and work.
Post it where you think is better. If you think it's mature, you can post in "Share my creation" or "Code Snipets" or in "Tutorials".
 
Top