﻿B4A=true
Group=Book\matnBook
ModulesStructureVersion=1
Type=Class
Version=10.5
@EndOfDesignText@
Sub Class_Globals
	
	Private mCallBack As Object
	Private mEventName As String
 
	Private rec_Quran As AX_RecyclerView

	Public Bool_Night      As Boolean 'Show Night Day
	Public Bool_Lock       As Boolean 'Lock or UnLock
  
	Public  list_page 	 As List
	Private list_farsi 	 As List
	Private list_farsi1 	 As List
	Private list_Start 	 As List
	Private list_id 	 As List
  	
	
	Private sql As SQL
	Private rs As ResultSet
  	
 
	Public  ennameBook As String 'enname Of Book
	
	Public  idSure As Int 'Id Of Sooreh
	Public  numAye  As Int 'Numbers Of Aye
	Public  numAye1 As Int 'size Of Aye
	
 
	Private colorFarsi As String
	Private colorFaal  As String
	Private sizeFarsi  As String
	Private fontFarsi  As String
 	
	Public Play_Text As String 'Play Text
  	
	Public boolPlay     As Boolean ' Play or Not
	Private positionPlay As Int ' Position Play
 
	Private NoA_pan_up As noaValueAnimator
	Private NoA_pan_up1 As noaValueAnimator
	Private NoA_pan_down As noaValueAnimator
	Private NoA_pan_down1 As noaValueAnimator
	Private NOA_AS As noaAnimatorSet
	Private NOA_AS1 As noaAnimatorSet

	Private sql2 As SQL
	Private rs2  As ResultSet

	Private content As Panel
	
	Private pKol As Panel
  	
	Private top1 As Int
	Private juympTo1 As Int = -1
	Private botom1 As Int

	Public QJH As String
	
	Private downloadBook As downloadMatnBook
	Private playBook As playMatnBook

	Private sooreh_Last_Neshan As String

 	Private nameBook As String
	
	Public txtSearch As String

	Public iPlay As Int
  
	Private lan2FaEn As String
	
	Private iscrol As Int

End Sub

Public Sub Initialize(Caller As Object, pEventName As String)
   	
	StartService(playServiceBook)

	mCallBack = Caller
	mEventName = pEventName
	
	Bool_Night = False
	Bool_Lock  = False
	boolPlay = False
 	
	positionPlay = 0
	
End Sub

