﻿B4A=true
Group=Book\matnBook
ModulesStructureVersion=1
Type=Class
Version=10.5
@EndOfDesignText@
Sub Class_Globals
	
	Private mCallBack As Object
	Private mEventName As String

	Dim AC As Activity'ignore

	Private test_conn As AriaLib
	Private PAD As ParsAsyncDownloader
      
	Private s_download As String   
	
	Private ehsan As EN_NumberProgressView
	Private pan_taeed As Panel
	Private lab_load As Label
     
	Private i_down As Int
  	
	Public bool_download  As Boolean
 
	Private idSure,aye As Int
	
	Private pTar As Panel
  
	Public IsInitialized As Boolean
	
	Private customDialog As customMaterialDialog

End Sub

Public Sub Initialize(Caller As Object, pEventName As String,content1 As Panel)
	
	IsInitialized = True
	
	mCallBack = Caller
	mEventName = pEventName
	
	customDialog.Initialize(content1,Me)

	s_download = urls.ch2Li&"/bookQuran/Book"

	pTar.Initialize("pTar")
	content1.AddView(pTar,0,0,content1.Width,content1.Height)
	pTar.Color = 0xAADDDDDD
	pTar.Visible = False
	pTar.Elevation = 50dip
	
End Sub

Public Sub download(idSure1 As Int,aye1 As Int)
	
	bool_download  = False
	i_down  = 0
   	
	idSure = idSure1
	aye = aye1
  	
	Warnning
	
End Sub

Public Sub close
	
	IsInitialized = False

	If bool_download Then
		PAD.Cancel(True)
				
		pTar.Visible=False
		
		If File.Exists(File.DirInternal,"abtahi/Book/"&idSure&"/1.mp3") Then
			func.hazf(File.DirInternal&"/abtahi/Book/"&idSure&"/1.mp3")
		End If
	End If
  	
End Sub
  
   
Private Sub Warnning
	
	customDialog.addDialog(func.gland(82),func.gland(83),func.gland(31),func.gland(29),"")
 
End Sub

Sub Dialog_Positive
	ConfirmClick
End Sub


Private Sub ConfirmClick
 	

	If test_conn.TestInterntConnection = False Then
		func.ToastERROR(func.gland(3))
	Else
		pTar.Visible=True
		CallSubDelayed(Me,"download_ayeh_tar")
 	End If
	
End Sub


Private Sub download_ayeh_tar
 		
	Dim f1 As AriaFile
		
	If File.Exists(File.DirInternal,"abtahi/Book/"&idSure)= False Then
		File.MakeDir(File.DirInternal,"abtahi/Book/"&idSure)
	End If
		
	If File.Exists(File.DirInternal,"abtahi/Book/"&idSure&"/1.mp3") Then
		func.hazf(File.DirInternal&"/abtahi/Book/"&idSure&"/1.mp3")
	End If

	f1.initialize(File.DirInternal,"abtahi/Book/"&idSure&"/1.mp3")
	PAD.Initialize("PAD",s_download&"/"&idSure&"/1.mp3")
	PAD.setPath(f1.GetPath,"")
		
	Log(s_download&"/"&idSure&"/1.mp3")

End Sub
 
Private Sub PAD_Started
	
	bool_download=True
	loading
  	
End Sub

Private Sub PAD_Update (Progress As Int)
 	
	ehsan.SetProgress(Progress)
	i_down=Progress
	
End Sub

Private Sub pTar_Touch (Action As Int, X As Float, Y As Float)
	
End Sub
  
Private Sub PAD_Finished (Result As String)
  	
	Try
		
		ehsan.SetProgress(0)
		
		If i_down<>100 Then
			bool_download=True
			func.ToastERROR(func.gland(32))
		Else
			perpakhsh
			bool_download=False
			CallSubDelayed(Me,"fini")
		End If

	Catch
		func.ToastERROR(func.gland(32))
		Log(LastException)
	End Try
	
End Sub

Private Sub fini
	
	pTar.Visible=False
 		
	pakhsh
	
End Sub
  
Private Sub loading
	
 	
	pTar.Visible=True
	
	pTar.RemoveAllViews

	pan_taeed.Initialize("")
	pTar.AddView(pan_taeed,5%x,(pTar.Height/2)-40dip,90%x,85dip)
		
	lab_load.Initialize("")
	pan_taeed.AddView(lab_load,2%x,10dip,86%x,35dip)

	ehsan.Initialize("")
	pan_taeed.AddView(ehsan,15%x,lab_load.Top+lab_load.Height+5dip,60%x,40dip)

		

	
	Dim dl1 As ColorDrawable
	dl1.Initialize2(Colors.White,6dip,0dip,0xFF3F51B5)
	pan_taeed.Background=dl1
 	
	func.setEllipsize(lab_load,"END")
	lab_load.Typeface=Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	lab_load.Text=func.gland(28)&" " & func.readPFM("NameBook")
	lab_load.Gravity=Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	lab_load.textColor = Colors.Black
	lab_load.TextSize=14
   	
 	
	ehsan.SetProgressColor(0xFF6A5EF0)
	ehsan.SetProgressTextColor(Colors.Black)
	ehsan.SetProgressTextSize(40)
	ehsan.SetUnreachedBarColor(Colors.RGB(223,223,223))
 	 

End Sub

Private Sub pakhsh
	
 	If SubExists(mCallBack, mEventName & "_pakhsh") Then
		CallSubDelayed2(mCallBack, mEventName & "_pakhsh",aye)
	End If

End Sub

Private Sub perpakhsh
	
	If SubExists(mCallBack, mEventName & "_perpakhsh") Then
		pTar.Visible=False
		CallSubDelayed(mCallBack, mEventName & "_perpakhsh")
	End If

End Sub

 

