﻿B4A=true
Group=Book
ModulesStructureVersion=1
Type=Class
Version=10.5
@EndOfDesignText@
Sub Class_Globals
 
 	Private recSooreh As AX_RecyclerView
 	
	Dim sql As SQL
	Dim Cursor As ResultSet

	Dim List_id  		  As List
	Dim List_doaa_name  As List
	Dim List_Pic        As List
	Dim List_tal        As List
  
	Dim List_hagm  As List
	Dim List_time  As List
	Dim List_intro As List

 	Private ed_search As ACEditText
	
	Dim ime As IME
  	
	Private downloadBook As downloadMatnBook
	Private boolDownloadBook As Boolean

	Dim content As Panel
	Dim lab_back As Label
	
	Private Label1 As Label
	
	Private idBook As Int
 	
	Private customDialog As customMaterialDialog
	Private boolDialog As Boolean

End Sub

Public Sub Initialize 
End Sub
 
public Sub onHiddenChanged
 	
 	CallSubDelayed(Me,"RefUlv")

End Sub
    
Public Sub onCreateView (Parent As Panel)
 	
	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

	
	boolDownloadBook = False
	
	List_id.Initialize
	List_doaa_name.Initialize
	List_Pic.Initialize
	List_tal.Initialize
	
	List_hagm.Initialize
	List_time.Initialize
	List_intro.Initialize
  
	If sql.IsInitialized=False Then
		sql.Initialize(File.DirInternal,"quransooreh.db",True)
	End If

	Log(func.readNIS("lan2FaEn",1))
	
	Cursor = sql.ExecQuery("SELECT idindex,name,enname,hagm,time,intro,ta_tgh FROM book where lang = '"&func.readNIS("lan2FaEn",1)&"' order by idindex asc")
	Do While Cursor.NextRow
		
		List_doaa_name.add((Cursor.GetString("name")))
		List_Pic.add((Cursor.GetString("enname")))
		List_tal.add((Cursor.GetString("ta_tgh")))
 		
		List_id.add((Cursor.GetInt("idindex")))
  
		List_hagm.add((Cursor.GetString("hagm")))
		List_time.add((Cursor.GetString("time")))
		List_intro.add((Cursor.GetString("intro")))
  
	Loop : Cursor.Close
  

	If func.readPFM("playQuranN3") = 1 Then
		func.savePFM("playQuranN3",-1)
		afterClick(List_id.IndexOf(func.SInt(func.readPFM("idBook"))))
		Return
	End If

	ime.Initialize("ime")
	ime.AddHandleActionEvent(ed_search)

	customDialog.Initialize(content,Me)

	recSooreh.Adapter = recSooreh.DefaultAdapter
 
End Sub

Sub addView
	
	If func.readPFM("playQuranN3") = 1 Then
		Return
	End If

	content.LoadLayout("menulistbooklayout")
	
	Label1.Text = func.gland(127)

	func.SetRipple(lab_back ,0x337FD3B1,0x884C9A7B,16)
	ed_search.RequestFocus
	ed_search.Color=Colors.Transparent
	ed_search.hint = func.gland(64)

	Label1.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	ed_search.Typeface = Typeface.LoadFromAssets(func.font3)

 	func.MinimomFontLabel(Label1,14)

End Sub

Sub Label1_LongClick
  	
	boolDialog = True
	customDialog.addDialog(func.gland(128),func.gland(129),func.gland(26),func.gland(27),"")
 	
End Sub

Private Sub Dialog_Positive
	
	If boolDialog Then
		
		If File.Exists(File.DirInternal,"abtahi/moarefi") Then
			func.hazf(File.DirInternal&"/abtahi/moarefi")
		End If

		func.ToastERROR(func.gland(130))
  
	Else
		func.hazf(File.DirInternal&"/abtahi/Book/"&idBook&"/1.mp3")
		CallSubDelayed(Me,"RefUlv")
	End If
 
End Sub
 
Sub hideKey
	ime.HideKeyboard
End Sub

Sub ime_HandleAction As Boolean
	hideKey
	Return True
