mirror of
https://github.com/KeymonSoft/ReplyAutoV1---WIP.git
synced 2026-04-17 21:06:09 +00:00
410 lines
14 KiB
QBasic
410 lines
14 KiB
QBasic
B4A=true
|
|
Group=Default Group
|
|
ModulesStructureVersion=1
|
|
Type=Class
|
|
Version=9.85
|
|
@EndOfDesignText@
|
|
Sub Class_Globals
|
|
Private Root As B4XView 'ignore
|
|
Private xui As XUI 'ignore
|
|
Public c_reglas As B4XReglas
|
|
Public c_imagenes As B4XImagenes
|
|
Public Page4 As B4XPage4
|
|
Dim rp As RuntimePermissions
|
|
Dim phv As PhoneVibrate
|
|
Public manager As AdminManager
|
|
|
|
Dim reqManager As DBRequestManager
|
|
Dim cmd As DBCommand
|
|
|
|
Type lasNotis(numero As String, notif As StatusBarNotification)
|
|
|
|
' Dim rp As ReplyAuto
|
|
Private et_mensaje As EditText
|
|
Private lv_notificaciones As ListView
|
|
Private EditText1 As EditText
|
|
Private b_activo As Button
|
|
Private b_p2 As Button
|
|
Private b_respaldaBD As Button
|
|
Private b_notifAccess As Button
|
|
Dim writePermission As Boolean
|
|
|
|
' Dim Su As SuShell
|
|
' Dim Process As SuProcess
|
|
' Dim lt As List
|
|
Dim notiIcon As Bitmap
|
|
Dim OldIntent As Intent
|
|
Private b_imgWA As Button
|
|
Dim b_config As Button
|
|
Dim Timer1 As Timer
|
|
Dim interval As Int = 15
|
|
Private p_notisDisponibles As Panel
|
|
Private b_NotisDisp As Button
|
|
Private p_botones As Panel
|
|
Private b_cierra As Button
|
|
End Sub
|
|
|
|
'You can add more parameters here.
|
|
Public Sub Initialize
|
|
StartService(NotificationService)
|
|
If Not(NotificationService.notisMap2.IsInitialized) Then NotificationService.notisMap2.Initialize
|
|
#if not(DEBUG)
|
|
Starter.logger = False
|
|
#end if
|
|
End Sub
|
|
|
|
'This event will be called once, before the page becomes visible.
|
|
Private Sub B4XPage_Created (Root1 As B4XView)
|
|
Timer1.Initialize("Timer1", interval * 1000)
|
|
Timer1.Enabled = True
|
|
notiIcon = LoadBitmapResize(File.DirAssets, "chatbot7_191x191.png", 24dip, 24dip, False)
|
|
Root = Root1
|
|
'load the layout to Root
|
|
Root.LoadLayout("mainPage")
|
|
B4XPages.SetTitle(Me, "Bow 2.0")
|
|
c_reglas.Initialize
|
|
B4XPages.AddPage("Reglas", c_reglas)
|
|
c_imagenes.Initialize
|
|
B4XPages.AddPage("Imagenes", c_imagenes)
|
|
#end region
|
|
If Starter.logger Then B4XPages.GetManager.LogEvents = True
|
|
getWritePermission
|
|
getcontactsPermission
|
|
End Sub
|
|
|
|
Sub b4xpage_appear
|
|
Dim in As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent 'Traemos en StartingIntent de Main.
|
|
If in.IsInitialized And in <> OldIntent Then
|
|
OldIntent = in
|
|
If in.HasExtra("Notification_Tag") Then 'Revisamos que traiga el tag.
|
|
If Starter.logger Then Log("Activity started from notification. Tag: " & in.GetExtra("Notification_Tag"))
|
|
Private waChat, nombre As String
|
|
Private ts() As String = Regex.Split("\|", in.GetExtra("Notification_Tag"))
|
|
waChat = ts(0)
|
|
nombre = ts(1)
|
|
If Starter.logger Then LogColor($"ts=${ts}, ts.Length=${ts.Length}, waChat=${waChat}, nombre=${nombre}"$, Colors.green)
|
|
Starter.historicoDB.ExecNonQuery2("update historico set clic = '1' where clic = '0' and nombre = ?", Array As Object(nombre)) 'Ponemos en 1 las notificacion a las que ya se les dió clic.
|
|
CallSubDelayed2(Main, "Activity_KeyPress", KeyCodes.KEYCODE_BACK)
|
|
Subs.abreWAChat(waChat)
|
|
End If
|
|
End If
|
|
Subs.centraPanel(p_botones, Root.Width)
|
|
If NotificationService.notisMap2.IsInitialized Then llenaLV
|
|
If Not(CheckNotificationAccess) Then
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.red, 10dip)
|
|
b_notifAccess.Background = cd1
|
|
b_notifAccess.TextColor = Colors.White
|
|
b_notifAccess.Text = "Activar Permisos"
|
|
Else
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.RGB(109, 221, 101), 10dip)
|
|
b_notifAccess.Background = cd1
|
|
b_notifAccess.TextColor = Colors.White
|
|
b_notifAccess.Text = "Permisos Activos"
|
|
End If
|
|
' Dim Su As SuShell
|
|
' If Su.DeviceRooted Then
|
|
' If Starter.logger Then LogColor("Rooted", Colors.Green)
|
|
' Private suCmd As String = $"sqlite3 /data/data/com.whatsapp/databases/msgstore.db 'SELECT _id FROM messages WHERE data="Test 2"';"$
|
|
'' Private suCmd As String = $"ls"$
|
|
' If Su.ExecuteWithEvent(suCmd, "Su").WaitForCompletion Then
|
|
' If starter.Logger Then Log("Root - Done")
|
|
' Else
|
|
' If starter.Logger Then Log("Root - Permissions Error")
|
|
' End If
|
|
' Else
|
|
' If Starter.logger Then LogColor("Root - Device not rooted", Colors.red)
|
|
' End If
|
|
If Starter.logger Then LogColor("Cola de notificaciones="&NotificationService.notificacionesPorContestar, Colors.RGB(168,0,0))
|
|
getAdminRights
|
|
End Sub
|
|
|
|
Sub B4XPage_CloseRequest As ResumableSub
|
|
'Return True to close, False to cancel
|
|
Return True
|
|
End Sub
|
|
|
|
Sub Su_Start
|
|
If Starter.logger Then Log("Su: Start")
|
|
End Sub
|
|
|
|
Sub Su_Command(Command As String, Response() As String)
|
|
If Starter.logger Then Log("Su: Command")
|
|
Dim Lines As String
|
|
For i=0 To Response.Length-1
|
|
Lines = Lines & Response(i) & CRLF
|
|
Next
|
|
' Msgbox(Lines.Trim, Command)
|
|
If Starter.logger Then Log(Lines & CRLF)
|
|
End Sub
|
|
|
|
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
|
Sub b_notifAccess_Click
|
|
Dim In As Intent
|
|
In.Initialize("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS", "")
|
|
StartActivity(In)
|
|
End Sub
|
|
|
|
Sub b_notifAccess_LongClick
|
|
Subs.abreWAChat("5215554192439@s.whatsapp.net")
|
|
End Sub
|
|
|
|
Private Sub b_activo_Click
|
|
If NotificationService.status = "Servicio Activo" Then
|
|
NotificationService.status = "Servicio Apagado"
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.red, 10dip)
|
|
b_activo.Background = cd1
|
|
b_activo.Text = "Servicio Apagado"
|
|
NotificationService.cont = 101
|
|
StopService(NotificationService)
|
|
Else
|
|
NotificationService.status = "Servicio Activo"
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.RGB(109, 221, 101), 10dip)
|
|
b_activo.Background = cd1
|
|
b_activo.Text = "Servicio Activo"
|
|
NotificationService.cont = 101
|
|
StartService(NotificationService)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_test_Click
|
|
If starter.Logger Then Log("Test clicked")
|
|
' If NotificationService.notisMap2.IsInitialized Then EditText1.Text = NotificationService.notisMap2.As(JSON).ToString
|
|
' Subs.mandaWAMsjSBN("+52 55 1661 1480", $"Prueba - ${DateTime.Time(DateTime.now)}"$)
|
|
' If Starter.logger Then LogColor($"starterStatus=${Starter.starterStatus}, nsStatus=${NotificationService.nsStatus}"$, Colors.Blue)
|
|
' CallSubDelayed(NotificationService, "procesaColaDeNotificaciones")
|
|
' Private jid As String = "5215516611480"
|
|
' Subs.mandaWAMsjRoot("1.- Hola", jid)
|
|
reqManager.Initialize(Me, Starter.DBRServer)
|
|
cmd.Initialize
|
|
cmd.Name = "select_revisaBorrarVenta" 'Intentamos conectarnos al servido publico y si no responde cambiamos al interno.
|
|
cmd.Parameters = Array As Object("525554192439","16","4","16","4","16","4","16","4","16","4","525554192439")
|
|
reqManager.ExecuteQuery(cmd , 0, "revisaVenta", 750) 'request con timeout corto en ms.
|
|
|
|
' cmd.Name = "proc_recuperaClientesNuevos"
|
|
' cmd.Parameters = Array As Object("35","634","CHATBOT")
|
|
' reqManager.ExecuteCommand(cmd ,"procRecuperaClientes")
|
|
End Sub
|
|
|
|
Private Sub b_test_LongClick
|
|
' desbloqueaUsuario("CDAZA")
|
|
Private cont As Int = 0
|
|
For j = 1 To 4
|
|
For i = cont To cont+5
|
|
cont = cont + 1
|
|
If Starter.logger Then LogColor("cont="&cont, Colors.Blue)
|
|
If Starter.logger Then LogColor("Mandamos mensaje " & cont, Colors.Magenta)
|
|
Subs.mandaWAMsjRoot(cont & ".- Hola", "5215516611480")
|
|
' Subs.hazRootQuery("killall com.whatsapp", "KillWA")
|
|
Next
|
|
If Starter.logger Then LogColor("Iniciamos WA", Colors.Blue)
|
|
Subs.hazRootQuery("am start -n com.whatsapp/com.whatsapp.Main", "iniciaWA")
|
|
|
|
' Try
|
|
' Dim Intent1 As Intent
|
|
' Dim pm As PackageManager
|
|
' Intent1 = pm.GetApplicationIntent("com.whatsapp")
|
|
' StartActivity (Intent1)
|
|
' Catch
|
|
' Log ("Failed to launch app! Is it installed?")
|
|
' End Try
|
|
|
|
If Starter.logger Then LogColor("Esperamos 5 segs", Colors.red)
|
|
Sleep(5000)
|
|
Next
|
|
cont = 0
|
|
If Starter.logger Then Log("TERMINAMOS")
|
|
' Subs.copyWADB
|
|
' Subs.mandaWAImageRoot_0(1)
|
|
' Subs.traeImgMsjData
|
|
End Sub
|
|
|
|
Sub llenaLV
|
|
' Log("llenaLV")
|
|
' lv_notificaciones.Initialize("lv_notificaciones")
|
|
lv_notificaciones.Color = Colors.LightGray
|
|
lv_notificaciones.Clear
|
|
Dim label1 As Label
|
|
label1 = lv_notificaciones.SingleLineLayout.Label
|
|
label1.TextSize = 16
|
|
label1.TextColor = Colors.Black
|
|
lv_notificaciones.SingleLineLayout.ItemHeight = 110 'Alto de la opcion de la lista.
|
|
label1.Height = 40dip 'Alto de la etiqueta dentro de la opcion de la lista.
|
|
' Log(NotificationService.notisMap2.Keys)
|
|
For Each k As String In NotificationService.notisMap2.Keys
|
|
lv_notificaciones.AddSingleLine(k)
|
|
Next
|
|
End Sub
|
|
|
|
Sub lv_notificaciones_ItemClick (Position As Int, Value As Object)
|
|
' Log($"posicion: ${Position}, valor: ${Value}, sender: ${Sender}"$)
|
|
Private t0 As Map = NotificationService.notisMap2.Get(Value)
|
|
Dim t1 As StatusBarNotification = t0.Get(Value).As(lasNotis).notif
|
|
' Dim t2 As StatusBarNotification = t1.notif
|
|
Subs.abreWAChat(Subs.getShortcut(t1))
|
|
End Sub
|
|
|
|
Private Sub lv_notificaciones_ItemLongClick (Position As Int, Value As Object)
|
|
If Starter.logger Then Log($"posicion: ${Position}, valor: ${Value}, sender: ${Sender}"$)
|
|
Private tempMap As Map = NotificationService.notisMap2.Get(Value) 'Valeria Guerra Rivera
|
|
Private t1 As lasNotis = tempMap.Get(Value)
|
|
Private t2 As StatusBarNotification = t1.notif
|
|
' Log(t2)
|
|
If et_mensaje.Text = "" Then ToastMessageShow("El texto del mensaje no debe estar en blanco.", False)
|
|
If t2.IsInitialized And et_mensaje.Text <> "" Then
|
|
NotificationService.rp.reply(t2.Notification, t2.PackageName, et_mensaje.text)
|
|
' CallSubDelayed3(NotificationService, "guardaMsjSalida", t2, et_mensaje.text)
|
|
ToastMessageShow("Mensaje enviado!", False)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_p2_Click
|
|
B4XPages.ShowPage("Reglas")
|
|
End Sub
|
|
|
|
Private Sub b_respaldaBD_Click
|
|
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
|
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
|
If Result Then
|
|
Subs.copiaDB
|
|
Else
|
|
ToastMessageShow("Sin permisos", False)
|
|
End If
|
|
End Sub
|
|
|
|
Sub b_respaldaBD_LongClick
|
|
Try
|
|
File.Copy(File.DirRootExternal&"/Bow2.0","bow.db",File.DirInternal,"bow.db")
|
|
ToastMessageShow("Listo, reglas restauradas " & File.DirRootExternal&"/Bow2.0", False)
|
|
If Starter.logger Then Log("Listo, reglas restauradas " & File.DirRootExternal&"/Bow2.0")
|
|
Subs.traeReglas
|
|
Starter.reglasDB.Initialize(Starter.ruta, "bow.db", True)
|
|
B4XPages.MainPage.c_reglas.muestraReglas
|
|
Catch
|
|
ToastMessageShow("No se pudo hacer la copia: "&LastException, True)
|
|
End Try
|
|
End Sub
|
|
|
|
Sub CheckNotificationAccess As Boolean
|
|
Dim ph As Phone
|
|
Dim nstr, pstr As String
|
|
Dim r As Reflector
|
|
pstr = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
|
|
nstr = ph.GetSettings("enabled_notification_listeners")
|
|
Return nstr.Contains(pstr)
|
|
End Sub
|
|
|
|
Sub getcontactsPermission
|
|
If Starter.logger Then Log("getcontactsPermission")
|
|
rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
|
|
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
|
Dim p2 As B4XReglas = B4XPages.GetManager.GetPage("Reglas")
|
|
If Result Then
|
|
p2.contactsPermission = True
|
|
If Starter.logger Then Log(p2.contactsPermission)
|
|
Else
|
|
p2.contactsPermission = False
|
|
If Starter.logger Then Log(p2.contactsPermission)
|
|
ToastMessageShow("Sin permisos de contactos", False)
|
|
End If
|
|
End Sub
|
|
|
|
Sub getWritePermission
|
|
If Starter.logger Then Log("getcontactsPermission")
|
|
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
|
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
|
If Result Then
|
|
writePermission = True
|
|
If Starter.logger Then Log(writePermission)
|
|
Else
|
|
writePermission = False
|
|
If Starter.logger Then Log(writePermission)
|
|
ToastMessageShow("Sin permisos de escritura", False)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_imgWA_Click
|
|
B4XPages.ShowPage("Imagenes")
|
|
End Sub
|
|
|
|
Sub getAdminRights
|
|
If manager.Enabled = False Then
|
|
manager.Enable("Please enable in order to get access to the secured server.")
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_config_Click
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.Gray, 10dip)
|
|
B4XPages.MainPage.b_config.Background = cd1
|
|
NotificationService.pruebaPaso = 0
|
|
CallSubDelayed(NotificationService, "revisaConexion")
|
|
End Sub
|
|
|
|
Private Sub Timer1_Tick
|
|
' ToastMessageShow("Timer",False)
|
|
' ENVIA_ULTIMA_GPS 'Comentado para que no estorbe hasta que no esten los queries correctos en el config.properties
|
|
NotificationService.pruebaPaso = 0
|
|
CallSubDelayed(NotificationService, "revisaConexion")
|
|
End Sub
|
|
|
|
Private Sub Panel1_Click
|
|
If p_notisDisponibles.Visible Then p_notisDisponibles.Visible = False
|
|
End Sub
|
|
|
|
Private Sub p_notisDisponibles_Click
|
|
|
|
End Sub
|
|
|
|
Private Sub b_NotisDisp_Click
|
|
p_notisDisponibles.Width = Root.Width * 0.9
|
|
Subs.centraPanel(p_notisDisponibles, Root.Width)
|
|
p_notisDisponibles.Top = (Root.Height/2) - (p_notisDisponibles.Height/2)
|
|
lv_notificaciones.Width = p_notisDisponibles.Width * 0.9
|
|
lv_notificaciones.Left = (p_notisDisponibles.Width/2) - (lv_notificaciones.Width/2)
|
|
b_cierra.Left = p_notisDisponibles.Width - (b_cierra.Width + 10)
|
|
et_mensaje.Width = p_notisDisponibles.Width * 0.8
|
|
p_notisDisponibles.BringToFront
|
|
p_botones.SendToBack
|
|
p_notisDisponibles.Visible = True
|
|
End Sub
|
|
|
|
Private Sub b_cierra_Click
|
|
p_notisDisponibles.Visible = False
|
|
End Sub
|
|
|
|
Sub JobDone(Job As HttpJob) 'ignore
|
|
If Starter.logger Then LogColor("jobDone: " & Job.Tag, Colors.Magenta)
|
|
If Job.Success = False Then
|
|
If Starter.Logger Then LogColor("***** jobDone Error *****", Colors.Red)
|
|
If Starter.Logger Then LogColor(Job.ErrorMessage, Colors.Red)
|
|
Else
|
|
If Starter.Logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211027
|
|
If Job.JobName = "DBRequest" Then 'Para desbloquear un usuario Guna.
|
|
Dim result As DBResult = reqManager.HandleJob(Job)
|
|
If Starter.Logger Then Log("******************************************************")
|
|
If Starter.Logger Then Log($"************ ${result.Tag} ***********"$)
|
|
If Starter.Logger Then Log("******************************************************")
|
|
|
|
If result.Tag=="revisaVenta" Then 'query tag
|
|
Private num As String = result.Tag
|
|
num = num.SubString(num.IndexOf("_")+1)
|
|
If Starter.logger Then Log(num)
|
|
For Each records() As Object In result.Rows
|
|
For Each k As String In result.Columns.Keys
|
|
If Starter.logger Then LogColor(result.Tag & ": " & k & "=" & records(result.Columns.Get(k)), Colors.blue)
|
|
Next
|
|
' Dim autorizado As String = records(result.Columns.Get("AUTORIZADO"))
|
|
' Dim existe_venta As String = records(result.Columns.Get("EXISTE_VENTA"))
|
|
' Dim impresa As String = records(result.Columns.Get("IMPRESA"))
|
|
' Dim comercial As String = records(result.Columns.Get("COMERCIAL"))
|
|
' Dim condescuento As String = records(result.Columns.Get("CONDESCUENTO"))
|
|
Next
|
|
End If
|
|
End If
|
|
Job.Release
|
|
End If
|
|
End Sub |