﻿B4A=true
Group=Book
ModulesStructureVersion=1
Type=Class
Version=11
@EndOfDesignText@
Sub Class_Globals
   
	Private sv As ScrollView

	Private ImageView1 	As ImageView
	Private ImageView2 	As ImageView
	Private l_Title 	As Label
	Private l_Shere 	As Label
	Private l_Full 	As Label
  	
	Private l_Matn As Label
  	
	Private pphon As Phone
  
	Private sql As SQL
	Private Cursor As ResultSet

	Private p_Fehrest As Panel
 
	Private list_title As List
	Private list_page  As List
	
	Private Bool_Visable   As Boolean
	Private Bool_Recycler  As Boolean

	Private l_Fav As Label
	Private p_Yad As Panel
	
	Dim content As Panel
	Private Panel1a As Panel
	Dim pancn As Panel
 	 
	Private l_Conti	 	As Label
	Private l_Fehrest 	As Label
	Private Label1t 	As Label

	Private l_tal  As Label
	Private l_time As Label
	
	Private lab_back As Label
   	
	Dim ime As IME
	Private ed_search As ACEditText

	Private panZoom As Panel
	Private WKWebView2 As WebView

	Private Bool_Night  As Boolean
	Private int_plusIntro   As Int

	Private P_Play As Panel
	
 	Private L_Plus As Label
	Private L_Mine As Label
	Private L_Background As Label
	
End Sub

Public Sub Initialize
End Sub
  
Public Sub onHiddenChanged
	
End Sub

Private Sub savef
	
	Dim sql5 As SQL
	Dim Cursor5 As ResultSet

	If sql5.IsInitialized=False Then
		sql5.Initialize(File.DirInternal,"quransooreh.db",True)
	End If

 	Cursor5 = sql5.ExecQuery("SELECT idindex,name,enname,hagm,time,intro,ta_tgh FROM book where lang = '"&func.readNIS("lan2FaEn",1)&"' order by idindex asc")
	Cursor5.Position = 0
   
	func.savePFM("introBook",Cursor5.GetString("intro"))
	func.savePFM("ennameBook",Cursor5.GetString("enname"))
	
	func.savePFM("NameBook",Cursor5.GetString("name"))
	func.savePFM("idBook",Cursor5.GetInt("idindex"))
	
	func.savePFM("talBook",Cursor5.GetString("ta_tgh"))
	func.savePFM("timeBook",Cursor5.GetString("time"))
 
	Cursor5.Close
  
End Sub

Public Sub onCreateView (Parent As Panel)
    	
	savef
	
	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
	  
	
	Bool_Visable  = False
	Bool_Recycler = False
	Bool_Night = False

 
	list_title.Initialize
	list_page.Initialize
 
	Dim bookDBPAE As String
	Dim lan2FaEn As String = (func.readNIS("lan2FaEn",1))
	
	If lan2FaEn = 1 Then
		bookDBPAE = "book.db"
 	Else If lan2FaEn = 3 Then
		bookDBPAE = "book_eng.db"
 	Else If lan2FaEn = 2 Then
		bookDBPAE = "book_arabi.db"
 	Else
		bookDBPAE = "book.db"
 	End If

	If sql.IsInitialized=False Then
		sql.Initialize(File.DirInternal,bookDBPAE,True)
	End If
  	
	changeBack(True)

End Sub

