﻿B4A=true
Group=Book
ModulesStructureVersion=1
Type=Class
Version=11.8
@EndOfDesignText@
Sub Class_Globals
 
	Dim content As Panel
 
	Private Edmsg As EditText
	Private Lbtn As Label
	Private lab_back As Label
	
	Private sql2 As SQL
	Private rs2  As ResultSet

	Private name_db As String
	
	Dim sBar As String

	Private L_Background As Label
	Private L_mine As Label
	Private L_Plus As Label
	
	Private int_plus   As Int

	Private Bool_Night As Boolean

	Dim alimo As Alimo_Keyboard

	Private Label1 As Label
	
	Dim boolE As Boolean
	Dim bool2E As Boolean
	
	Private customDialog As customMaterialDialog
	
End Sub

Public Sub Initialize
End Sub
  
Public Sub onCreateView (Parent As Panel)
 	
	boolE = False
	bool2E = False

	content = Parent
	content.Color = 0xFFFBFDFF
  
	If sql2.IsInitialized=False Then
		sql2.Initialize(File.DirInternal,"prv_note_book.db",True)
	End If

	Dim l2n As Label
	l2n.Initialize("")
	content.AddView(l2n,0,50%y-30dip,100%x,60dip)
	l2n.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	l2n.Text=func.gland(54)
	l2n.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	l2n.textColor = Colors.Black
	l2n.TextSize=14

	l2n.Visible = True
	Sleep(5)
	addView
	l2n.Visible = False
 
 	
	alimo.Initialize(content)
	alimo.StartListenerKeyboardHeightChange("alimo")

	customDialog.Initialize(content,Me)
	
End Sub


Sub addView
	
	content.LoadLayout("add_prv")
	func.SetRipple(lab_back ,0x337FD3B1,0x884C9A7B,16)
  
	func.SetRipple(Lbtn,0xFF4C9A7B,0xFF487D66,10dip)
	
	Edmsg.Padding = Array As Int (10dip,10dip,10dip,10dip)

	func.SetRipple(L_Plus	     ,Colors.Transparent,0XAAEEEEEE,16)
	func.SetRipple(L_mine		,Colors.Transparent,0XAAEEEEEE,16)
	func.SetRipple(L_Background,Colors.Transparent,0XAAEEEEEE,16)

	Lbtn.Text = func.gland(138)
	Label1.Text = func.gland(143)
	Edmsg.hint = func.gland(141)

	Lbtn.Typeface = Typeface.LoadFromAssets(func.font3)
	Label1.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	Edmsg.Typeface = Typeface.LoadFromAssets(func.font3)
	func.MinimomFontLabel(Label1,14)

	name_db = "bardasht_"&func.readPFM("idBook")
 
	sBar = ""
	
	rs2 = sql2.ExecQuery("SELECT bar from '"&name_db&"' where ayeh = '"&func.readPFM("ipageBook")&"' ")
	If rs2.RowCount > 0 Then
		rs2.Position = 0
		sBar = rs2.GetString("bar")
	End If

	Dim sFirst As String = func.gland(115)&" "&func.readPFM("NameBook")&" "&func.gland(121)&" ," & func.readPFM("ipageBook")
 	
'	sFirst = sFirst&CRLF&"┄┄┅─✧─┅┄┄"&CRLF&func.readPFM("prvArabi")&CRLF&"┄┄┅─✧─┅┄┄"
	' 	sFirst = sFirst&CRLF&func.readPFM("prvFarsi")

	sFirst = sFirst&CRLF&"┄┄┅─✧─┅┄┄"
	
	sFirst = func.PersianNumbers(sFirst)
  
	If sBar.Length = 0 Then
		Edmsg.Text =  sFirst & CRLF & func.gland(143)&": " & CRLF
	Else
		Edmsg.Text =   sBar
	End If


	If func.readPFM("sizeFarsi")<>"-1" Then
		Edmsg.TextSize=func.readPFM("sizeFarsi")
		int_plus=func.readPFM("sizeFarsi")
	Else
		Edmsg.TextSize=16
		int_plus=16
	End If
 
	changeBack(True)
  