End Sub
 
 
Sub recSooreh_onCreateViewHolder (Parent As Panel,ViewType As Int)
  
	Dim panKoli As Panel
	panKoli.Initialize("panKoli")
 
	Dim imBook   As ImageView
	Dim labTitle As Label
	Dim labTime  As Label
	Dim labHagm  As Label
	Dim labRead  As Label
	Dim labDl As Label
 
	
	imBook.Initialize("")
	labTitle.Initialize("")
	labTime.Initialize("")
	labHagm.Initialize("")
	labRead.Initialize("labRead")
	labDl.Initialize("labDl")
 	
	
	Parent.AddView(panKoli,3%x,5dip,44%x,200dip)
	
	panKoli.AddView(imBook  ,11.5%x,2%x,21%x,33%x )  
	panKoli.AddView(labTitle,2%x ,imBook.Top+imBook.Height+5dip,40%x,35dip)
	
	panKoli.AddView(labTime ,2%x   ,labTitle.Top+labTitle.Height+0.5%x,40%x,35dip)
	panKoli.AddView(labHagm ,2%x,labTime.Top+labTime.Height+0.5%x,40%x,35dip)
	
	panKoli.AddView(labDl,2%x ,labHagm.Top+labHagm.Height+1%x,19%x,40dip)
	panKoli.AddView(labRead ,23%x,labHagm.Top+labHagm.Height+1%x,19%x,40dip)
    
End Sub

Sub recSooreh_GetItemCount As Int
	Return List_id.Size
End Sub
 
Sub recSooreh_onBindViewHolder (Parent As Panel,Position As Int)
 	 			
 	Dim panKoli As Panel=Parent.GetView(0)
  
	func.SetRipple(panKoli,Colors.White,0xaaeeeeee,25)
	panKoli.Elevation = 6dip
 	
	Dim imBook   As ImageView = panKoli.GetView(0)
	Dim labTitle As Label     = panKoli.GetView(1)
	Dim labTime  As Label     = panKoli.GetView(2)
	Dim labHagm  As Label     = panKoli.GetView(3)
	Dim labDl    As Label     = panKoli.GetView(4)
	Dim labRead  As Label     = panKoli.GetView(5)

	setLab(labTitle,List_doaa_name.Get(Position),Colors.Black,14)
	setLab(labRead , func.gland(131),0xFF86551E,14)
  
	Dim t1  As Boolean
	t1  = File.Exists(File.DirInternal,"abtahi/Book/"&List_id.Get(Position)&"/1.mp3")

	If t1 Then
		setLab(labDl, func.gland(31),Colors.White,14)
		func.SetRipple(labDl,0xFF008000,0xFF005700,25)

	Else
		setLab(labDl, func.gland(31),0xFF86551E,14)
		func.SetRipple(labDl,0xFFE1DDDA,0xFFE5BEA1,25)

	End If

	LabCsb(labTime,func.gland(132)&": ",List_time.Get(Position)&" "&func.gland(113))
	LabCsb(labHagm,func.gland(108)&": ",List_hagm.Get(Position)&" "&func.gland(109))
	
	func.SetRipple(labRead,0xFFE1DDDA, 0xFFE5BEA1,25)
	
	imBook.Gravity = Gravity.FILL
	
	Try
		imBook.Bitmap = LoadBitmapSample(File.DirAssets, List_Pic.Get(Position)&".jpg",imBook.Width,imBook.Height)
	Catch
		imBook.Bitmap = LoadBitmapSample(File.DirAssets, "parvazrooh.jpg",imBook.Width,imBook.Height)
		Log(LastException)
	End Try
	
	
	labRead.Tag = Position
	labDl.Tag=Position
	panKoli.Tag=Position
   	
	panKoli.Width=44%x
	Parent.Width=50%x
	
	panKoli.Height=labRead.Top+labRead.Height+3%x
	Parent.Height=panKoli.Top+panKoli.Height+15dip

End Sub

Sub panKoli_Click
	
	Dim pp As Panel = Sender
	func.savePFM("sooreh_Last_2NeshanBook",2)
	afterClick(pp.Tag)
	
End Sub

Sub labRead_Click

	Dim pp As Label = Sender
	func.savePFM("sooreh_Last_2NeshanBook",2)
	afterClick(pp.Tag)
 
End Sub
 
Sub afterClick(pos As Int)
	
	hideKey
	
	func.savePFM("introBook",List_intro.Get(pos))
	func.savePFM("ennameBook",List_Pic.Get(pos))
 
	func.savePFM("NameBook",List_doaa_name.Get(pos))
	func.savePFM("idBook",List_id.Get(pos))
	
	func.savePFM("talBook",List_tal.Get(pos))
	func.savePFM("timeBook",List_time.Get(pos))
   
	CallSub2(actBook,"show_hide_frag",func.listInitialize(21,Me,""))