Sub addView
 
	pancn.Initialize("")
	content.AddView(pancn,0,0,100%x,100%y)
 	 
	pancn.LoadLayout("introBookLayout1")

	sv.Initialize2(10000dip,"sv")
	Panel1a.AddView(sv,5dip,5dip,Panel1a.Width-10dip,Panel1a.Height-10dip-5%y)
	Dim r As Reflector
	r.Target = sv
	r.RunMethod2("setVerticalScrollBarEnabled", False, "java.lang.boolean")
	r.RunMethod2("setOverScrollMode", 2, "java.lang.int" )
  
	sv.Panel.LoadLayout("introBookLayout")
 	
	func.SetRipple(lab_back ,0x337FD3B1,0x884C9A7B,16)
	func.SetRipple(l_Fav ,0x337FD3B1,0x884C9A7B,16)
	func.SetRipple(p_Yad ,0x337FD3B1,0x884C9A7B,16)
	func.SetRipple(l_Shere,0x337FD3B1,0x884C9A7B,16)
	func.SetRipple(l_Full,0xaa4C9A7B,0x884C9A7B,16)
 	
	func.SetRipple(L_Plus	     ,Colors.Transparent,0XAAEEEEEE,16)
	func.SetRipple(L_Mine		,Colors.Transparent,0XAAEEEEEE,16)
	func.SetRipple(L_Background,Colors.Transparent,0XAAEEEEEE,16)
	
 	func.MinimomFontLabel(L_Plus		 ,26)
	func.MinimomFontLabel(L_Mine		 ,26)
	func.MinimomFontLabel(L_Background   ,26)

	Dim ImageView As ImageView
	ImageView.Initialize("")
	p_Yad.AddView(ImageView,10dip,10dip,p_Yad.Width-20dip,p_Yad.Height-20dip)
	ImageView.Bitmap = LoadBitmap(File.DirAssets, "book4.png")
	ImageView.Gravity = Gravity.FILL


	ImageView1.Gravity = Gravity.FILL
	
	Try
		ImageView1.Bitmap = LoadBitmap(File.DirAssets, func.readPFM("ennameBook")&".jpg")
	Catch
		ImageView1.Bitmap = LoadBitmap(File.DirAssets, "parvazrooh.jpg")
		Log(LastException)
	End Try

	
	l_Conti.Text = func.gland(411)
	l_Fehrest.Text = func.gland(117) 
 	
	Label1t.Text = func.gland(115)
	
	l_Conti.Typeface = Typeface.LoadFromAssets(func.font3)
	l_Fehrest.Typeface = Typeface.LoadFromAssets(func.font3) 
	Label1t.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
 	
	Dim sask As String = func.readPFM("introBook")
	
	l_Title.Text = func.readPFM("NameBook")
	l_Matn.Text = func.setThing2(sask,"Ꞅ")

	l_Title.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	l_Matn.Typeface = Typeface.LoadFromAssets(func.font3)

	func.setEllipsize(l_Title,"END")
	
	If func.readPFM("talBook") = 1 Then
		l_tal.Text = func.gland(111)
	Else
		l_tal.Text = func.gland(112)
	End If
	
	l_tal.Typeface = Typeface.LoadFromAssets(func.font3)

	l_time.Text = func.readPFM("timeBook") & " "&func.gland(113)
	
	l_time.Typeface = Typeface.LoadFromAssets(func.font3)

	If func.readPFM("int_plusIntro")<>"-1" Then
		l_Matn.TextSize=func.readPFM("int_plusIntro")
		int_plusIntro=func.readPFM("int_plusIntro")
	Else
		l_Matn.TextSize=16
		int_plusIntro=16
	End If
	
	func.setJustificationMode(l_Matn)

	l_Matn.Height = func.heightLabel(l_Matn,l_Matn.Text) + 10dip
	sv.Panel.Height = l_Matn.Top + l_Matn.Height + 10dip + 60dip
	
  
	p_Fehrest.Initialize("p_Fehrest")
	content.AddView(p_Fehrest,0,0,100%x,100%y)
	p_Fehrest.Visible = False
	func.color_border(p_Fehrest ,0xFFFBFDFF,0)
 	

	panZoom.Initialize("panZoom")
	content.AddView(panZoom,0,0,100%x,100%y)
	func.color_border(panZoom,0xee7B7A7A,10dip)
	panZoom.Visible = False
 	
	WKWebView2.Initialize("WKWebView2")
	panZoom.AddView(WKWebView2,0,0,100%x,100%y)
	WKWebView2.Color = Colors.Transparent


	func.MinimomFontLabel(l_Conti,14)
	func.MinimomFontLabel(l_Fehrest,14) 
	func.MinimomFontLabel(Label1t,14)
	func.MinimomFontLabel(l_Title,14)
	func.MinimomFontLabel(l_tal,14)
	func.MinimomFontLabel(l_time,14)
	func.MinimomFontLabel(l_tal,14)
	
	
	Dim bd As BitmapDrawable
 	bd.Initialize(LoadBitmap(File.DirAssets, "kadr.png"))
	bd.Gravity = Gravity.FILL
	
	l_Conti.Background = bd
	l_Fehrest.Background = bd
	 
	 
