﻿B4A=true
Group=support
ModulesStructureVersion=1
Type=Class
Version=12.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 s_name As String   
     
	Private ehsan As EN_NumberProgressView
	Private pan_taeed As Panel
	Private lab_load As Label
     
	Private i_down As Int

	Private bool_download  As Boolean
  	
	Private pTar As Panel
  
	Public IsInitialized As Boolean
	
End Sub

Public Sub Initialize(Caller As Object, pEventName As String,content1 As Panel)
	
	IsInitialized = True
	
	mCallBack = Caller
	mEventName = pEventName
	
	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(s_download1 As String,s_name1 As String)
	
	bool_download  = False
	i_down  = 0
	
	s_download = s_download1
	s_name = s_name1
  	
	ConfirmClick
	
End Sub

Public Sub close
	
	IsInitialized = False

	If bool_download Then
		PAD.Cancel(True)
				
		pTar.Visible=False
		
		If File.Exists(File.DirInternal,"abtahi/support/"&s_name) Then
			func.hazf(File.DirInternal&"/abtahi/support/"&s_name)
		End If
	End If
  	
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/support")= False Then
		File.MakeDir(File.DirInternal,"abtahi/support")
	End If
		
	If File.Exists(File.DirInternal,"abtahi/support/"&s_name) Then
		func.hazf(File.DirInternal&"/abtahi/support/"&s_name)
	End If
  	
	f1.initialize(File.DirInternal,"abtahi/support/"&s_name)
	PAD.Initialize("PAD",s_download)
	PAD.setPath(f1.GetPath,"")
		
	Log(s_download)

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
			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(374)
	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",s_name)
	End If

End Sub

 

