Android Question XUIViews: B4XDialog + B4XDateTemplate enable only a few days interval

AscySoft

Active Member
Licensed User
Longtime User
Hi, I reecently switched to B4XDateTemplate in XUIViews as the older datepicker I used no longer working with B4A10.7
Now, one silly question is how can I prevent users to select a date wich is not allowed by default? I need to limit each user to allow only from a limited number of days to be picked.
I realized that a min/max year properties are available in B4XDateTemplate, is there a similar way to set a min/max Days with this dialog?
 

josejad

Expert
Licensed User
Longtime User
Hi:

Based on this answer, your best options are:
- Use Pref_IsValid and return false and a message saying the valid dates.
- The other option is to create a modified B4XDateTemplate (with a different name) and modify B4XPreferencesDialog to use it.
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
Use Pref_IsValid
Sorry, I don't have any "isValid" event, I switched to B4Xdialog inside XUI Views. There is no " B4XPreferencesDialog" inside this library, but B4XDialog and B4XDateTemplate are.
I know I can check the "Date" value returned by B4XDateTemplate object, and discard it if is not between a min and a max day. Then start again. But I just need a GUI limitation similar to @DonManfred "DateTimePicker" wich no longer work in B4A 10.7
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
There is no " B4XPreferencesDialog" inside this library, but B4XDialog and B4XDateTemplate are.
B4XPreferencesDialog is a library of its own. It is not part of XUI Views lib. Here is the link that has 3 projects , one for each platform. You just need to check the library in the lib pane because it is an internal lib.
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
It is not part of XUI Views lib
Yes sir, exactly my point! I am trying to replace an obsolete datepicker not with B4XpreferenceDialog + B4XDateTemplate (wich also require XUIViews) but with XUIViews.B4XDialog + B4XDateTemplate.
So I do not want a preferenceDialog, but only B4XDialog inside XUIViews. I hope now is clear for everyone, (my bad for not explained it propperly)
Code is here https://www.b4x.com/android/forum/threads/b4x-light-theme-b4xdatetemplate.111837/#content
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Sorry, you’re right, I thougth you were using B4XPrefDialog
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Full example:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private dialog As B4XDialog
    Private DateTemplate As B4XDateTemplate
End Sub

Public Sub Initialize
    
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")
    dialog.Initialize(Root)
    DateTemplate.Initialize
    SetDialogTheme
End Sub

Sub Button2_Click
    Wait For (GetDate(10)) Complete (Ticks As Long)
    If Ticks > 0 Then
        Log($"Selected date: $Date{Ticks}"$)
    End If
End Sub

Private Sub GetDate(MaxIntervalInDays As Int) As ResumableSub
    Do While True
        Wait For (dialog.ShowTemplate(DateTemplate, "", "", "Cancel")) Complete (Result As Int)
        Dim zero As Long = 0 'type must be exact
        If Result = xui.DialogResponse_Cancel Then Return zero
        Dim days As Int = DateUtils.PeriodBetweenInDays(DateTime.Now, DateTemplate.Date).Days
        If Abs(days) > MaxIntervalInDays Then
            DateTemplate.Date = DateTime.Now
            Wait For (dialog.Show("Invalid date", "Ok", "", "")) Complete (Result As Int)
        Else
            Return DateTemplate.Date
        End If
    Loop
    Return 0
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    If dialog.Visible Then
        dialog.Close(xui.DialogResponse_Cancel)
        Return False
    End If
    Return True
End Sub

Private Sub SetDialogTheme
    dialog.OverlayColor = xui.Color_Transparent
    dialog.TitleBarColor = 0xFF0A0B37 'Hintergrundfarbe der Titelzeile: dunkelblau
    dialog.TitleBarTextColor = 0xFFFFBD59
    dialog.ButtonsColor = 0xFF0A0B37 'Hintergrundfarbe der Buttons einstellen: dunkelblau
    dialog.ButtonsTextColor = 0xFFFFBD59 'Farbe des Buttons einstellen: Gold
    dialog.BackgroundColor = 0xFF0A0B37 'Hintergrundfarbe der Templates einstellen: dunkelblau
    DateTemplate.SelectedColor = 0xFFFFBD59 'Goldene Farbe von Buttons und co
    DateTemplate.DaysInMonthColor = xui.Color_White 'Schriftfarbe der Monate weiß
    DateTemplate.DaysInWeekColor = xui.Color_White 'Schriftfarbe der Tage weiß
    DateTemplate.lblMonth.TextColor = xui.Color_White 'Schriftfarbe der Monatsauswahl weiß
    DateTemplate.lblYear.TextColor = xui.Color_White 'Schriftfarbe der Jahresauswahl weiß
    For Each x As B4XView In Array(DateTemplate.btnMonthLeft, DateTemplate.btnMonthRight, DateTemplate.btnYearLeft, DateTemplate.btnYearRight)
        x.Color = xui.Color_Transparent
        x.TextColor = xui.Color_White
    Next
End Sub
Theme based on: https://www.b4x.com/android/forum/t...log-templates-theming-code.131243/post-826602
 
Upvote 0
Top