End Sub
  

Sub l_Fav_Click
	func.savePFM("sooreh_Last_NeshanBook",3)
  
	func.savePFM("booklAs","2")
	CallSub2(actBook,"show_hide_frag",func.listInitialize(18,Me,""))

End Sub

Sub p_Yad_Click
	func.savePFM("idPosBookY",-1)
 
	func.savePFM("backNOB",-1)
	CallSub2(actBook,"show_hide_frag",func.listInitialize(27,Me,""))
End Sub

Sub ImageView1_Click
	l_Conti_Click
End Sub
 
 
Sub l_Conti_Click

	func.savePFM("sooreh_Last_NeshanBook",1)
  
	CallSub2(actBook,"show_hide_frag",func.listInitialize(16,Me,""))
	
End Sub

Sub l_Full_Click
	
	Try
		func.LoadHtmlZoom(File.DirAssets, func.readPFM("ennameBook")&".jpg",WKWebView2)
	Catch
		func.LoadHtmlZoom(File.DirAssets,"parvazrooh.jpg",WKWebView2)
		Log(LastException)
	End Try

	panZoom.Visible = True
  
End Sub
 
Sub panZoom_Touch (Action As Int, X As Float, Y As Float)
	panZoom.Visible = False
End Sub

Sub l_Shere_Click
	
	Dim Smatn As String=func.gland(115)&" "&l_Title.Text&CRLF&func.gland(114)
	Dim smatn2 As String = CRLF&CRLF&func.gland(330) & " :"&CRLF&"https://anvarvahy.com/appref?moarefi="&func.readPFM("idBook")
 
	Dim sss As String = l_Matn.Text	
	func.TextShare(func.PersianNumbers("‌"&CRLF&sss&CRLF&Smatn)&smatn2)

End Sub

Sub l_Fehrest_Click

	Bool_Visable  = True
 
	func.savePFM("idPosBook",-1)

	If Bool_Recycler Then
	Else
  		
		ime.Initialize("ime")

		Private lb_Search As Label
		Private boxSearch As Panel
		
		boxSearch.Initialize("boxSearch")
		p_Fehrest.AddView(boxSearch,5%x,2%y,90%x,55dip)
 		func.color_border(boxSearch,Colors.White,100)
		boxSearch.Elevation = 5dip
		
		ed_search.Initialize("ed_Search")
		boxSearch.AddView(ed_search,60dip,0,90%x-70dip,55dip)
 		ed_search.hint = func.gland(64)
		ed_search.SingleLine=True
		ed_search.HintColor=0xFF7C8336
		ed_search.Typeface= Typeface.LoadFromAssets(func.font3)
		ed_search.Gravity=Bit.Or(Gravity.RIGHT,Gravity.CENTER)
		ed_search.Text=""
		ed_search.RequestFocus
		ed_search.TextColor= 0xFF7C8336
		ed_search.TextSize=14
 		func.color_border(ed_search,Colors.Transparent,16)
	
		lb_Search.Initialize("lb_Search")
		boxSearch.AddView(lb_Search,10dip,5dip,45dip,45dip)
		lb_Search.Typeface = Typeface.MATERIALICONS
		lb_Search.Text = Chr(0xE8B6)
		lb_Search.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
		lb_Search.TextSize = 25
		lb_Search.TextColor = 0xFF7C8336
		lb_Search.Color = Colors.Transparent

		func.color_border(lb_Search,0x327FD3B1,100)

		Private Recycler As AX_RecyclerView
	
		Recycler.SetRecyclerViewStyle("VerticalScrollbarRecyclerView")
		Recycler.Initializer("RV").ListView.Build
		p_Fehrest.AddView(Recycler,0,boxSearch.Top+boxSearch.Height+1%y,100%x,p_Fehrest.Height-(boxSearch.Top+boxSearch.Height+1%y)-1%y)
		Recycler.ScrollSettings.ScrollBarSize=5dip
		Recycler.ScrollSettings.VerticalFadingEdgeEnabled=True
		Recycler.Adapter = Recycler.DefaultAdapter
		Recycler.Tag = "Recycler"
		
		Bool_Recycler = True
 		
		ime.AddHandleActionEvent(ed_search)

	End If

	ed_search.Text = ""
	
	list_page.Clear
	list_title.Clear

	Cursor = sql.ExecQuery("SELECT matn,page FROM mozooat_book where id_index = '"&func.readPFM("idBook")&"' order by id asc")
	Do While Cursor.NextRow
		list_title.add((Cursor.GetString("matn")))
		list_page.add((Cursor.GetInt("page")))
	Loop : Cursor.Close
	
	CallSubDelayed(Me,"refRecBook")

	p_Fehrest.SetVisibleAnimated(500,True)

