iOS Question [SMM] SimpleMediaManager Images disappear

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello,

This is a new post for this issue that continues to torment me and I can't find a solution.

Again, this bug occurs only in b4i.

Here is a link with a screen recording demostrating the bug.


Moreover, attached you will find the code in order to reproduce it.

Thank you for your time.
 

Attachments

  • smm buggy.zip
    182.5 KB · Views: 45
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
I've created a cross platform example based on your layout and this nice API: https://www.b4x.com/android/forum/threads/b4x-randomuser-api-smm-lazy-loading-list-ddd.169044/

Don't use PreoptimizedCLV. It only makes things more complicated.
Check the example. If you are able to reproduce this issue with my example then please post it here and I'll check it.
Hello,

I tried this solution for the attached project using and not using DDD. Now the problem is that the first couple visible images are not shown and the next one are shown correctly as you see at screen capture.

https://share.icloud.com/photos/06b1VfeP0k9TiEGYgsoyyXupA

If I put a sleep(1000) in getNotifications then images are shown normally. I think there is a (bug)? between page loading completion and loading SMM images.

B4X:
Sub getNotifications
    LogColor("getNotifications", xui.Color_Yellow)
  
    B4XPages.mainpage.abrirProgresso("Loading...")
  
    If Not(toast.IsInitialized) Then
        #if b4i
        wait for B4XPage_Resize (Width As Int, Height As Int)
        #End If
        Wait For (CreateLayout) Complete (Result1 As Object)
    End If
  
    'IF I PUT THIS SLEEP THEN IMAGES ARE SHOWN CORRECTLY
    Sleep(1000)
      
    If clvNotifications.IsInitialized Then clvNotifications.Clear
  
    Dim job As HttpJob
    job.Initialize("", Me)
    job.Download("https://randomuser.me/api/?results=150&inc=name,location,picture,id,cell,email")
    'job.GetRequest.SetContentType("application/json")
    Wait For (job) JobDone (job As HttpJob)
    Log(job.Success)
    If job.Success Then
        Log(job.GetString)
        Dim response As Map = job.GetString.As(JSON).ToMap
        Log(response)
      
        Dim results As List = response.Get("results")
      
        Log(results.Size)
      
        If results.Size = 0 Then
            lblNoNotifications.BringToFront
            lblNoNotifications.Visible=True
        Else
            lblNoNotifications.SendToBack
            lblNoNotifications.Visible=False
        End If
      
        For Each Result As Map In results
          
            Dim name As Map = Result.Get("name")
            Dim nameTitle As String = name.Get("title")
            Dim nameFirst As String = name.Get("first")
            Dim nameLast As String = name.Get("last")
            Dim nameComplete As String = nameTitle & " " & nameFirst & " " & nameLast
          
            Dim location As Map = Result.Get("location")
          
            Dim street As Map = location.Get("street")
            Dim streetName As String = street.Get("name")
            Dim streetNumber As String = street.Get("number")
          
            Dim city As String = location.Get("city")
            Dim state1 As String = location.Get("state")
            Dim country As String = location.Get("country")
            Dim locationComplete As String = streetName & ", " & streetNumber & CRLF & city & " " & state1 & " " & country
          
            Dim picture As Map = Result.Get("picture")
            Dim pictureMedium As String = picture.Get("medium")
          
            Dim email As String = Result.Get("email")
            Dim cell As String = Result.Get("cell")
          
            Dim id As Map = Result.Get("id")
            Dim idName As String = id.Get("name")
            Dim idValue As String = id.Get("value")
            Dim idComplete As String = idName & idValue
          
            Dim u As user
            u.Initialize
            u.id = idComplete
            u.name = nameComplete
            u.location = locationComplete
            u.picture = pictureMedium
            u.email = email
            u.cell = cell
          
            Log(u)
          
'            PCLVnotifications.AddItem(100dip, xui.Color_Transparent, u)
            Dim pnl As B4XView = xui.CreatePanel("")
            pnl.SetLayoutAnimated(0, 0, 0, clvNotifications.AsView.Width, 100dip)
            clvNotifications.Add(pnl, u)
        Next
  
    Else
        Log("ERROR: " & job.ErrorMessage)
    End If
    job.Release
  
    Log("job.Release")
  
'    PCLVnotifications.ShowScrollBar = False 'no fast scrolling
'    PCLVnotifications.ExtraItems = 15
'    PCLVnotifications.Commit
  
    B4XPages.mainpage.fecharProgresso
  
    Log("Fim")
End Sub

p.s. your sample project is working fine, but there is no B4XPage_Resize event in order to handle safe areas and a seperate sub like getNotifications if I want to pass and argument. In this case there is no argument, but I have couple of other pages that exists.
 

Attachments

  • test.zip
    182.7 KB · Views: 29
Last edited:
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Try to reproduce it based on my example and I'll check it.
Hello,

The attached project and the capturescreen is based on your project. I tried with and without DDD.

The differences between your example and attached project is that is multipage, b4xpage_risize and argument passing subs. Moreover, I put wait for b4xpage_risize event and the createlayout sub in order to be resized correctly before loading childviews in clv.

The attahced project is on #3 post.

If I am missing something on this, please infrom me.

Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: this code has no real meaning. It doesn't do anything
B4X:
    #If B4I   
    wait for B4XPage_Resize (Width As Int, Height As Int)
    #End If
End Sub

My code doesn't include a call to: MediaManager.TrimMediaCache

This sub shouldn't return a ResumableSub as there is no call to Wait For or Sleep:
B4X:
Sub CreateLayout As ResumableSub
    LogColor("CreateLayout", xui.Color_Green)
    
    toast.Initialize(Root)
        
'    PCLVnotifications.Initialize(Me, "PCLVnotifications", clvNotifications)
    
    #if b4i
    clvNotifications.Asview.Color = xui.Color_Transparent
    clvNotifications.GetBase.Height = Root.Height - pnlToolbar.Height - B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom
    #End If
    
    Return Null
    
End Sub

Waiting for B4XPage_Resize in random places will lead to your code not running, as the event is not raised. In B4i and B4J (and in the future in B4A as well) the page can be resized multiple times.

The only case where it is appropriate to wait for B4XPage_Resize is if Width or Height are 0.
 
Upvote 0
Top