B4J Question B4XPreferencesDialog - Today button

aeric

Expert
Licensed User
Longtime User
B4X:
'Same as ShowDialog but DateTemplate shows TODAY button
'Example:<code>
'Dim Data As Map = CreateMap()
'Wait For (Preferences.ShowDialog2(Data, "OK", "CANCEL")) Complete (Result As Int)
'If Result = xui.DialogResponse_Positive Then
'
'End If</code>
Public Sub ShowDialog2 (Data As Map, Yes As Object, Cancel As Object) As ResumableSub
    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf
            End If
        Next
        #if B4A
        'this sets ForceDone to True.
        If LastTextField.IsInitialized Then LastTextField.NextField = LastTextField
        #end if
      
        Dialog.InternalAddStubToCLVIfNeeded(CustomListView1, CustomListView1.DefaultTextBackgroundColor)
    End If
    FillData (Data)
    Dim ScrollViewOffset As Int 'ignore
    Do While True
        Dialog.Title = mTitle
        Dialog.PutAtTop = xui.IsB4A Or xui.IsB4i
        Dim rs As Object = Dialog.ShowTemplate(Me, Yes, "", Cancel) 
        #if B4A
        If ScrollViewOffset > 0 Then
            Sleep(50)
            Dim sv As ScrollView = CustomListView1.sv
            sv.ScrollToNow(ScrollViewOffset)
        End If
        #End If
        RaiseBeforeDialogDisplayed(Me)
        Wait For (rs) Complete (Result As Int)
        ScrollViewOffset = CustomListView1.sv.ScrollViewOffsetY
        If Result <> RESULT_SHOWING_NESTED_DIALOG Then
            If Result = xui.DialogResponse_Positive Then
                If CommitChanges(Data) = False Then
                    ScrollViewOffset = 0
                    Continue
                End If
            End If
            Return Result
        Else
            Dim y As Object
            Dim c As Object = Cancel
            If Template = ColorTemplate Then
                y = Yes
            Else If Template = LongTextTemplate Then
                y = Yes
                c = ""
            Else
                y = ""
            End If
            Dialog.PutAtTop = xui.IsB4A Or xui.IsB4i         
            If Template = DateTemplate Then
                Dim rs As Object = Dialog.ShowTemplate(Template, "", "TODAY", c)
            Else
                Dim rs As Object = Dialog.ShowTemplate(Template, y, "", c)
            End If         
            RaiseBeforeDialogDisplayed(Template)
            Wait For (rs) Complete (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Dim lbl As B4XView = CustomListView1.GetPanel(NestedDialogItemIndex).GetView(1)
                Dim value As String
                If Template = DateTemplate Then
                    value = DateTime.Date(DateTemplate.Date)
                    lbl.Text = value
                Else if Template = SearchTemplate Then
                    value = SearchTemplate.SelectedItem
                    lbl.Text = value
                Else If Template = ColorTemplate Then
                    value = ColorTemplate.SelectedColor
                    SetLabelColor(lbl, value)
                End If
            Else If Result = xui.DialogResponse_Negative Then
                Dim lbl As B4XView = CustomListView1.GetPanel(NestedDialogItemIndex).GetView(1)
                If Template = DateTemplate Then
                    'Log(DateTime.Date(DateTime.Now))
                    lbl.Text = DateTime.Date(DateTime.Now)
                End If
            End If
        End If
    Loop
    Return -1 'never happens
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
B4X:
'Same as ShowDialog but DateTemplate shows Today button
'Example:<code>
'Dim Data As Map = CreateMap()
'Wait For (Preferences.ShowDialog2(Data, "OK", "CANCEL")) Complete (Result As Int)
'If Result = xui.DialogResponse_Positive Then
'
'End If</code>
Public Sub ShowDialog2 (Data As Map, Yes As Object, Cancel As Object) As ResumableSub
    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf
            End If
        Next
        #if B4A
        'this sets ForceDone to True.
        If LastTextField.IsInitialized Then LastTextField.NextField = LastTextField
        #end if
       
        Dialog.InternalAddStubToCLVIfNeeded(CustomListView1, CustomListView1.DefaultTextBackgroundColor)
    End If
    FillData (Data)
    Dim ScrollViewOffset As Int 'ignore
    Do While True
        Dialog.Title = mTitle
        Dialog.PutAtTop = xui.IsB4A Or xui.IsB4i
        Dim rs As Object = Dialog.ShowTemplate(Me, Yes, "", Cancel)  
        #if B4A
        If ScrollViewOffset > 0 Then
            Sleep(50)
            Dim sv As ScrollView = CustomListView1.sv
            sv.ScrollToNow(ScrollViewOffset)
        End If
        #End If
        RaiseBeforeDialogDisplayed(Me)
        Wait For (rs) Complete (Result As Int)
        ScrollViewOffset = CustomListView1.sv.ScrollViewOffsetY
        If Result <> RESULT_SHOWING_NESTED_DIALOG Then
            If Result = xui.DialogResponse_Positive Then
                If CommitChanges(Data) = False Then
                    ScrollViewOffset = 0
                    Continue
                End If
            End If
            Return Result
        Else
            Dim y As Object
            Dim n As Object = ""
            Dim c As Object = Cancel
            If Template = ColorTemplate Then
                y = Yes
            Else If Template = LongTextTemplate Then
                y = Yes
                c = ""
            Else If Template = DateTemplate Then
                y = ""
                n = "TODAY"
            Else
                y = ""
            End If
            Dialog.PutAtTop = xui.IsB4A Or xui.IsB4i
            Dim rs As Object = Dialog.ShowTemplate(Template, y, n, c)      
            RaiseBeforeDialogDisplayed(Template)
            Wait For (rs) Complete (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Dim lbl As B4XView = CustomListView1.GetPanel(NestedDialogItemIndex).GetView(1)
                Dim value As String
                If Template = DateTemplate Then
                    value = DateTime.Date(DateTemplate.Date)
                    lbl.Text = value
                Else if Template = SearchTemplate Then
                    value = SearchTemplate.SelectedItem
                    lbl.Text = value
                Else If Template = ColorTemplate Then
                    value = ColorTemplate.SelectedColor
                    SetLabelColor(lbl, value)
                End If
            Else If Result = xui.DialogResponse_Negative Then
                Dim lbl As B4XView = CustomListView1.GetPanel(NestedDialogItemIndex).GetView(1)
                If Template = DateTemplate Then
                    'Log(DateTime.Date(DateTime.Now))
                    lbl.Text = DateTime.Date(DateTime.Now)
                End If
            End If
        End If
    Loop
    Return -1 'never happens
End Sub
 
Upvote 0
Top