End Sub

Private Sub hideKey
	ime.HideKeyboard
End Sub

Sub ime_HandleAction As Boolean
	lb_Search_Click
	Return True
End Sub

Sub lb_Search_Click
	
	hideKey
 	
	If list_page.IsInitialized Then
		
		list_page.Clear
		list_title.Clear
  	
		Cursor = sql.ExecQuery("SELECT matn,page FROM mozooat_book where id_index = '"&func.readPFM("idBook")&"' and matn LIKE '%"&ed_search.Text&"%' order by id asc")
		Do While Cursor.NextRow
			list_title.add((Cursor.GetString("matn")))
			list_page.add((Cursor.GetInt("page")))
		Loop : Cursor.Close
 		
		CallSubDelayed(Me,"refRecBook")
	
	End If

End Sub

Sub refRecBook
	
	For Each v As View In p_Fehrest.GetAllViewsRecursive
		If v Is AX_RecyclerView Then
			Dim Recycler As AX_RecyclerView = v
			If Recycler.Tag="Recycler" Then
				Recycler.Adapter2.NotifyDataSetChanged
				Recycler.Adapter2.NotifyItemRemoved(0)
			End If
		End If
	Next

End Sub


Private Sub RV_GetItemCount As Int
	Return list_page.Size
End Sub
 
Private Sub RV_onCreateViewHolder (Parent As Panel,ViewType As Int)
 
	Dim pan As Panel
	pan.Initialize("pans")
	Parent.AddView(pan,5%x,5dip,90%x,50dip)

	Dim lab_title As Label
	lab_title.Initialize("")
	pan.AddView(lab_title,50dip,5dip,88%x-50dip,40dip)
 	
	Dim labs As Label
	labs.Initialize("")
	pan.AddView(labs,5dip,5dip,40dip,40dip)

End Sub

Private Sub RV_onBindViewHolder (Parent As Panel,Position As Int)

	Dim pan As Panel = Parent.GetView(0)
	Dim lab_title As Label = pan.GetView(0)
	Dim labs As Label = pan.GetView(1)
  	
	If func.readPFM("idPosBook") = Position Then
		func.SetRipple(pan,0xFFCDFFD9,0XAAEEEEEE,20)
 
	Else
		func.SetRipple(pan,Colors.White,0XAAEEEEEE,20)

	End If

	pan.Elevation = 2dip
	pan.Tag = Position

	lab_title.Text = func.setThing1( (Position+1) &"- "&list_title.Get(Position) , "ꬸ")
	lab_title.Typeface= Typeface.LoadFromAssets(func.font3)
	lab_title.TextSize=14
	lab_title.TextColor=Colors.Black
	lab_title.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
  	
	Dim su As StringUtils
	lab_title.Height = su.MeasureMultilineTextHeight(lab_title,lab_title.Text) + 10dip
 
	If lab_title.Height<50dip Then
		lab_title.Height = 50dip
	End If

	labs.Text = Chr(0xE314)
	labs.Typeface= Typeface.MATERIALICONS
	labs.TextSize=25
	labs.TextColor=0XFF4C9A7B
	labs.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.color_border(labs,0X337FD3B1,20)
	
	pan.Height = lab_title.Top+lab_title.Height+5dip
 	
 	labs.Top = (pan.Height/2) - 20dip
	
	Parent.Height=pan.Top+pan.Height+8dip

