#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=exemploLista50RegistrosETodosVisiveis.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Public pgCLVReachEnd As pageCLVReachEnd
Public pgCLVVisibleRangeChanged As pageCLVVisibleRangeChanged
Public pgCLVCombinado As pageCLVCombinado
Public SQL1 As SQL
Private Nomes As List = Array As String("Lucas", "Miguel", "Alice", "Sofia", "João", "Helena", "Gabriel", "Isabella", "Bernardo", "Lorenzo")
Private Sobrenomes As List = Array As String("Silva", "Santos", "Oliveira", "Souza", "Pereira", "Lima", "Carvalho", "Ferreira", "Ribeiro", "Almeida")
Private Cidades As List = Array As String("São Paulo", "Rio de Janeiro", "Belo Horizonte", "Salvador", "Curitiba", "Porto Alegre", "Recife", "Fortaleza", "Brasília", "Manaus")
Private Estados As List = Array As String("SP", "RJ", "MG", "BA", "PR", "RS", "PE", "CE", "DF", "AM")
Private bitmaps As List = Array("pexels-photo-446811.jpeg", "pexels-photo-571195.jpeg", "pexels-photo-736212.jpeg", "pexels-photo-592798.jpeg")
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
B4XPages.AddPage("pgCLVReachEnd", pgCLVReachEnd.Initialize)
B4XPages.AddPage("pgCLVVisibleRangeChanged", pgCLVVisibleRangeChanged.Initialize)
B4XPages.AddPage("pgCLVCombinado", pgCLVCombinado.Initialize)
#if b4j
xui.SetDataFolder("b4x")
sql.InitializeSQLite(xui.DefaultFolder, "dados.db", True)
#Else
SQL1.Initialize(xui.DefaultFolder, "dados.db", True)
#End If
Dim n As Long = DateTime.Now
Wait for (GeraDadosAleatorios(5000)) Complete (success As Boolean)
Log("A inserção dos dados levou: " & (DateTime.Now - n) & "ms")
Log("Dados inseridos com sucesso.")
End Sub
Private Sub btnCLVReachEnd_Click
B4XPages.ShowPage("pgCLVReachEnd")
End Sub
Private Sub btnCLVVisibleRangeChanged_Click
B4XPages.ShowPage("pgCLVVisibleRangeChanged")
End Sub
Private Sub btnCLVCombinado_Click
B4XPages.ShowPage("pgCLVCombinado")
End Sub
#Region FUNCOES
Sub CriaTabela As ResumableSub
' Cria a tabela no banco de dados SQLite
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS contatos (id INTEGER PRIMARY KEY AUTOINCREMENT, nome TEXT, email TEXT, telefone TEXT, localizacao TEXT, imagem TEXT)")
Return True
End Sub
Sub GeraDadosAleatorios(quantidade As Int) As ResumableSub
Wait for (CriaTabela) Complete (success As Boolean)
Dim qtd As Int = SQL1.ExecQuerySingleResult("SELECT count(*) FROM contatos")
If qtd > 0 Then
Return True
End If
Dim nome, sobrenome, email, telefone, cidade, estado, localizacao, imagem As String
Dim i As Int
SQL1.BeginTransaction
Try
For i = 1 To quantidade
nome = Nomes.Get(Rnd(0, Nomes.Size))
sobrenome = Sobrenomes.Get(Rnd(0, Sobrenomes.Size))
email = nome.ToLowerCase & "." & sobrenome.ToLowerCase & "@exemplo.com"
telefone = GeraTelefone
cidade = Cidades.Get(Rnd(0, Cidades.Size))
estado = Estados.Get(Rnd(0, Estados.Size))
localizacao = cidade & " - " & estado
imagem = bitmaps.Get(Rnd(0, bitmaps.Size))
SQL1.ExecNonQuery2("INSERT INTO contatos (nome, email, telefone, localizacao, imagem) VALUES (?, ?, ?, ?, ?)", Array As String(nome & " " & sobrenome, email, telefone, localizacao, imagem))
Next
SQL1.TransactionSuccessful
Catch
Log(LastException)
#if b4j or b4i
SQL1.RollBack
#End If
End Try
#if b4a
SQL1.EndTransaction
#End If
Return True
End Sub
Sub GeraTelefone() As String
' Gera um número de telefone realista no formato (XX) XXXXX-XXXX
Dim ddd As Int = Rnd(11, 99) ' Código de área entre 11 e 99
Dim numero As Int = Rnd(10000, 99999)
Dim sufixo As Int = Rnd(1000, 9999)
Return $"(${ddd}) ${numero}-${sufixo}"$
End Sub
Public Sub abrirProgresso(texto As String)
#if b4a
ProgressDialogShow2(texto, False)
#else if b4i
hud1.ProgressDialogShow(texto)
#End If
End Sub
Public Sub fecharProgresso
#if b4a
ProgressDialogHide
#else if b4i
hud1.ProgressDialogHide
#End If
End Sub
Public Sub abrirToast(texto As String, demorar As Boolean)
#if b4a
ToastMessageShow(texto, demorar)
#else if b4i
hud1.ToastMessageShow(texto, demorar)
#End If
End Sub
#End Region