﻿B4A=true
Group=support
ModulesStructureVersion=1
Type=Class
Version=11.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 i_down As Int
  	
	Public bool_download  As Boolean
 
	Private idSure As Int
  	
	Dim ehsan As EN_NumberProgressView
	
 	Dim dirs As String
 	Dim slink As String
	
	Dim sir0a As String
	
End Sub

Public Sub Initialize(Caller As Object, pEventName As String,content1 As Panel,ehsan1 As EN_NumberProgressView,types As String)
  	
	mCallBack = Caller
	mEventName = pEventName

	ehsan = ehsan1

	If types = "doaa" Then
		s_download = urls.ch2Li&"/bookQuran/Doaa"
		dirs = "doaa"
		
		sir0a = "1.mp3"
		slink = "1.mp3"

	else if types = "book" Then
		s_download = urls.ch2Li&"/bookQuran/Book"
		dirs = "Book"
		
		sir0a = "1.mp3"
		slink = "1.mp3"
		
	else if types = "ahkam" Then
		s_download = urls.ch2Li&"/bookQuran/ahkam"
		dirs = "Ahkam"
		
		sir0a = "1.zip"
		slink = "moabpa"

	End If
	
End Sub
 
Public Sub download(idSure1 As Int)
	
	
	bool_download  = False
	i_down  = 0
   	
	idSure = idSure1
   	
	ConfirmClick
	
End Sub

Public Sub close
 	
	If bool_download Then
		PAD.Cancel(True)
		If File.Exists(File.DirInternal,"abtahi/"&dirs&"/"&idSure&"/"&slink) Then
			func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure&"/"&slink)
		End If
	End If
  	
End Sub
  
Private Sub ConfirmClick
 	

	If test_conn.TestInterntConnection = False Then
		func.ToastERROR(func.gland(3))
		
		func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure)
		pakhsh
	Else
 		CallSubDelayed(Me,"download_ayeh_tar")
 	End If
	
End Sub

Private Sub download_ayeh_tar
 		
	Dim f1 As AriaFile
		
	If File.Exists(File.DirInternal,"abtahi/"&dirs&"/"&idSure)= False Then
		File.MakeDir(File.DirInternal,"abtahi/"&dirs&"/"&idSure)
	End If
		
	If File.Exists(File.DirInternal,"abtahi/"&dirs&"/"&idSure&"/"&slink) Then
		func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure&"/"&slink)
	End If
	
	f1.initialize(File.DirInternal,"abtahi/"&dirs&"/"&idSure&"/"&slink)
	PAD.Initialize("PAD",s_download&"/"&idSure&"/"&sir0a)
	PAD.setPath(f1.GetPath,"")
		
	Log(s_download&"/"&idSure&"/"&sir0a)

End Sub
 
Private Sub PAD_Started
	
	bool_download=True
   	
End Sub

Private Sub PAD_Update (Progress As Int)
 	
	ehsan.SetProgress(Progress)
	i_down=Progress
	
End Sub
   
Private Sub PAD_Finished (Result As String)
  	
	Try
  		
		If i_down<>100 Then
			bool_download=True
			func.ToastERROR(func.gland(32))
			func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure)

			pakhsh
		Else
			bool_download=False
			CallSubDelayed(Me,"fini")
		End If

	Catch
		bool_download=False
		func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure)

		pakhsh
		func.ToastERROR(func.gland(32))
		Log(LastException)
	End Try
	
End Sub

Private Sub fini
   		
	If slink = "moabpa" Then
 		
		Dim zip As ABZipUnzip
		If zip.ABUnzip(File.DirInternal&"/abtahi/"&dirs&"/"&idSure&"/"&slink,File.DirInternal&"/"&"abtahi/"&dirs&"/"&idSure) Then
			func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure&"/"&slink)
  			
		Else
			func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure)

			func.hazf(File.DirInternal&"/abtahi/"&dirs&"/"&idSure&"/"&slink)
			Log("fail unzip")
			func.ToastERROR(func.gland(32))
			
 		End If
  	End If
		
	pakhsh

End Sub
  
Private Sub pakhsh
	If SubExists(mCallBack, mEventName & "_pakhsh") Then
		CallSubDelayed2(mCallBack, mEventName & "_pakhsh",idSure)
	End If
End Sub

  