End Sub

Sub pans_Click
	
	Dim ll As Panel = Sender
	Log(ll.tag)
	
	func.savePFM("sooreh_Last_NeshanBook",5)

	func.savePFM("lastSeenBook1_d",list_page.get(ll.tag))
	func.savePFM("idPosBook",ll.tag)
   
	CallSubDelayed(Me,"refRecBook")
	

	CallSub2(actBook,"show_hide_frag",func.listInitialize(16,Me,""))

End Sub

Sub p_Fehrest_Touch (Action As Int, X As Float, Y As Float)
	

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
		
		Bool_Night = True
		func.savePFM("Bool_Night",1)

		l_Matn.TextColor = Colors.White
		
		sv.Panel.Color = 0xFF3F473B
		
		func.SetRipple(L_Background	,0x884C9A7B,0x880D603E,16)

		P_Play.Color = 0xFF323A2F
		Panel1a.Color = 0xFF3F473B
 		pancn.Color =  0xFF3F473B
		
		ImageView2.Visible = True
		
	Else
		
		ImageView2.Visible = False
		
		Bool_Night = False
		func.savePFM("Bool_Night",-1)

		l_Matn.TextColor = Colors.Black
		sv.Panel.Color = 0xFFFBFDFF
		
		func.SetRipple(L_Background	,Colors.Transparent,0XAAEEEEEE,16)

		P_Play.Color = Colors.White
		Panel1a.Color = Colors.White
 		pancn.Color =  0xFFFBFDFF


	End If
End Sub


Private Sub L_Mine_Click
	
	If int_plusIntro<>14 Then
		int_plusIntro=int_plusIntro-1
		l_Matn.TextSize=int_plusIntro
 		
		l_Matn.Height = func.heightLabel(l_Matn,l_Matn.Text) + 10dip
		sv.Panel.Height = l_Matn.Top + l_Matn.Height + 10dip + 60dip
		
		
		func.savePFM("int_plusIntro",int_plusIntro)

	Else
	End If
End Sub

Private Sub L_Plus_Click
	
	If int_plusIntro<>30 Then
		int_plusIntro=int_plusIntro+1
		l_Matn.TextSize=int_plusIntro
 		
		l_Matn.Height = func.heightLabel(l_Matn,l_Matn.Text) + 10dip
		sv.Panel.Height = l_Matn.Top + l_Matn.Height + 10dip + 60dip
		 
		func.savePFM("int_plusIntro",int_plusIntro)

	Else
	End If
End Sub

'**********************************
'**********************************
'**********************************

Sub close
	If Bool_Visable Then
		Bool_Visable = False
		p_Fehrest.SetVisibleAnimated(500,False)
			 
	Else If panZoom.Visible Then
		panZoom.Visible = False
	Else
		CallSub2(actBook,"show_hide_frag",func.listInitialize(14,Me,""))
	End If

End Sub

Sub lab_back_Click
	close
End Sub

public Sub onKey (KeyCode As Int)

	If KeyCode = KeyCodes.KEYCODE_BACK Then
		
		close
 
	else If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
		pphon.SetVolume(pphon.VOLUME_MUSIC,pphon.GetVolume(pphon.VOLUME_MUSIC) - 1,True)
	Else If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
		pphon.SetVolume(pphon.VOLUME_MUSIC,pphon.GetVolume(pphon.VOLUME_MUSIC) + 1,True)
	End If
	
End Sub
