B4A=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=9.86 @EndOfDesignText@ Sub Class_Globals Private Root As B4XView 'ignore Private xui As XUI 'ignore Dim ime As IME 'ignore ' Private lblHello As B4XView Private ImageView1 As B4XView 'ignore ' Private Page3 As B4XPage3 Private CustomListView1 As CustomListView 'ignore ' Private Tree As CLVTree ' Private b_colapsa As Button ' Private b_expande As Button ' Private Panel2 As Panel Private clv_reglas2 As CustomListView Private et_regla As EditText Private p_rules As Panel Private l_tit As Label ' Private l_rule As Label Private p_reglas As Panel Private l_tit2 As Label Private et_regla2 As EditText Private cb_activa As CheckBox Private l_regla As Label Private p_editarRegla As Panel Private et_nombre As EditText Private b_cancelar As Button Private et_entra As EditText Private et_sale As EditText Private l_sale As Label Private l_regla_1 As Label Private l_regla_2 As Label Private p_separador As Panel Private r_destinatario_p As RadioButton Private r_destinatario_g As RadioButton Private r_destinatario_a As RadioButton Dim destinatario As String = "Personas" Private l_flecha As Label Private fb_add As cvFloatingBtn Private p_msgBox As Panel Private l_msgBoxTitle As Label Private l_msgBoxText As Label Private b_msgBoxYes As Button Private b_msgBoxNo As Button Private p_sombra As Panel Private p_contestacion As Panel Private l_sale2 As Label Private et_sale2 As EditText Private p_recibimos As Panel Private l_entra As Label Private p_contactosEspecificos As Panel Private et_contEsp As EditText Private l_contEsp As Label Dim contactsPermission As Boolean = False Private clv_contactPicker As CustomListView Private PCLV As PreoptimizedCLV Private l_contact As Label Private cb_selectContact As CheckBox Private p_contacts As Panel Private p_contactPicker As Panel Dim contactosEspecificos As List Private p_conEsp As Panel Private b_guardaConEsp As Button Private et_conEsp As EditText Private et_conEsp2 As EditText Private b_getContacts As Button Dim listaReglasContestaciones As List Private b_addET As Button Private ScrollView1 As ScrollView End Sub 'You can add more parameters here. 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 'load the layout to Root Root.LoadLayout("Page2") ' Root.LoadLayout("floatbutton_layout") B4XPages.SetTitle(Me, "Reglas") ' Page3 = B4XPages.GetPage("Page 3") contactosEspecificos.Initialize PCLV.Initialize(Me, "PCLV", clv_contactPicker) PCLV_AddItems muestraReglas End Sub Private Sub B4XPage_Appear ' NotificationService.mapReglas = Subs.traeReglas ' clv_reglas2.Clear ' clv_reglas2.PressedColor = Colors.Transparent ' For Each m As Map In NotificationService.mapReglas.Values ' clv_reglas2.Add(CreateListItem(m.get("id"), m.get("nombre"), "Recibimos:", m.Get("recibe"), "Contestamos:", m.Get("contesta"), m.Get("activa"), 386dip, 90dip), m.get("id")) ' Next ' p_editarRegla.Visible = False ' p_sombra.Visible = False ' p_reglas.Width = Root.Width - 20 ' Subs.centraPanel(p_editarRegla, Root.Width) End Sub Sub clv_contactPicker_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int) For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex) Dim item As CLVItem = clv_contactPicker.GetRawListItem(i) Dim pnl As B4XView = xui.CreatePanel("") pnl.Color = Colors.White item.Color = Colors.White item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height) 'Create the item layout pnl.LoadLayout("contactItem") cb_selectContact.Tag = item.Value l_contact.Text = item.Value Next End Sub Sub PCLV_AddItems For Each contact As String In Subs.getContactos PCLV.AddItem(40dip, xui.Color_White, contact) Next PCLV.Commit End Sub 'Return the hint that will be displayed when the user fast scrolls the list. It can be a string or CSBuilder. Sub PCLV_HintRequested (Index As Int) As Object Dim word As String = clv_contactPicker.GetValue(Index) Return word End Sub Sub muestraReglas NotificationService.mapReglas = Subs.traeReglas ' Log("mapReglas=" & NotificationService.mapReglas) clv_reglas2.Clear clv_reglas2.PressedColor = Colors.Transparent ' clv_reglas2.AsView.Color = Colors.red For Each m As Map In NotificationService.mapReglas.Values clv_reglas2.Add(CreateListItem(m.get("id"), m.get("nombre"), "Recibimos:", m.Get("recibe"), "Contestamos:", m.Get("contesta"), m.Get("activa"), 386dip, 90dip), m.get("id")) Next p_editarRegla.Visible = False p_sombra.Visible = False p_reglas.Width = Root.Width - 20 p_sombra.Width = Root.Width p_sombra.Height = Root.Height Subs.centraPanel(p_editarRegla, Root.Width) Subs.centraPanel(p_sombra, Root.Width) End Sub Sub CreateListItem(id As Int, nom As String, tit As String, rule As String, tit2 As String, rule2 As String, activa As Int, Width As Int, Height As Int) As Panel Dim p As B4XView = xui.CreatePanel("") Dim active As Boolean = False ' Private pLeft = p_rules.left If activa = 1 Then active = True p.SetLayoutAnimated(0, 0, 0, Width, Height) p.LoadLayout("ruleItem") l_tit.Text = tit l_regla_1.Text = rule l_tit2.Text = tit2 l_regla_2.Text = rule2 Subs.SetButtonTintList(cb_activa, Colors.red, Colors.RGB(7, 183, 0)) If nom.IndexOf(".") > -1 Then Private cuantos As Int = Subs.CountChars(nom, ".") ' Log(cuantos) Private leftOffs As Int = 15 If cuantos > 0 Then leftOffs = leftOffs * cuantos p_rules.Left = p_rules.Left + leftOffs p_rules.Width = p_rules.Width - leftOffs l_regla_1.Width = l_regla_1.Width - leftOffs l_regla_2.Width = l_regla_2.Width - leftOffs cb_activa.Left = cb_activa.Left - leftOffs Dim cd1 As ColorDrawable cd1.Initialize2(Colors.White, 30, 5, Colors.Red) l_regla.TextColor = Colors.red ' l_flecha.TextColor = Colors.red ' p_rules.Color = Colors.RGB(209, 0, 0) p_rules.Background = cd1 If cuantos > 0 Then l_flecha.Visible = True l_regla.Left = l_regla.Left + 40 ' If cuantos = 2 Then p_rules.Color = Colors.RGB(134, 246, 126) ' If cuantos > 2 Then p_rules.Color = Colors.RGB(217, 217, 217) If cuantos = 2 Then cd1.Initialize2(Colors.White, 30, 5, Colors.Gray) l_regla.TextColor = Colors.Gray ' l_flecha.TextColor = Colors.Gray End If If cuantos = 3 Then cd1.Initialize2(Colors.White, 30, 6, Colors.RGB(255, 140, 125)) l_regla.TextColor = Colors.RGB(255, 140, 125) ' l_flecha.TextColor = Colors.RGB(255, 140, 125) End If If cuantos > 3 Then cd1.Initialize2(Colors.White, 30, 6, Colors.RGB(250, 161, 38)) l_regla.TextColor = Colors.RGB(250, 161, 38) ' l_regla.TextColor = Colors.RGB(250, 161, 38) End If p_rules.Background = cd1 End If End If Dim su As StringUtils ' recalculate new heights ' Dim prhTemp As Int = p_rules.Height l_regla_1.height = su.MeasureMultilineTextHeight(l_regla_1, l_regla_1.Text) l_regla_2.height = su.MeasureMultilineTextHeight(l_regla_2, l_regla_2.Text) p_separador.Top = l_regla_1.Top + l_regla_1.Height + 10 l_tit2.Top = p_separador.Top + 20 l_regla_2.Top = l_tit2.top p_rules.Height = l_regla_1.Height + l_regla_2.Height + 110 p.SetLayoutAnimated(0, 0, 0, Width, p_rules.Height +10) cb_activa.Checked = active cb_activa.Tag = id l_regla.Text = nom l_regla.Tag = id Return p End Sub 'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage. Sub b_1_Click ' B4XPages.ShowPage("Page 3") End Sub Sub btnSignOut_Click ' Page3.ClearImage ' UpdateImage ' B4XPages.ShowPageAndRemovePreviousPages("MainPage") End Sub Private Sub cb_activa_CheckedChange(Checked As Boolean) Dim chk As CheckBox = Sender ' if starter.showLogs then Log(Checked & " | " & chk.tag ) If chk.Tag <> Null And chk.Tag <> "" Then Dim p_regla As Panel = Sender.As(View).Parent.As(Panel) ' if starter.showLogs then Log("|"&p_regla.NumberOfViews) Private idRegla As Int = chk.tag Private activa As Boolean = Checked ' Private recibimos As String = p_regla.GetView(1).as(Label).text ' Private mandamos As String = p_regla.GetView(3).as(Label).text If Starter.showLogs Then Log("|"&p_regla.GetView(5)) Subs.guardaRegla(idRegla, activa) NotificationService.mapReglas = Subs.traeReglas End If ' Log(NotificationService.mapReglas) End Sub 'Borramos la regla. Sub cb_activa_LongClick Private chk As CheckBox = Sender If Starter.showLogs Then Log(chk.tag) p_msgBox.Top = (Root.Height/2) - (p_msgBox.Height/2) Subs.centraPanel(p_msgBox, Root.Width) l_msgBoxTitle.Text = "Borrar regla" l_msgBoxText.text = $"¿Seguro que desea borrar la regla ${chk.tag}?"$ p_msgBox.Visible = True b_msgBoxYes.Tag = chk.tag p_msgBox.Tag = clv_reglas2.GetItemFromView(Sender.As(View)) If Starter.showLogs Then LogColor(p_msgBox.tag, Colors.Magenta) ' if starter.showLogs then LogColor(clv_reglas2.Size,Colors.Magenta) End Sub Private Sub b_msgBoxYes_Click p_msgBox.Visible = False If Starter.showLogs Then Log(Sender.As(Button).tag) Subs.borrarRegla(Sender.As(Button).tag) NotificationService.mapReglas = Subs.traeReglas ' B4XPage_Appear clv_reglas2.RemoveAt(p_msgBox.Tag) ' muestraReglas End Sub Private Sub b_msgBoxNo_Click p_msgBox.Visible = False End Sub Sub p_msgBox_Click 'Do nothing End Sub Private Sub et_regla_TextChanged (Old As String, New As String) Dim p_regla As Panel = Sender.As(View).Parent.As(Panel) Private cb As CheckBox = p_regla.GetView(2) cb.Checked = False ' Log(cb.checked) End Sub Private Sub et_regla2_TextChanged (Old As String, New As String) Dim p_regla As Panel = Sender.As(View).Parent.As(Panel) Private cb As CheckBox = p_regla.GetView(2) cb.Checked = False ' Log(cb.checked) End Sub Private Sub L_regla_LongClick ' et_nombre.Text = Sender.As(Label).text ' et_nombre.Tag = Sender.As(Label).tag ' Log(Sender.As(Label)) '' Log(Sender.As(Label).Tag & "|"&NotificationService.mapReglas) ' Private d As Map = NotificationService.mapReglas.Get(Sender.As(Label).tag) '' Log(d) ' et_entra.Text = d.Get("recibe") ' et_sale.Text = d.Get("contesta") ' p_editarRegla.visible = True ' RecalculateHeightViews End Sub Private Sub b_guardar_Click For i = 0 To listaReglasContestaciones.Size -1 et_sale.Text = et_sale.Text & "//" & listaReglasContestaciones.Get(i).As(EditText).text Next if starter.showLogs then Log(et_sale.text) Subs.actualizaRegla(et_nombre.Tag, et_nombre.text, et_entra.Text, et_sale.text, r_destinatario_p.tag, et_contEsp.text) ' NotificationService.mapReglas = Subs.traeReglas muestraReglas p_editarRegla.Visible = False p_sombra.Visible = False ime.HideKeyboard End Sub Private Sub b_cancelar_Click p_editarRegla.Visible = False p_editarRegla.SendToBack ' ScrollView1.Visible = False p_sombra.Visible = False ime.HideKeyboard End Sub Sub RecalculateHeightViews ' Log("Recalcula") Dim su As StringUtils 'Recalculate new heights et_entra.height = su.MeasureMultilineTextHeight(et_entra, et_entra.Text) + 60 et_sale.height = su.MeasureMultilineTextHeight(et_sale, et_sale.Text)+ 60 et_contEsp.Height = su.MeasureMultilineTextHeight(et_contEsp, et_contEsp.Text)+ 60 p_recibimos.Height = et_entra.Height + 20 p_contestacion.Height = et_sale.Height + 20 p_contactosEspecificos.Height = et_contEsp.Height + 20 ' Recalculate new vertical positions p_recibimos.Top =l_entra.Top + l_entra.Height + 5 l_sale.Top = p_recibimos.Top + p_recibimos.height + 5 p_contestacion.Top = l_sale.Top + l_sale.height + 5 If listaReglasContestaciones.Size > 0 Then For j = 0 To listaReglasContestaciones.Size - 1 listaReglasContestaciones.Get(j).As(EditText).Height = su.MeasureMultilineTextHeight(listaReglasContestaciones.Get(j).As(EditText), listaReglasContestaciones.Get(j).As(EditText).Text) + 60 p_contestacion.Height = p_contestacion.Height + listaReglasContestaciones.Get(j).As(EditText).Height - 15 Next End If ScrollView1.Panel.Height = p_recibimos.Height + p_contestacion.Height + p_contactosEspecificos.Height + 500 For n = 0 To listaReglasContestaciones.Size - 1 If n = 0 Then listaReglasContestaciones.Get(n).As(EditText).Top = et_sale.Top + et_sale.Height - 15 Else if n > 0 Then listaReglasContestaciones.Get(n).As(EditText).Top = listaReglasContestaciones.Get(n-1).As(EditText).Top + listaReglasContestaciones.Get(n-1).As(EditText).Height - 15 End If ' LogColor(listaReglasContestaciones.Get(n).As(EditText).Top, Colors.red) Next r_destinatario_p.Top = p_contestacion.Top + p_contestacion.Height r_destinatario_g.Top = r_destinatario_p.top r_destinatario_a.Top = r_destinatario_p.top l_contEsp.Top = r_destinatario_p.Top + r_destinatario_p.Height b_addET.Top = l_sale.top - 1 b_getContacts.Top = l_contEsp.top - 5 p_contactosEspecificos.Top = l_contEsp.Top + l_contEsp.Height End Sub Private Sub et_entra_TextChanged (Old As String, New As String) RecalculateHeightViews End Sub Private Sub et_sale_TextChanged (Old As String, New As String) RecalculateHeightViews End Sub Private Sub et_sale2_TextChanged (Old As String, New As String) RecalculateHeightViews End Sub Private Sub et_contEsp_TextChanged (Old As String, New As String) RecalculateHeightViews End Sub Private Sub clv_reglas2_ItemClick (Index As Int, Value As Object) If Starter.showLogs Then Log(Index &"|" & Value) listaReglasContestaciones.Initialize ' p_editarRegla.Visible = True ' p_editarRegla.BringToFront ScrollView1.Panel.RemoveAllViews ScrollView1.Panel.LoadLayout("editaRegla") ScrollView1.Height = p_editarRegla.Height * 0.9 ScrollView1.Panel.Height = ScrollView1.Height Private et_sale As EditText et_sale.Initialize("et_sale") et_sale.TextColor = Colors.Black et_sale.TextSize = 12 p_contestacion.RemoveAllViews p_contestacion.AddView(et_sale, 10, 10, (p_contestacion.Width*0.95), 30dip) Private d As Map = NotificationService.mapReglas.Get(Value) If Starter.showLogs Then Log(d) et_entra.InputType = Bit.Or(0x00080000, 0x00000090) 'TYPE_TEXT_FLAG_NO_SUGGESTIONS | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD et_entra.SingleLine = False et_sale.InputType = Bit.Or(0x00080000, 0x00000090) 'TYPE_TEXT_FLAG_NO_SUGGESTIONS | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD et_sale.SingleLine = False et_contEsp.InputType = Bit.Or(0x00080000, 0x00000090) 'TYPE_TEXT_FLAG_NO_SUGGESTIONS | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD et_contEsp.SingleLine = False et_nombre.Tag = Value et_nombre.Text = d.Get("nombre") et_entra.Text = d.Get("recibe") Private ets() As String = Regex.Split("//", d.Get("contesta")) 'Dividimos el regla en sus multiples respuestas. ' et_sale.Text = d.Get("contesta") et_sale.Text = ets(0).trim If ets.Length > 1 Then For x = 1 To ets.Length - 1 addET(ets(x).Trim) Next End If destinatario = "Personas" If d.Get("destinatario") <> Null Then destinatario = d.Get("destinatario") If destinatario = "Personas" Then r_destinatario_p.Checked = True If destinatario = "Grupos" Then r_destinatario_g.Checked = True If destinatario = "Ambos" Then r_destinatario_a.Checked = True et_contEsp.Text = d.Get("contactoEspecifico") r_destinatario_p.Tag = destinatario p_editarRegla.visible = True p_sombra.Visible = True If Starter.showLogs Then Log(contactsPermission) ' If contactsPermission Then ' Dim res As List = InputMultiList(Subs.getContactos, "Select") ' Log(res) ' End If RecalculateHeightViews End Sub Private Sub r_destinatario_p_CheckedChange(Checked As Boolean) If Starter.showLogs Then Log(Sender.As(RadioButton).text & "|" &Checked) destinatario = Sender.As(RadioButton).text r_destinatario_p.Tag = destinatario End Sub Private Sub r_destinatario_g_CheckedChange(Checked As Boolean) If Starter.showLogs Then Log(Sender.As(RadioButton).text & "|" &Checked) destinatario = Sender.As(RadioButton).text r_destinatario_p.Tag = destinatario End Sub Private Sub r_destinatario_a_CheckedChange(Checked As Boolean) ' Log(Sender.As(RadioButton).text & "|" &Checked) destinatario = Sender.As(RadioButton).text r_destinatario_p.Tag = destinatario End Sub 'Agregamos regla. Sub fb_add_Clicked(X As Float,Y As Float) ' ToastMessageShow("Button Clicked",False) Subs.agregaRegla NotificationService.mapReglas = Subs.traeReglas ' B4XPage_Appear muestraReglas End Sub Private Sub B4XPage_CloseRequest As ResumableSub Sleep(0) If Starter.showLogs Then Log("B4XPage_CloseRequest") ' if starter.showLogs then Log(p_contactPicker.Visible) If p_contactPicker.Visible = True Then p_contactPicker.Visible = False Return False End If If p_editarRegla.Visible Then p_editarRegla.Visible = False p_sombra.Visible = False Return False End If Return True End Sub Private Sub p_editarRegla_Click 'Nothing here. End Sub Private Sub p_sombra_Click 'Nothing here. End Sub Sub muestraContactos If Starter.showLogs Then Log("muestraContactos") p_contactPicker.Visible = True ime.HideKeyboard p_contactPicker.left = 0 p_contactPicker.Top = 0 p_contactPicker.Width = Root.Width p_contactPicker.Height = Root.Height clv_contactPicker.GetBase.SetLayoutAnimated(0, 5dip, 30dip, Root.Width - 10, Root.Height * 0.68) 'Cambiamos el tamaño y posición de la lista de productos clv_contactPicker.Base_Resize(clv_contactPicker.GetBase.Width, clv_contactPicker.GetBase.Height) 'Cambiamos el tamaño del panel interno de la lista para que ajuste al nuevo tamaño. p_conEsp.Top = clv_contactPicker.GetBase.Top + clv_contactPicker.GetBase.Height + 20 b_guardaConEsp.top = p_conEsp.Top + p_conEsp.Height + 20 End Sub Sub CreateContactsItem(nom As String, Width As Int, Height As Int) As Panel 'ignore Dim p As B4XView = xui.CreatePanel("") p.SetLayoutAnimated(0, 0, 0, Width, Height) p.LoadLayout("contactItem") l_contact.Text = nom p_contacts.Height = Height ' Log($"${p_contacts.Height}, ${l_contact.Height}"$) cb_selectContact.Top = (p_contacts.Height/2) - (cb_selectContact.Height/2) l_contact.Top = (p_contacts.Height/2) - (l_contact.Height/2) Subs.SetButtonTintList(cb_selectContact, Colors.red, Colors.RGB(7, 183, 0)) cb_selectContact.Tag = nom l_contact.Text = nom Return p End Sub Private Sub clv_contactPicker_ItemClick (Index As Int, Value As Object) ' Log($"${Index}, ${Value}"$ ) Dim cb As CheckBox = clv_contactPicker.GetPanel(Index).GetView(0).GetView(0) If cb.Checked Then cb.Checked = False Else cb.Checked = True End Sub Private Sub et_contEsp_FocusChanged (HasFocus As Boolean) ' If HasFocus Then ' muestraContactos ' End If End Sub Private Sub cb_selectContact_CheckedChange(Checked As Boolean) if starter.showLogs then Log(Sender.As(CheckBox).tag) et_conEsp2.Text = "" If Checked Then contactosEspecificos.Add(Sender.As(CheckBox).tag) 'Si no está en la lista, lo agregamos. Else If contactosEspecificos.IndexOf(Sender.As(CheckBox).tag) > -1 Then contactosEspecificos.RemoveAt(contactosEspecificos.IndexOf(Sender.As(CheckBox).tag)) 'Si ya esta en la lista lo quitamos. End If End If ' if starter.showLogs then Log(contactosEspecificos) For Each c In contactosEspecificos If et_conEsp2.Text <> "" Then et_conEsp2.Text = et_conEsp2.Text & ", " & c Else et_conEsp2.Text = c Next End Sub Private Sub b_guardaConEsp_Click Dim l As List l.initialize Dim t() As String = Regex.Split(",", et_contEsp.text) For i = 0 To t.Length-1 l.add(t(i).trim) Next contactosEspecificos.AddAll(l) contactosEspecificos = Subs.removeListDuplicates(contactosEspecificos) et_contEsp.Text = "" For Each c In contactosEspecificos If et_contEsp.Text <> "" Then et_contEsp.Text = et_contEsp.Text & ", " & c Else et_contEsp.Text = c Next et_contEsp.text = et_contEsp.text.Replace(", ,", ",") p_contactPicker.Visible = False et_conEsp2.Text = "" contactosEspecificos.Clear clv_contactPicker.Clear PCLV_AddItems End Sub Private Sub b_getContacts_Click muestraContactos End Sub Sub addET(texto As String) Dim etX As EditText etX.Initialize("etX") etX.TextColor = Colors.Black etX.TextSize = 12 etX.Tag = listaReglasContestaciones.size listaReglasContestaciones.add(etX) Dim newTop As Int = et_sale.top + et_sale.Height If listaReglasContestaciones.Size > 0 Then For k = 0 To listaReglasContestaciones.Size - 1 newTop = newTop + listaReglasContestaciones.Get(k).As(EditText).Height Next End If p_contestacion.AddView(etX, et_sale.left, newTop, et_sale.Width, 35dip) etX.Text = texto End Sub Private Sub b_addET_Click addET("") ' Log("Agregamos ET, " & listaReglasContestaciones.size & "|" & etX.Tag & ", top=" & newTop) RecalculateHeightViews ' Log(etX.top) End Sub Sub etX_TextChanged (Old As String, New As String) ' Log(Sender.As(EditText).tag) RecalculateHeightViews End Sub