﻿B4A=true
Group=Book
ModulesStructureVersion=1
Type=Class
Version=11.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_hagm  As List
	Dim List_Pic  As List
  
	Private lab_search As Label
	Private ed_search As ACEditText
	
	Dim ime As IME
 	
	Dim content As Panel
	Dim lab_back As Label
	
	Private Label1 As Label

	Private ehsan     As EN_NumberProgressView
	Private L_File As Label
 	
	Private downloadDoaa As downloadallDoaa
  
	Dim iDekeye As Int
	
	Dim l_cancel As Label

	Dim dbsD As multiDownload

	Private customDialog As customMaterialDialog

	
End Sub

Public Sub Initialize
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
	
	dbsD.Initialize("book","id_book")
	
	List_id.Initialize
	List_doaa_name.Initialize
	List_hagm.Initialize
	List_Pic.Initialize
  
	If sql.IsInitialized=False Then
		sql.Initialize(File.DirInternal,"quransooreh.db",True)
	End If

	Cursor = sql.ExecQuery("SELECT idindex,name,hagm,enname 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_id.add((Cursor.GetInt("idindex")))
		List_hagm.add((Cursor.GetInt("hagm")))
  
	Loop : Cursor.Close
	
	
	downloadDoaa.Initialize(Me,"download",content,ehsan,"book")

	ime.Initialize("ime")
	ime.AddHandleActionEvent(ed_search)

	customDialog.Initialize(content,Me)

End Sub

Sub addView
	
	content.LoadLayout("doawnloadall")
	
	func.SetRipple(lab_back ,0x337FD3B1,0x884C9A7B,16)
	ed_search.RequestFocus
	ed_search.Color=Colors.Transparent

	Label1.Text = func.gland(107)
	L_File.Text = func.gland(56)
	ed_search.hint = func.gland(64)

	Label1.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	L_File.Typeface = Typeface.LoadFromAssets(func.font3)
	ed_search.Typeface = Typeface.LoadFromAssets(func.font3)

	func.MinimomFontLabel(L_File,14)
	func.MinimomFontLabel(Label1,14)

	func.SetRipple(l_cancel,Colors.Transparent,0xaaeeeeee,5)
	
	ehsan.Initialize("")
	content.AddView(ehsan,7%x+40dip,L_File.Top+L_File.Height+5dip,100%x-2*(7%x+40dip),40dip)
	
	ehsan.SetProgressColor(0xFF00FF15)
	ehsan.SetProgressTextColor(Colors.Black)
	ehsan.SetProgressTextSize(40)
	ehsan.SetUnreachedBarColor(0XAAEEEEEE)
	ehsan.SetProgress(0)

End Sub

Sub l_cancel_Click
	
	downloadDoaa.close

	L_File.Text = func.gland(56)
	L_File.TextColor = Colors.Black
	CallSubDelayed(Me,"RefUlv")
	CallSubDelayed(Me,"delEh")
	
	dbsD.deleteAllBook
	
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 pan As Panel
	pan.Initialize("pan")
 	
	Dim lab1 As Label
	Dim lab2 As Label
	Dim lab3 As Label
	Dim lab4 As Label
  	
	lab1.Initialize("")
	lab2.Initialize("lDelete")
	lab3.Initialize("")
	lab4.Initialize("")
   	
	Parent.AddView(pan,5%x+70dip,5dip,90%x-70dip,60dip)
	
	pan.AddView(lab1,60dip,7.5dip,pan.Width-80dip,45dip)
	pan.AddView(lab3,5dip,3dip,34dip,34dip)
	pan.AddView(lab4,5dip,37dip,30%x,18dip)
	
	Parent.AddView(lab2,5%x,5dip,60dip,60dip)
  
End Sub

Sub recSooreh_GetItemCount As Int
	Return List_id.Size
End Sub
 
Sub recSooreh_onBindViewHolder (Parent As Panel,Position As Int)
  	
	Dim pan As Panel=Parent.GetView(0)
	Dim lab1 As Label=pan.GetView(0)
	Dim lab3 As Label=pan.GetView(1)
	Dim lab4 As Label=pan.GetView(2)
 	
	Dim lab2 As Label=Parent.GetView(1)
'	***********************
'	***********************

	pan.Tag = Position
	pan.Elevation = 2dip
	
	If dbsD.sel0Book( List_id.Get(Position)) Then
		func.SetRipple(pan,0xFFCDFFD9,0x99eeeeee,25)

	Else
		func.SetRipple(pan,Colors.White,0x99eeeeee,25)

	End If

	func.setEllipsize(lab1,"END")
	lab1.Typeface=Typeface.LoadFromAssets(func.font3)
	lab1.Text= List_id.Get(Position) & "- " & List_doaa_name.Get(Position)
	lab1.Gravity=Bit.Or(Gravity.RIGHT,Gravity.CENTER_VERTICAL)
	lab1.TextSize = 14
  
	If 0 = List_hagm.Get(Position) Then
		lab1.textColor = 0xFFC2C1C1
	Else
		lab1.textColor = Colors.Black
	End If
	
	lab2.Text = Chr(0xF1F8)
	lab2.Typeface = Typeface.FONTAWESOME
	lab2.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	lab2.TextSize = 25
	lab2.Tag = Position

	lab3.Text = Chr(0xF0ED)
	lab3.Typeface = Typeface.FONTAWESOME
	lab3.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	lab3.TextSize = 25
 
	lab4.Text = func.gland(108)&": "&List_hagm.Get(Position) &" "&func.gland(109)
	lab4.Typeface = Typeface.LoadFromAssets(func.font3)
	lab4.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
	func.MinimomFontLabel(lab4,10)

	func.color_border(lab3,Colors.Transparent,10dip)

	Dim t1  As Boolean
	t1  = File.Exists(File.DirInternal,"abtahi/Book/"&List_id.Get(Position)&"/1.mp3")
	If t1 Then
		lab3.TextColor = 0xFF3492F0
		func.SetRipple1(lab2,Colors.Transparent,0x7DFF0000,10dip,1,Colors.Red)
		lab2.TextColor = 0xFFCE5669
		lab4.TextColor = Colors.Black

	Else
		lab3.TextColor = 0xFFC2C1C1
		func.SetRipple1(lab2,Colors.Transparent,0xFFC2C1C1,10dip,1,0xFFC2C1C1)
		lab2.TextColor = 0xFFC2C1C1
		lab4.TextColor = 0xFFC2C1C1

	End If


	pan.Height = 60dip
	Parent.Height = pan.Top+pan.Height+10dip

End Sub
 
Sub pan_Click
  		
	hideKey

	Dim pp As Panel=Sender
 	
	If 0 = List_hagm.Get(pp.Tag) Then
		func.ToastERROR(func.gland(110))
	Else
  			
		Dim t1  As Boolean
		t1  = File.Exists(File.DirInternal,"abtahi/Book/"&List_id.Get(pp.Tag)&"/1.mp3")
		If t1 Then
'			func.ToastERROR(func.gland(250))
			interOth(pp.tag)
			
		Else
 
			dbsD.insertBook(List_id.Get(pp.Tag))
 			
			Dim lis As List = dbsD.selectAll
			If lis.Size = 1 Then
				startDownload(lis)
			End If
			
			CallSubDelayed(Me,"RefUlv")

		End If

	End If

End Sub

Sub interOth(pos As Int)
  	
	If dbsD.sel0Book( List_id.Get(pos)) Then
		func.ToastERROR(func.gland(249))
		Return
	End If

	func.savePFM("ennameBook",List_Pic.Get(pos))
	func.savePFM("NameBook",List_doaa_name.Get(pos))
	func.savePFM("idBook",List_id.Get(pos))
   
	CallSub2(actBook,"show_hide_frag",func.listInitialize(16,Me,""))

End Sub

Sub startDownload(lis As List)
	downloadF(lis.Get(0))
End Sub

Sub downloadF(idBook As Int)
	
	downloadDoaa.download(idBook)
	L_File.Text = List_doaa_name.Get(List_id.IndexOf(idBook))
	L_File.TextColor = Colors.Red

End Sub

Sub lDelete_Click
	
	hideKey

	Dim pp As Label=Sender
 	
	Dim t1  As Boolean
	t1  = File.Exists(File.DirInternal,"abtahi/Book/"&List_id.Get(pp.Tag)&"/1.mp3")
	If t1 Then
		iDekeye = pp.Tag
		Warnning
	End If


End Sub
    
Private Sub Warnning
	
	customDialog.addDialog(func.gland(58),func.gland(59),func.gland(30),func.gland(29),"")
 
End Sub

Private Sub Dialog_Positive

	func.hazf(File.DirInternal&"/abtahi/Book/"&List_id.Get(iDekeye) )
	CallSubDelayed(Me,"RefUlv")
   
End Sub
 


Private Sub download_pakhsh(idBook As Int)
	
	dbsD.delBook(idBook)
	
	Dim lis As List = dbsD.selectAll

	If lis.Size > 0 Then
		startDownload(lis)
		CallSubDelayed(Me,"RefUlv")
	Else
		L_File.Text = func.gland(56)
		L_File.TextColor = Colors.Black
		CallSubDelayed(Me,"RefUlv")
		CallSubDelayed(Me,"delEh")
	End If

End Sub
 

Sub delEh
	ehsan.SetProgress(0)
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_hagm.Clear
		List_Pic.Clear
 	
		Cursor = sql.ExecQuery("SELECT idindex,name,hagm,enname FROM book  where lang = '"&func.readNIS("lan2FaEn",1)&"' and name LIKE '%"&New&"%'  order by idindex asc")
	
		Do While Cursor.NextRow
		
			List_doaa_name.add((Cursor.GetString("name")))
			List_Pic.add((Cursor.GetString("enname")))
			List_id.add((Cursor.GetInt("idindex")))
			List_hagm.add((Cursor.GetInt("hagm")))

		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 downloadDoaa.IsInitialized Then downloadDoaa.close
		CallSub2(actBook,"show_hide_frag",func.listInitialize(14,Me,""))
	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