﻿B4A=true
Group=Book
ModulesStructureVersion=1
Type=Class
Version=11.8
@EndOfDesignText@
Sub Class_Globals
 
	Dim content As Panel
  
	Private Edphon As EditText
	Private Edmsg As EditText
	Private Lbtn As Label
	Private lab_back As Label
	Private lab_confirm As Label
	Private Label1 	As Label

	Private sql2 As SQL


	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

	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
	
	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


	If sql2.IsInitialized=False Then
		sql2.Initialize(File.DirInternal,"note_book.db",True)
	End If

 	alimo.Initialize(content)
	alimo.StartListenerKeyboardHeightChange("alimo")

	customDialog.Initialize(content,Me)

End Sub


Sub addView
	
	content.LoadLayout("add_note")
	func.SetRipple(lab_back ,0x337FD3B1,0x884C9A7B,16)
	func.SetRipple(lab_confirm ,0x337FD3B1,0x884C9A7B,16)
  
	func.SetRipple(Lbtn,0xFF4C9A7B,0xFF487D66,10dip)
	
	Edphon.Padding = Array As Int (0,0,10dip,0)
	Edmsg.Padding = Array As Int (10dip,10dip,10dip,10dip)

	func.color_border1(Edphon,0xFFFFFFFF,10dip,2,0xffB0BEC5)
	func.color_border1(Edmsg,0xFFFFFFFF,10dip,2,0xffB0BEC5)
  
	Label1.Text = func.gland(137)

	Edmsg .hint = func.gland(141)
	Edphon.hint = func.gland(142)

	If func.readPFM("sdfsd") = 1 Then
		Lbtn.Text = func.gland(138)
	Else
		Edphon.Text = func.readPFM("titleBookY")
		Edmsg.Text = func.readPFM("matnBookY" )
 
		Lbtn.Text = func.gland(139)
	End If

	Label1.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	Edmsg.Typeface = Typeface.LoadFromAssets(func.font3)
	Edphon.Typeface = Typeface.LoadFromAssets(func.font3)
	Lbtn.Typeface = Typeface.LoadFromAssets(func.font3)

	func.MinimomFontLabel(Label1,14)

	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
  	
	If Edmsg.Text<>"" And Edphon.Text<>"" Then
		
		boolE = True

		If func.readPFM("sdfsd") = 1 Then
			sql2.ExecNonQuery("INSERT INTO ybook (title , matn , en_book) VALUES ('"&Edphon.Text&"','"&Edmsg.Text&"','"&func.readPFM("ennameBook")&"') ")
		Else
			sql2.ExecNonQuery("UPDATE ybook SET title = '"&Edphon.Text&"' , matn = '"&Edmsg.Text&"'  WHERE id = '"&func.readPFM("idBookY")&"' ")
		End If
		
		func.ToastERROR(func.gland(144))

 
'		CallSubDelayed(Me,"close")
	Else
		func.ToastERROR(func.gland(140))
	End If

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)
		func.color_border1(Edphon,0xFF3F473B,10dip,2,0xffB0BEC5)

		Edmsg.TextColor = Colors.White
		Edphon.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)
		func.color_border1(Edphon,0xFFFFFFFF,10dip,2,0xffB0BEC5)

		Edmsg.TextColor = (Colors.Black)
		Edphon.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
	close
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
	func.savePFM("backNOB",1)
	CallSub2(actBook,"show_hide_frag",func.listInitialize(27,Me,""))
End Sub

public Sub onKey (KeyCode As Int)

	If KeyCode = KeyCodes.KEYCODE_BACK Then
		close
	End If
	
End Sub
 