End Sub

Sub confirm
	
	boolE = True

  		
	If sBar.Length = 0 Then
		sql2.ExecNonQuery("INSERT INTO '"&name_db&"' (ayeh , bar) VALUES ('"&func.readPFM("ipageBook")&"','"&Edmsg.Text&"' ) ")
	Else
		sql2.ExecNonQuery("UPDATE '"&name_db&"' SET bar = '"&Edmsg.Text&"' WHERE ayeh = '"&func.readPFM("ipageBook")&"' ")
	End If
 
 
	func.ToastERROR(func.gland(144))
 
'	CallSubDelayed(Me,"close")
 	
End Sub

Sub Lbtn_Click
	confirm
End Sub

Sub lab_confirm_Click
	confirm
End Sub
 
Private Sub L_Plus_Click
	
	If int_plus<>30 Then
		int_plus=int_plus+1
		Edmsg.TextSize=int_plus
		func.savePFM("sizeFarsi",int_plus)
	End If
	
End Sub

Private Sub L_mine_Click
	
	If int_plus<>14 Then
		int_plus=int_plus-1
		Edmsg.TextSize=int_plus
		func.savePFM("sizeFarsi",int_plus)
	End If

End Sub

Private Sub L_Background_Click
	changeBack(False)
End Sub

Sub changeBack(bill As Boolean)
  	
	If bill Then
		If func.readPFM("Bool_Night") = -1 Then
			Bool_Night = True
		Else
			Bool_Night = False
		End If
	End If
  	 

	If Bool_Night=False Then
		
		func.SetRipple(L_Background	,0x884C9A7B,0x880D603E,16)
		Bool_Night = True
		
		content.color = 0xFF3F473B
		func.color_border1(Edmsg,0xFF3F473B,10dip,2,0xffB0BEC5)

		Edmsg.TextColor = Colors.White
  		
		func.savePFM("Bool_Night",1)
	Else
		func.savePFM("Bool_Night",-1)
		
		func.SetRipple(L_Background	,Colors.Transparent,0XAAEEEEEE,16)
		Bool_Night = False
	
		content.color = 0xFFFBFDFF
		func.color_border1(Edmsg,0xFFFFFFFF,10dip,2,0xffB0BEC5)

		Edmsg.TextColor = (Colors.Black)
 		 
	End If
	
End Sub

Sub alimo_KeyboardHeightChange (OldHeight As Int,NewHeight As Int)
 	
	If (NewHeight < OldHeight) Then
		Edmsg.Height = 96%y- Edmsg.Top - alimo.GetKeyboardHeight
		Try
			Edmsg.SelectionStart = Edmsg.Text.Length
		Catch
		End Try'ignore
	Else
		Edmsg.Height = 96%y- Edmsg.Top - 110dip
	End If
	 
End Sub

Sub lab_back_Click
  	
	func.TextShare(("‌"&CRLF&Edmsg.Text))

End Sub
  
Sub Edmsg_FocusChanged (HasFocus As Boolean)
	bool2E = True
End Sub
   
Sub materQu
 	customDialog.addDialog(func.gland(339),func.gland(340),func.gland(26),func.gland(27),func.gland(341))
End Sub

Sub Dialog_Positive
	confirm
	cl2se
End Sub

Sub Dialog_Negative
	cl2se
End Sub

Sub close
	
	alimo.HideKeyboard

	If Not(bool2E) Then
		cl2se
		Return
	End If
	
	If Not(boolE) Then
		materQu
		Return
	End If
	
	cl2se
	
End Sub
 
Sub cl2se
	
	alimo.HideKeyboard

	If func.readPFM("kodamPrvB") = 1 Then
		CallSub2(actBook,"show_hide_frag",func.listInitialize(16,Me,""))
	Else
		CallSub2(actBook,"show_hide_frag",func.listInitialize(32,Me,""))
	End If


End Sub

public Sub onKey (KeyCode As Int)

	If KeyCode = KeyCodes.KEYCODE_BACK Then
		close
	End If
	
End Sub
 