End Sub

Sub labDl_Click
	
	Dim pp As Label = Sender
	Log(pp.Tag)

	If 0 = List_hagm.Get(pp.Tag) Then
		func.ToastERROR(func.gland(110))
	Else
		func.savePFM("NameBook",List_doaa_name.Get(pp.Tag))
		func.savePFM("idBook",List_id.Get(pp.Tag))

		downloadSooreh(List_id.Get(pp.Tag))
	End If

	hideKey
	 

End Sub


Sub labDl_LongClick
	
	Dim pp As Label = Sender
	Log(pp.Tag)

	idBook = List_id.Get(pp.Tag)
	
	Warnning(List_doaa_name.Get(pp.Tag))
	
End Sub
 
Private Sub Warnning(s1 As String)
	
	boolDialog = False
 	customDialog.addDialog(func.gland(133)&" "&s1,func.gland(134),func.gland(26),func.gland(27),"")
 	
End Sub
 

Private Sub downloadSooreh(idSure 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
		func.ToastERROR(func.gland(135))
	Else
		boolDownloadBook = True
		downloadBook.download(idSure,0)
	End If
  	
End Sub

Private Sub download_perpakhsh 
	
	ProgressDialogShow(func.gland(136))
	
End Sub

Private Sub download_pakhsh(aye As Int)
	
	boolDownloadBook = False

	ProgressDialogHide
	Log("done")
	CallSubDelayed(Me,"RefUlv")
  	
End Sub
  

Sub setLab(lab As Label,ss As String,color As Int,fo As Float)
	lab.Text = ss
	lab.Typeface =  Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	lab.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
 	func.MinimomFontLabel(lab,fo)

	lab.TextColor = color
End Sub
 
Sub LabCsb(labshow As Label,s1 As String,s2 As String)
	
	labshow.Typeface =  Typeface.LoadFromAssets(func.font3) 
	labshow.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	labshow.textColor = 0xFF86551E
 
	Dim reg501 As RichString
	reg501.Initialize("{o}"&s1&"{o}"&s2)
	labshow.Text= reg501.Color2(Colors.DarkGray,"{o}")
 	func.MinimomFontLabel(labshow,14)

End Sub
  
   
Sub ed_search_TextChanged (Old As String, New As String)
	
	If List_id.IsInitialized Then
		
		List_id.Clear
		List_doaa_name.Clear
		List_Pic.Clear
		List_tal.Clear
	
		List_hagm.Clear
		List_time.Clear
		List_intro.Clear
		
		New = func.FToF1(New)
		Cursor = sql.ExecQuery("SELECT idindex,name,enname,hagm,time,intro,ta_tgh FROM book  where lang = '"&func.readNIS("lan2FaEn",1)&"' and name2 LIKE '%"&New&"%'  order by idindex asc")
	
		Do While Cursor.NextRow
		
			List_doaa_name.add((Cursor.GetString("name")))
			List_Pic.add((Cursor.GetString("enname")))
			List_tal.add((Cursor.GetString("ta_tgh")))
 		
			List_id.add((Cursor.GetInt("idindex")))
  
			List_hagm.add((Cursor.GetString("hagm")))
			List_time.add((Cursor.GetString("time")))
			List_intro.add((Cursor.GetString("intro")))
  
		Loop : Cursor.Close
		
		CallSubDelayed(Me,"RefUlv")
	
	End If
	
End Sub

Sub RefUlv
	recSooreh.Adapter2.NotifyDataSetChanged
	recSooreh.Adapter2.NotifyItemRemoved(0)
End Sub
 
Sub lab_back_Click
	close
End Sub
 
Sub close
 	 
	If ed_search.Text="" Then
		
		If boolDownloadBook Then
			
			boolDownloadBook = False
			
			If downloadBook.IsInitialized Then downloadBook.close

		Else
 			CallSub2(actBook,"show_hide_frag",func.listInitialize(14,Me,""))
		End If
 	Else
		hideKey

		ed_search.Text=""
	End If
  		
End Sub

public Sub onKey (KeyCode As Int)

	If KeyCode = KeyCodes.KEYCODE_BACK Then
		close
	End If
	
End Sub