#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=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Public mSQL As SQL
Public ApVals As Map
Private bVerisons As B4XComboBox
Private bChapters As B4XComboBox
Private Books As B4XComboBox
Private selectedVersion As String
Public kvs As KeyValueStore
Private Verses As CustomListView
Private lblVerse As Label
Private lblText As Label
Type versevalues (lblVerse As Label, lblText As Label)
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
xui.SetDataFolder("DevoSettings")
kvs.Initialize(xui.DefaultFolder, "devo.dat")
CopyDBIfNeeded("bible.db")
mSQL.Initialize(File.DirInternal, "bible.db", False)
Log(File.DirInternal)
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("bible")
LoadBibleVersions
LoadBibleBooks
LoadBibleChapters
LoadVerses
End Sub
Sub CopyDBIfNeeded (Filename As String)
If File.Exists(File.DirInternal, Filename) = False Then
File.Copy(File.DirAssets, Filename, File.DirInternal, Filename)
Log("Copied")
End If
End Sub
Sub LoadBibleChapters
bChapters.cmbBox.Clear
Dim mindex As Int
If Books.cmbBox.SelectedIndex=-1 Then
mindex =1
Else
mindex=Books.cmbBox.SelectedIndex+1
End If
Log("mindex: " & mindex)
Dim SenderFilter As Object = mSQL.ExecQueryAsync("SQL", "SELECT c FROM key_english where b=?", Array As String(mindex))
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
Dim numofchapters As Int
Do While rs.NextRow
numofchapters= rs.GetInt("c")
Loop
For x=1 To numofchapters
bChapters.cmbBox.Add(x)
Next
Else
Log(LastException)
End If
rs.Close
bChapters.cmbBox.SelectedIndex=kvs.GetDefault("Chapter",0)
End Sub
Sub LoadVerses
Dim SenderFilter As Object = mSQL.ExecQueryAsync("SQL", "SELECT v, t FROM " & selectedVersion & " WHERE b=?", Array As String(Books.SelectedIndex))
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
Dim x As Int=1
Do While rs.NextRow
Log(rs.GetString2(0))
Dim p As B4XView = xui.CreatePanel("")
p.LoadLayout("VersesLO")
lblVerse.Text=x
lblText.Text=rs.GetString2(0)
Dim iv As versevalues
iv.Initialize
iv.lblVerse=lblVerse
iv.lblText=lblText
Log("Added: " & iv.lblVerse.Text & " - " & iv.lblText.Text)
Verses.Add(p,iv)
x=x+1
Loop
rs.Close
Else
Log(LastException)
End If
End Sub
Sub LoadBibleVersions
Dim SenderFilter As Object = mSQL.ExecQueryAsync("SQL", "SELECT version FROM bible_version_key", Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
Do While rs.NextRow
Log(rs.GetString2(0))
bVerisons.cmbBox.Add(rs.GetString2(0))
Loop
rs.Close
Else
Log(LastException)
End If
bVerisons.cmbBox.SelectedIndex=kvs.GetDefault("Version",0)
End Sub
Sub LoadBibleBooks
Dim SenderFilter As Object = mSQL.ExecQueryAsync("SQL", "SELECT n FROM key_english", Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
Do While rs.NextRow
Log(rs.GetString2(0))
Books.cmbBox.Add(rs.GetString2(0))
Loop
rs.Close
Else
Log(LastException)
End If
Books.cmbBox.SelectedIndex=kvs.GetDefault("Book",0)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Sub setVersionforSQL(vIndex As Int)
Select Case vIndex
Case 0
selectedVersion="t_asv"
Case 1
selectedVersion="t_bbe"
Case 2
selectedVersion="t_dby"
Case 3
selectedVersion="t_kjv"
Case 4
selectedVersion="t_wbt"
Case 5
selectedVersion="t_web"
Case 6
selectedVersion="t_ylt"
End Select
kvs.Put("Version", vIndex)
End Sub
Private Sub bVerisons_SelectedIndexChanged (Index As Int)
setVersionforSQL(Index)
End Sub
Private Sub bChapters_SelectedIndexChanged (Index As Int)
kvs.Put("Chapter",Index)
End Sub
Private Sub Books_SelectedIndexChanged (Index As Int)
kvs.Put("Book",Index)
End Sub