Public Sub addParent(Parent As Panel,top As Int,botom As Int)
  	
	top1 = top
	botom1 = botom
    		
	list_page.Initialize
	list_farsi.Initialize
	list_Start.Initialize
	list_id.Initialize
	list_farsi1.Initialize
 
	content = Parent

	Dim bookDBPAE As String
	lan2FaEn = (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
	
	If sql2.IsInitialized=False Then
		sql2.Initialize(File.DirInternal,"fav.db",True)
	End If

	sooreh_Last_Neshan = func.readPFM("sooreh_Last_NeshanBook")

	nameBook = func.readPFM("NameBook")

	idSure = func.readPFM("idBook")
	             
	ennameBook = func.readPFM("ennameBook")
	Log(ennameBook)

	rs = sql.ExecQuery("SELECT  page,farsi,start,farsi2,id from '"&ennameBook&"' where type != 1 order by page asc")
 	
	Do While rs.NextRow
		
		list_page.add(rs.GetInt("page"))
		list_id.add(rs.GetInt("id"))
 		
		list_farsi.add(rs.GetString("farsi"))
		list_farsi1.add(rs.GetString("farsi2"))
		list_Start.add(rs.GetString("start"))
 		
	Loop : rs.Close
	
  	
	numAye  = list_page.Get(list_page.Size-1)
	numAye1 = list_page.Size
	
	
	colorFarsi = func.readPFM("colorFarsi")
	colorFaal  = func.readPFM("colorFaal")
	sizeFarsi  = func.readPFM("sizeFarsi")
	fontFarsi  = func.readPFM("fontFarsi")
 
 		
	pKol.Initialize("")
	Parent.AddView(pKol,0,top,100%x,100%y-top-botom)

	
	rec_Quran.SetRecyclerViewStyle("VerticalScrollbarRecyclerView")
	rec_Quran.Initializer("rec_Quran").ListView.Vertical.Build
	pKol.AddView(rec_Quran,0,0,pKol.Width,pKol.Height)
	rec_Quran.ScrollSettings.ScrollBarSize=5dip
	rec_Quran.ScrollSettings.VerticalFadingEdgeEnabled=True
	rec_Quran.DefaultAdapter

	NoA_pan_up.InitializeInt(top, 0, "NoA_pan_up") ' top
	NoA_pan_up1.InitializeInt(100%y-(top),100%y, "NoA_pan_up1") ' Height
	
	NoA_pan_down.InitializeInt(0,top, "NoA_pan_down") ' top
	NoA_pan_down1.InitializeInt(100%y,100%y-(top), "NoA_pan_down1") ' Height

	NOA_AS.PlayTogether(Array As Object(NoA_pan_up,NoA_pan_up1))
	NOA_AS.setDuration(500)
	NOA_AS.Interpolator = NOA_AS.INTERPOLATOR_LINEAR
 
	NOA_AS1.setDuration(500)
	NOA_AS1.PlayTogether(Array As Object(NoA_pan_down,NoA_pan_down1))
	NOA_AS1.Interpolator = NOA_AS1.INTERPOLATOR_LINEAR
  
 
	CallSubDelayed(Me,a4)

End Sub

Private Sub a4
	
	iPlay = 0
	
	Try
		
		If sooreh_Last_Neshan = 4 Or func.readPFM("typesSerchBk") = 1 Then
			
			Dim ii As Int = func.readPFM("search")
		
			Dim iii1 As Int = list_page.IndexOf(ii)
			
			txtSearch = func.readPFM("txtSearchbd")

			iPlay = iii1
		
			JumpRecycler(iii1)
			
		else If sooreh_Last_Neshan = 2 Then
			Dim ii As Int = func.readPFM("lastSeenBook")
			JumpRecycler(ii)
		
			iPlay = ii
		
		else if sooreh_Last_Neshan = 3 Then
			Dim ii As Int = func.readPFM("neshan")
			JumpRecycler(ii)

			iPlay = ii
		
		

		else if sooreh_Last_Neshan = 1 Then

			Dim sss As String = func.readPFM("lastSeenBook_"&idSure)
		
			If sss<>-1 Then
			
				Dim ii As Int = sss
				JumpRecycler(ii)
		
				iPlay = ii
			
			End If

		else if sooreh_Last_Neshan = 5 Then

			Dim sss As String = func.readPFM("lastSeenBook1_d")

			Dim ii As Int = list_page.IndexOf(func.SInt(sss))
		
			func.savePFM("lastSeenBook_"&idSure,ii)

			JumpRecycler(ii)
		
			iPlay = ii

		End If

	Catch
		iPlay = 0
		JumpRecycler(0)
		Log(LastException)
	End Try

End Sub
  
Public Sub positionBook As Int
	Log(CenterItemPosition)
	Log(list_page.Get(CenterItemPosition))
	
	Return list_page.Get(CenterItemPosition)
End Sub

Public Sub positionBook1(io As Int) As Int
	Return list_page.Get(io)
 End Sub

Public Sub changeColor
	
	colorFarsi = func.readPFM("colorFarsi")
	colorFaal  = func.readPFM("colorFaal")
	sizeFarsi  = func.readPFM("sizeFarsi")
	fontFarsi  = func.readPFM("fontFarsi")

	CallSubDelayed(Me,"ref_rec")
	
End Sub

Public Sub JumpRecycler(Position1 As Int)
	
	If func.readPFM("playBBook") = -1 Then Return

	rec_Quran.ScrollToPositionWithOffset(Position1,0)
 	
End Sub
  
Public Sub CenterItemPosition As Int
	Return rec_Quran.CenterItemPosition
End Sub

Public Sub changeBackground(color As Int)
	rec_Quran.Color = color
End Sub

Public Sub LZoomClick
	NOA_AS.Start
End Sub

Public Sub panexitClick
	NOA_AS1.Start
End Sub

Private Sub NoA_pan_up1_Update
	pKol.Height = NoA_pan_up1.AnimatedValue
	rec_Quran.Height = 100%y
End Sub

Private Sub NoA_pan_up_Update
	pKol.top = NoA_pan_up.AnimatedValue
End Sub

Private Sub NoA_pan_down1_Update
	pKol.Height = NoA_pan_down1.AnimatedValue
	rec_Quran.Height = 100%y-top1-botom1
End Sub

Private Sub NoA_pan_down_Update
	pKol.top = NoA_pan_down.AnimatedValue
End Sub


Private Sub rec_Quran_onCreateViewHolder (Parent As Panel,ViewType As Int)

	Dim P_play      As Panel
	
 	Dim L_Farsi As Label
	Dim L_Page  As Label
	Dim L_Star  As Label

	Dim L_Farsi1  As Label
	Dim labLine As Label
	Dim L_More As Label 
	
	Dim imgPage As ImageView

	Dim panImg As Panel

	P_play.Initialize("P_play")
 	
	L_Farsi.Initialize("")
	L_Page.Initialize("")
	L_Star.Initialize("")
	L_Farsi1.Initialize("")
	labLine.Initialize("")
	L_More.Initialize("L_More")
	imgPage.Initialize("")
	panImg.Initialize("")
 
	
	Parent.AddView(P_play  ,2%x,0,96%x,38dip)
	
	P_play.AddView(labLine,10%x,5dip,80%x,1dip)
	
	P_play.AddView(L_Star        ,5dip,15dip,45dip,45dip)
	P_play.AddView(L_More        ,96%x-40dip,15dip,45dip,45dip)
 	 
	P_play.AddView(L_Farsi1,0%x,L_Star.Top+L_Star.Height+5dip,96%x,30dip)
 	P_play.AddView(L_Farsi,0%x,L_Star.Top+L_Star.Height+5dip,96%x,30dip)
	
	
	P_play.AddView(panImg,48%x-41dip,L_Farsi.Top+L_Farsi.Height,82dip,30dip)
	
	panImg.AddView(L_Page,0,0,52dip,30dip)
	panImg.AddView(imgPage,52dip,5dip,28dip,20dip)
 	

End Sub

Private Sub rec_Quran_GetItemCount As Int
	Return list_page.Size
End Sub
 
Private Sub rec_Quran_onBindViewHolder (Parent As Panel,Position As Int)
	
	Dim P_play   	As Panel = Parent.GetView(0)
    
	Dim labLine As Label = P_play.GetView(0)
	
	Dim L_Star  As Label = P_play.GetView(1)
	Dim L_More  As Label = P_play.GetView(2)

	Dim L_Farsi1 As Label = P_play.GetView(3)
	Dim L_Farsi As Label = P_play.GetView(4)

	Dim panImg As Panel = P_play.GetView(5)
	
	Dim L_Page As Label = panImg.GetView(0)
	Dim imgPage As ImageView = panImg.GetView(1)

	'***************************************
	'***************************************
	P_play.Tag ="panel,"&Position
	
	If boolPlay Then
		If Position=positionPlay Then
			func.color_border(P_play,colorFaal,4dip)
		Else
			P_play.Color=Colors.Transparent
		End If
	Else
		P_play.Color=Colors.Transparent
	End If
	
	'***************************************
	'***************************************
 	
	func.color_border(labLine,0xaaC79B57,1000)
	
	L_More.Typeface = Typeface.MATERIALICONS
	L_More.Text=Chr(0xE5D4)
	L_More.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	L_More.Tag=Position
	L_More.TextSize=26
	
	imgPage.Gravity = Gravity.FILL
	imgPage.Bitmap = LoadBitmap(File.DirAssets, "cap1.png")

	'***************************************
	'***************************************

 	
	L_Star.Typeface = Typeface.MATERIALICONS
	L_Star.Text=Chr(0xE838)
	L_Star.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	L_Star.textColor = 0xffffab00
	L_Star.Tag=Position
	L_Star.TextSize=25

	rs2 = sql2.ExecQuery("SELECT id FROM favebook where position = '"&Position&"' and  number = '"&idSure&"' and lang = '"&lan2FaEn&"' " )
	If rs2.RowCount > 0 Then
		L_Star.Visible=True
	Else
		L_Star.Visible=False
	End If
	
	'***************************************
	
	L_Page.Text = list_page.Get(Position)
	L_Page.Typeface = Typeface.LoadFromAssets(func.font3)
	L_Page.Gravity = Bit.Or(Gravity.CENTER,Gravity.BOTTOM)
	L_Page.TextSize = 18

'	***************************************

	If Bool_Night Then
		L_Farsi.TextColor = Colors.White
		L_Page.TextColor = Colors.White
		L_More.textColor = Colors.White

	Else
		L_Farsi.TextColor = colorFarsi
		L_Page.TextColor = Colors.Black
		L_More.textColor = Colors.Black

	End If

	'***************************************
	'***************************************
  
	Dim textFarsi As String = list_farsi.Get(Position)
	Dim textFarsi1 As String
   	
	'***************************************

	L_Farsi.Typeface = Typeface.LoadFromAssets(fontFarsi)
	L_Farsi.Gravity = func.setGravity1("checkBook")
	L_Farsi.TextSize = sizeFarsi
  	
 
	textFarsi = textFarsi.Replace("ZZZ1ZZZ"," (1)")
	textFarsi = textFarsi.Replace("ZZZ2ZZZ"," (2)")
	textFarsi = textFarsi.Replace("ZZZ3ZZZ"," (3)")
	textFarsi = textFarsi.Replace("ZZZ4ZZZ"," (4)")
	textFarsi = textFarsi.Replace("ZZZ5ZZZ"," (5)")
	textFarsi = textFarsi.Replace("ZZZ6ZZZ"," (6)")
	textFarsi = textFarsi.Replace("ZZZ7ZZZ"," (7)")
	textFarsi = textFarsi.Replace("ZZZ8ZZZ"," (8)")
	textFarsi = textFarsi.Replace("ZZZ9ZZZ"," (9)")

	
	L_Farsi.Top = L_Star.Top+L_Star.Height+1%y
 
	L_Farsi.Text = func.setThing0(textFarsi,"Ꞅ")
											 
	func.setJustificationMode(L_Farsi)
 	
	func.heightView(L_Farsi,textFarsi,5dip)
  	
	'*****************
  	
	If txtSearch.Trim.Length>0 Then
		
		textFarsi1  = list_farsi1.Get(Position)
  		
		textFarsi1 = textFarsi1.Replace("ꝭ","")
		textFarsi1 = textFarsi1.Replace("Ꞵ","")
		textFarsi1 = textFarsi1.Replace("ⱹ","")
		textFarsi1 = textFarsi1.Replace("ꬸ","")
		textFarsi1 = textFarsi1.Replace("Ï","")
 
		textFarsi1 = textFarsi1.Replace("ZZZ1ZZZ"," (1)")
		textFarsi1 = textFarsi1.Replace("ZZZ2ZZZ"," (2)")
		textFarsi1 = textFarsi1.Replace("ZZZ3ZZZ"," (3)")
		textFarsi1 = textFarsi1.Replace("ZZZ4ZZZ"," (4)")
		textFarsi1 = textFarsi1.Replace("ZZZ5ZZZ"," (5)")
		textFarsi1 = textFarsi1.Replace("ZZZ6ZZZ"," (6)")
		textFarsi1 = textFarsi1.Replace("ZZZ7ZZZ"," (7)")
		textFarsi1 = textFarsi1.Replace("ZZZ8ZZZ"," (8)")
		textFarsi1 = textFarsi1.Replace("ZZZ9ZZZ"," (9)")

		textFarsi1 = func.setThing00(textFarsi1,"Ꞅ")
		textFarsi1 = textFarsi1.Replace("Ꞅ","")

		L_Farsi1.Text = func.SearchHighLight(textFarsi1,txtSearch)
	
		L_Farsi1.Top = L_Farsi.Top

		L_Farsi1.Typeface = Typeface.LoadFromAssets(fontFarsi)
		L_Farsi1.Gravity = func.setGravity1("checkBook")
		L_Farsi1.TextSize = sizeFarsi
		L_Farsi1.TextColor = Colors.Transparent

		func.setJustificationMode(L_Farsi1)
	
		L_Farsi1.Height = L_Farsi.Height

		L_Farsi1.Visible = True
	Else
		L_Farsi1.Visible = False

	End If

	panImg.Top = L_Farsi.Top+L_Farsi.Height
 	
	'***************************************
 
	P_play.Height=panImg.Height+panImg.Top+5dip
	Parent.Height=P_play.Height+P_play.Top+5dip
 
End Sub
  
   
Private Sub rec_Quran_onScrollStateChanged (NewState As Int)
	
	If NewState = 0 Then
		scrols(iscrol)
	End If
 
End Sub

Private Sub rec_Quran_GetItemOffsets (OutRect As Rect,Item As Object,Position As Int)
 
	Dim pos As Int = rec_Quran.GetVisibleItemPosition(True,False)
  	
	If pos = -1 Then pos = rec_Quran.GetVisibleItemPosition(True,True)
	If pos = -1 Then pos = 0
 	
	func.savePFM("lastSeenBook",pos)
	func.savePFM("lastSeenBook_"&idSure,pos)
 
  	func.savePFM("lastJBook",list_id.Get(pos))

End Sub
 
Sub L_More_Click
	Dim pp As Label = Sender
  
	Dim ss As String  = pp.Tag

	If SubExists(mCallBack, mEventName & "_seClick") Then
		CallSub2(mCallBack, mEventName & "_seClick",ss)
	End If

	
End Sub
 
Private Sub P_play_LongClick
	
	Dim pp As Panel = Sender
	
	Dim ss As String  = pp.Tag
	ss = ss.Replace("panel,","")
	
 	If SubExists(mCallBack, mEventName & "_seClick") Then
		CallSub2(mCallBack, mEventName & "_seClick",ss)
	End If
 	
End Sub
 
Sub checkNeshan(ii3 As Int) As List
	
  	Dim lis As List
	lis.Initialize
	
	Dim Aye As String = list_page.Get(ii3)
 
	rs2 = sql2.ExecQuery("SELECT id FROM favebook where position = '"&ii3&"' and  number = '"&idSure&"' and lang = '"&lan2FaEn&"' " )
	
	Dim nameSure As String = func.gland(121)&" "&Aye&" "&func.gland(115)&" "& nameBook
	
	lis.Add(nameSure)
	  
	lis.Add (rs2.RowCount)
	
	rs = sql.ExecQuery2("SELECT id FROM pavaragh_book where book= ? and page=?",Array As String(idSure,list_page.Get(ii3)))

	If rs.RowCount>0 Then
		lis.Add(True)
	Else
		lis.Add(False)
	End If
	
	Return lis
	
End Sub

Public Sub pavar(ii As Int) As Boolean
	rs = sql.ExecQuery2("SELECT id FROM pavaragh_book where book= ? and page=?",Array As String(idSure,list_page.Get(ii)))

	If rs.RowCount>0 Then
		func.savePFM("idPageBook",list_page.Get(ii))
		 Return True

	End If
	
	Return False

End Sub

Public Sub copys(ii As Int)
	
	Dim textFarsi1 As String
	
	textFarsi1  = list_farsi.Get(ii)
  		
	textFarsi1 = textFarsi1.Replace("ꝭ","")
	textFarsi1 = textFarsi1.Replace("Ꞵ","")
	textFarsi1 = textFarsi1.Replace("ⱹ","")
	textFarsi1 = textFarsi1.Replace("ꬸ","")
	textFarsi1 = textFarsi1.Replace("Ï","")
	textFarsi1 = textFarsi1.Replace("Ꞅ","")
 
	textFarsi1 = textFarsi1.Replace("ZZZ1ZZZ"," (1)")
	textFarsi1 = textFarsi1.Replace("ZZZ2ZZZ"," (2)")
	textFarsi1 = textFarsi1.Replace("ZZZ3ZZZ"," (3)")
	textFarsi1 = textFarsi1.Replace("ZZZ4ZZZ"," (4)")
	textFarsi1 = textFarsi1.Replace("ZZZ5ZZZ"," (5)")
	textFarsi1 = textFarsi1.Replace("ZZZ6ZZZ"," (6)")
	textFarsi1 = textFarsi1.Replace("ZZZ7ZZZ"," (7)")
	textFarsi1 = textFarsi1.Replace("ZZZ8ZZZ"," (8)")
	textFarsi1 = textFarsi1.Replace("ZZZ9ZZZ"," (9)")
 
 	Dim cops As BClipboard
	cops.setText(func.PersianNumbers(textFarsi1))
End Sub
 
Public Sub addNeshan(ii As Int)
	
	neshan(ii)
	
	CallSubDelayed(Me,"ref_rec")

End Sub

Public Sub neshan(position As Int)
 	
	Dim textFarsi As String = list_farsi.Get(position)
	Dim Aye As String = list_page.Get(position)
	
	textFarsi = textFarsi.Replace("Ꞅ","")
	textFarsi = textFarsi.Replace("ⱹ","")
	textFarsi = textFarsi.Replace("ꬸ","")
	textFarsi = textFarsi.Replace("Ꞵ","")
	textFarsi = textFarsi.Replace("ꝭ","")
	textFarsi = textFarsi.Replace("Ï","")

	textFarsi = textFarsi.Replace("ZZZ1ZZZ"," (1)")
	textFarsi = textFarsi.Replace("ZZZ2ZZZ"," (2)")
	textFarsi = textFarsi.Replace("ZZZ3ZZZ"," (3)")
	textFarsi = textFarsi.Replace("ZZZ4ZZZ"," (4)")
	textFarsi = textFarsi.Replace("ZZZ5ZZZ"," (5)")
	textFarsi = textFarsi.Replace("ZZZ6ZZZ"," (6)")
	textFarsi = textFarsi.Replace("ZZZ7ZZZ"," (7)")
	textFarsi = textFarsi.Replace("ZZZ8ZZZ"," (8)")
	textFarsi = textFarsi.Replace("ZZZ9ZZZ"," (9)")

	rs2 = sql2.ExecQuery("SELECT id FROM favebook where position = '"&position&"' and  number = '"&idSure&"' and lang = '"&lan2FaEn&"' " )
	
	If rs2.RowCount > 0 Then

		sql2.ExecNonQuery("DELETE FROM favebook where position = '"&position&"' and  number = '"&idSure&"' and lang = '"&lan2FaEn&"' " )
		func.ToastSUCCESS(func.gland(99))

	Else
		sql2.ExecNonQuery("INSERT INTO favebook (position , name , mattn , number , enname , page , lang) VALUES ('" &position&"','"&nameBook&"','"&textFarsi&"','"&idSure&"','"&ennameBook&"','"&Aye&"','"&lan2FaEn&"') ")
		func.ToastSUCCESS(func.gland(100))
	
	End If
  	
End Sub
  
Public Sub shareQuran(ii As Int)
  
	Dim textFarsi As String = list_farsi.Get(ii)
	Dim Aye As String = list_page.Get(ii)

	textFarsi = textFarsi.Replace("Ꞅ","")
	textFarsi = textFarsi.Replace("ⱹ","")
	textFarsi = textFarsi.Replace("ꬸ","")
	textFarsi = textFarsi.Replace("Ꞵ","")
	textFarsi = textFarsi.Replace("ꝭ","")
	textFarsi = textFarsi.Replace("Ï","")

	textFarsi = textFarsi.Replace("ZZZ1ZZZ"," (1)")
	textFarsi = textFarsi.Replace("ZZZ2ZZZ"," (2)")
	textFarsi = textFarsi.Replace("ZZZ3ZZZ"," (3)")
	textFarsi = textFarsi.Replace("ZZZ4ZZZ"," (4)")
	textFarsi = textFarsi.Replace("ZZZ5ZZZ"," (5)")
	textFarsi = textFarsi.Replace("ZZZ6ZZZ"," (6)")
	textFarsi = textFarsi.Replace("ZZZ7ZZZ"," (7)")
	textFarsi = textFarsi.Replace("ZZZ8ZZZ"," (8)")
	textFarsi = textFarsi.Replace("ZZZ9ZZZ"," (9)")

	Dim Smatn As String="("&func.gland(115)&" "&nameBook&" "&func.gland(121)&" ,"&Aye&")"&CRLF&func.gland(114)
 	
	Dim smatn2 As String = CRLF&CRLF&"https://anvarvahy.com/appref?book="&idSure&"&page="&ii
 
 	func.TextShare(func.PersianNumbers("‌"&CRLF&textFarsi&CRLF&Smatn)&smatn2)

'	https://anvarvahy.com/appref?book=9&page=8
	
End Sub

Public Sub Im_Bardasht(ii As Int)
  		
	func.savePFM("kodamPrvB",1)

	func.savePFM("ipageBook",list_page.Get(ii))
	CallSub2(actBook,"show_hide_frag",func.listInitialize(30,Me,""))

End Sub


Private Sub P_play_Click
	
	If func.readPFM("dlBookH") = -1 Then
		func.ToastERROR(func.gland(110))
	Else
		If (Bool_Lock) Then Return
		
		Dim pp As Panel = Sender
 		Dim ss As String  = pp.Tag
		ss = ss.Replace("panel,","")
   		
		boolPlay = False
		iPlay = ss

		CallSub(mCallBack, mEventName & "_plys")
  		
	End If
  
End Sub
 
Public Sub LPlayClick
	
	If  Play_Text = Chr(0xE037) Then
	 
		If boolPlay Then
			changeChr
			playBook.plays
		Else
			checkPlayDownload(iPlay)
		End If
	Else
		If boolPlay Then
			changeChr
			playBook.pause
		Else
			checkPlayDownload(iPlay)
		End If
	End If
 	
End Sub

Public Sub LPlayClick2
	
	Dim test_conn As AriaLib
   
	If  Play_Text = Chr(0xE037) Then
	 
		If test_conn.TestInterntConnection = False Then
			func.ToastERROR(func.gland(22))
			Return
		End If
		
		If boolPlay Then
			changeChr
			playBook.plays
		Else
			downloadPlay(iPlay)
		End If
	Else
		If boolPlay Then
			changeChr
			playBook.pause
		Else
			downloadPlay(iPlay)
		End If
	End If
 	
End Sub

Private Sub downloadPlay(aye As Int)
	lodingVis(True)
	
 	Dim startPosition As String = list_Start.Get(aye)
 	
	If list_Start.Get(aye) = "" Or list_Start.Get(aye) = Null Then
		downloadPlay(aye+1)
		Return
	Else
	End If
	
 	aye = aye+1
	
  	If Not( playBook.IsInitialized ) Then playBook.Initialize(Me,"play")
	If Not(playBook.isPlaying) Then changeChr
	playBook.play(idSure,aye,startPosition,True)
	
End Sub
 
public Sub checkPlayDownload(ii As Int)
	downloadSooreh(ii)
End Sub

Private Sub downloadSooreh(ii As Int)
	
	Dim t1  As Boolean
	
	t1  = File.Exists(File.DirInternal,"abtahi/Book/"&idSure&"/1.mp3")
 			 
	If Not( downloadBook.IsInitialized ) Then downloadBook.Initialize(Me,"download",content)

	If t1 Then
		download_pakhsh(ii)
	Else
		downloadBook.download(idSure,ii)
	End If
  	
End Sub

Private Sub download_pakhsh(aye As Int)
 
	boolPlay = True
	
	If SubExists(mCallBack, mEventName & "_recDl") Then
		CallSubDelayed(mCallBack, mEventName & "_recDl")
	End If

	Dim startPosition As String = list_Start.Get(aye)
	
	If list_Start.Get(aye) = "" Or list_Start.Get(aye) = Null Then
		download_pakhsh(aye+1)
		Return
	Else
	End If
	
	aye = aye+1
  	
	If Not( playBook.IsInitialized ) Then playBook.Initialize(Me,"play")
	If Not(playBook.isPlaying) Then changeChr
	playBook.play(idSure,aye,startPosition,False)
 
End Sub
 
Private Sub changeChr
	If SubExists(mCallBack, mEventName & "_rec") Then
		CallSubDelayed(mCallBack, mEventName & "_rec")
	End If
End Sub

Sub stopScroll
	rec_Quran.stopScroll
End Sub

Public Sub scrols(iscrol1 As Int) As Boolean
  	
	iscrol = iscrol1
	
	Try
		If iscrol1 = 0 Then
			rec_Quran.stopScroll
			Return True
		End If
		Dim factor As Int = 500 - ( iscrol1*100)
		If factor > 0 Then
			rec_Quran.SmoothScrollToPosition3(list_id.Size,factor)
			Return True
		End If
	Catch
		Log(LastException)
	End Try
 
	Return False
	
End Sub

Public Sub ref_rec
	rec_Quran.Adapter2.NotifyDataSetChanged
	rec_Quran.Adapter2.NotifyItemRemoved(0)
End Sub

Private Sub play_jump(Position1 As Int)
	
	Try
		Dim ghj As String = list_page.Get(Position1)
		playBook.playServices(ghj)
	Catch
		Log(LastException)
	End Try
	
	positionPlay = Position1
	JumpRecycler(Position1)
	color_lab(Position1)
	
End Sub

Private Sub play_nextClick
	changeChr
End Sub
 
Public Sub addSpeed (speedSound1 As Float)
	func.savePFM("speedQuran",speedSound1)
 	playBook.addSpeed(speedSound1)
End Sub
    
Public Sub seek_play_ValueChanged (Value As Int, UserChanged As Boolean,Seek_Play As ACSeekBar,Lb_monde As Label,Lb_kol As Label)
	If boolPlay Then
		If UserChanged = False Then Return '
		
		playBook.setPosition( Value / 100 * playBook.getDuration )
		timerofline_Tick(Seek_Play,Lb_monde,Lb_kol)
		
	Else
	End If
End Sub

Public Sub timerofline_Tick(Seek_Play As ACSeekBar,Lb_monde As Label,Lb_kol As Label)
	
	CallSub2(mCallBack, "setPage",rec_Quran.GetVisibleItemPosition(True,False))

	If boolPlay Then
		If playBook.IsPlaying Then
			Seek_Play.Value = playBook.getPosition / playBook.getDuration * 100
			
			setPositionD(playBook.getPosition)
 			
			Lb_monde.Text =   func.ConvertMillisecondsToString( playBook.getPosition )
			Lb_kol.Text= func.ConvertMillisecondsToString(playBook.getDuration)
 
		End If
	End If
	
End Sub


Public Sub mine_lick
	If (Bool_Lock) Then Return

	If boolPlay Then
		If playBook.IsPlaying Then
			If (playBook.getPosition - 10000) < (0) Then Return
			playBook.setPosition( (playBook.getPosition - 10000) )
		End If
	End If
End Sub

Public Sub plus_lick
	If (Bool_Lock) Then Return

	If boolPlay Then
		If playBook.IsPlaying Then
			If (playBook.getPosition + 10000) > (playBook.Duration) Then Return
			playBook.setPosition( (playBook.getPosition + 10000) )
		End If
	End If
End Sub
 
  
Sub play_StreamBuffer(Percentage As Int)

	If func.readPFM("playBBook") = -1 Then Return
	
	If SubExists(mCallBack, mEventName & "_strb") Then
		CallSubDelayed2(mCallBack, mEventName & "_strb",Percentage)
	End If
End Sub
   
Sub play_StreamReady
	boolPlay = True
	lodingVis(False)
 End Sub

Sub play_StreamError
	lodingVis(False)
	func.ToastERROR(func.gland(3))
End Sub
 
Private Sub lodingVis(bill As Boolean)
	If SubExists(mCallBack, mEventName & "_svis") Then
		CallSubDelayed2(mCallBack, mEventName & "_svis",bill)
	End If
End Sub

public Sub setPositionD(Pos As String)
  	
	Try
		
		Dim juympTo As Int
  	
		For i=0 To list_Start.Size-1
 			
			If i=list_Start.Size-1 Then
				juympTo=i
				Exit
			Else
  
				Dim P1 As String = list_Start.Get(i)
				Dim P2 As String = list_Start.Get(i+1)
  
				If P1="" Then
  					
				Else

					If Pos>= P1 Then
						If P2="" Then
							juympTo=i
							Exit
						Else
							If Pos<P2 Then
								juympTo=i
								Exit
							End If
						End If
					End If
				End If

			End If
		Next
  		
		If juympTo1=juympTo Then
		
		Else
			play_jump(juympTo)
		End If
	
		juympTo1 = juympTo
		
	Catch
		Log(LastException)
	End Try

End Sub

Public Sub getPosition As Int
	Return playBook.Position
End Sub
 
Private Sub color_lab(wi As String)
  	
	If func.readPFM("playBBook") = -1 Then Return

	For Each v As View In pKol.GetAllViewsRecursive
		If v Is Panel Then
			Dim panel As Panel = v
			If panel.Tag<>Null Then
				Dim ss As String = panel.Tag
				If ss="panel,"&wi Then
					func.color_border(panel,colorFaal,4dip)
				Else
					panel.Color=Colors.Transparent
				End If
			End If
		End If
	Next
	
	CallSubDelayed(Me,"ref_rec")
 	
End Sub

Public Sub isPlaying As Boolean
	Try
		If playBook.IsInitialized Then
			Return playBook.isPlaying
		End If
 	Catch
		Log(LastException)
	End Try
	Return False

End Sub

Public Sub close
	If downloadBook.IsInitialized Then downloadBook.close
	If playBook.IsInitialized Then playBook.close
  	
End Sub

public Sub close2
	func.savePFM("psbook",1)
	StopService(playServiceBook)
End Sub