iOS Question ProgressDialog hides without executing ProgressDialogHide

German Buchmuller

Member
Licensed User
Longtime User
Hi, I have the following problem. My code downloads images from my jRDC server. Before the download starts, it shows the ProgressDialog by the line hd.ProgressDialogShow("Loading")
after it downloads, it hides it by: hd.ProgressDialogHide. The problem is that it often hides the progress dialog before the download finishes. And also, if I remove the hd.ProgressDialogHide line, the ProgressDialog Hides even though no command to hide it was executed. The code I use:
B4X:
Wait For (LoadBankSkins(BanksIDList.Get(BanksList.IndexOf(Item)))) Complete (Resultt As Int)

Sub LoadBankSkins (BankID As String) As ResumableSub
    
    Dim req As DBRequestManager = CreateRequest
    Dim comand As DBCommand = CreateCommand("getIDCARDSBankSkins", Array(BankID))
    hd.ProgressDialogShow("Loading")
    Wait For (req.ExecuteQuery(comand, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Sleep(0)
        Wait For (req) req_Result(res As DBResult)
        Sleep(0)
        BankCardTextColor.Initialize
        BankCardTopLightTheme.Initialize
        BankCardLightTheme.Initialize
        BankCardSkin.Initialize
        BankCardSkinId.Initialize
        BankCardBitmap=Null
        BankCardSkin.Tag=0
        For Each row() As Object In res.Rows
            CardNumberLb.Tag=Colors.RGB(row(res.Columns.Get("text_color_red")),row(res.Columns.Get("text_color_green")),row(res.Columns.Get("text_color_blue")))
            BankCardTextColor.Add(CardNumberLb.Tag)
            BankCardTopLightTheme.Add((row(res.Columns.Get("top_light_theme"))))
            BankCardLightTheme.Add((row(res.Columns.Get("light_theme"))))
            BankCardSkinId.Add((row(res.Columns.Get("skin_id"))))
            Sleep(0)
            Dim buffer() As Byte
            Sleep(0)
            buffer = row(res.Columns.Get("skin_image"))
            Sleep(0)
            BankCardBitmap=req.BytesToImage(buffer)
            Sleep(0)
            BankCardSkin.Add(BankCardBitmap)
        Next
        Sleep(0)
        If BankCardSkinId.Size>0 Then
            CreditCardBankSkinLb.Text=Dictionary1.Get("SKIN",Main.Language)&" "&(BankCardSkin.Tag+1)&"/"&BankCardSkinId.Size
            CreditCardBankSkinLb.Visible=True
            CreditCardBankSkinNextBtn.Visible=True
            CreditCardBankSkinPrevBtn.Visible=True
        Else
            CreditCardBankSkinLb.Visible=False
            CreditCardBankSkinNextBtn.Visible=False
            CreditCardBankSkinPrevBtn.Visible=False
        End If
        Sleep(0)
        j.Release
        Log("Skins Download finished")
        Sleep(0)
        hd.ProgressDialogHide
        'If I remove ProgressDialogHide, the ProgessDialog will hide anyway. Yet when executing another download, hd.ProgressDialogShow will do nothing
        Sleep(0)
        Return 1
    Else
        j.Release
        Return -1
    End If
End Sub

Any ideas how to solve this issue? Thanks
 

roumei

Active Member
Licensed User
You could try to call hd.XXX outside your sub and remove all the Sleep(0) calls (why are they needed?). Please also note that if j.Success is false, hd.ProgressDialogHide is not called.
B4X:
hd.ProgressDialogShow("Loading")
Wait For (LoadBankSkins(BanksIDList.Get(BanksList.IndexOf(Item)))) Complete (Resultt As Int)
hd.ProgressDialogHide
You may want to read this: [B4X] Resumable subs that return values (ResumableSub) | B4X Programming Forum
 
Upvote 0

German Buchmuller

Member
Licensed User
Longtime User
You could try to call hd.XXX outside your sub and remove all the Sleep(0) calls (why are they needed?). Please also note that if j.Success is false, hd.ProgressDialogHide is not called.
B4X:
hd.ProgressDialogShow("Loading")
Wait For (LoadBankSkins(BanksIDList.Get(BanksList.IndexOf(Item)))) Complete (Resultt As Int)
hd.ProgressDialogHide
You may want to read this: [B4X] Resumable subs that return values (ResumableSub) | B4X Programming Forum

I tried to move the hd.XXX outside the sub and still for some reason, the ProgressDialog hides before the download finishes.
It hides sometime after Wait For (req.ExecuteQuery(comand, 0, Null)) JobDone(j As HttpJob) is executed, but before the next line is executed. It seems like after the req.ExecuteQuery is executed, the ProgressDialog hides for itself.

I even modified the code as follows:
B4X:
Sub DownloadSkins
    hd.ProgressDialogShow("Cargando")
    CallSubDelayed3(CloudStorage,"LoadBankSkins",BanksIDList.Get(BanksList.IndexOf(Item)),Item)
End Sub

Sub BankSkinsDownloaded(Success As Boolean, Item As String)
    hd.ProgressDialogHide
    If Success Then
        If BankCardSkinId.Size>0 Then
            CreditCardBankSkinLb.Text=Dictionary1.Get("SKIN",Main.Language)&" "&(BankCardSkin.Tag+1)&"/"&BankCardSkinId.Size
            CreditCardBankSkinLb.Visible=True
            CreditCardBankSkinNextBtn.Visible=True
            CreditCardBankSkinPrevBtn.Visible=True
        Else
            CreditCardBankSkinLb.Visible=False
            CreditCardBankSkinNextBtn.Visible=False
            CreditCardBankSkinPrevBtn.Visible=False
        End If
                        
        UpdateSkinImage
        CardBankLb.Text=Item
        CreditCardBankLb.Text=Item
    Else
        
        CreditCardBankSkinLb.Visible=False
        CreditCardBankSkinNextBtn.Visible=False
        CreditCardBankSkinPrevBtn.Visible=False
        SelectedSkin="null"
        CardBackgroundPanel.SetAlphaAnimated(500,1)
        CardBankLb.SetAlphaAnimated(500,1)
        CardBackgroundIm.SetAlphaAnimated(500,0)
        ColorPickerTop.Visible=True
        CreditCardColorPicker.Visible=True
        SaveNewCardBtn.Top=ColorPickerTop.Height+ColorPickerTop.Top-Main.ScreenX*0.01
        DiscardNewCardBtn.Top=SaveNewCardBtn.Top
        CardNumberLb.TextColor=TextColor
        CardBankLb.TextColor=TextColor
        CardCVVLb.TextColor=TextColor
        CardThruLb.TextColor=TextColor
        CardIdentityNameLb.TextColor=TextColor
        CardTypeLb.TextColor=TextColor
        CreditCardNumberEtx_TextChanged ("", CreditCardNumberEtx.Text)
        CardBankLb.Text=Item
        CreditCardBankLb.Text=Item
    End If
End Sub

'CloudStorage Code Module:
Sub LoadBankSkins(BankID As String, Item As String)
    Main.hd.ProgressDialogShow("Loading")
    Dim req As DBRequestManager = CreateRequest
    Dim comand As DBCommand = CreateCommand("getIDCARDSBankSkins", Array(BankID))
    Wait For (req.ExecuteQuery(comand, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        For Each row() As Object In res.Rows
            MenuScreen.CardNumberLb.Tag=Colors.RGB(row(res.Columns.Get("text_color_red")),row(res.Columns.Get("text_color_green")),row(res.Columns.Get("text_color_blue")))
            MenuScreen.BankCardTextColor.Add(MenuScreen.CardNumberLb.Tag)
            MenuScreen.BankCardTopLightTheme.Add((row(res.Columns.Get("top_light_theme"))))
            MenuScreen.BankCardLightTheme.Add((row(res.Columns.Get("light_theme"))))
            MenuScreen.BankCardSkinId.Add((row(res.Columns.Get("skin_id"))))
            Dim buffer() As Byte
            buffer = row(res.Columns.Get("skin_image"))
            MenuScreen.BankCardBitmap=req.BytesToImage(buffer)
            MenuScreen.BankCardSkin.Add(MenuScreen.BankCardBitmap)
        Next
        j.Release
        CallSub3(MenuScreen,"BankSkinsDownloaded",True,Item)
    Else
        j.Release
        CallSub3(MenuScreen,"BankSkinsDownloaded",False,Item)
    End If
End Sub

Cannot figure out whats going on. Any ideas @Erel ?
 
Upvote 0
Top