iOS Question [SMM] SimpleMediaManager Images disappear

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello,

I have this strange problem with loaded images if i go back and forth. Better see videos to understand:

b4i version: https://share.icloud.com/photos/0abs6-ok-9luTqB60Gt3g3JVQ

b4a version working excellent: https://photos.app.goo.gl/RAiDr8RrR8VHo1nM6

Images shown OK only at initial open of the page.

It is a b4x project so it uses exact same code loading images:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
 
    Root.Color=0xFF05030F
 
'    imageLoader.Initialize
 
    MediaManager.Initialize
    MediaManager.DefaultBackgroundColor = xui.Color_Transparent
    MediaManager.DefaultForegroundColor = xui.Color_Transparent
    MediaManager.DefaultErrorRequest.Extra.Put(MediaManager.REQUEST_BACKGROUND, xui.Color_Transparent)
    MediaManager.DefaultLoadingRequest.Extra.Put(MediaManager.REQUEST_BACKGROUND, xui.Color_Transparent)
    MediaManager.DefaultResizeMode = "FILL_NO_DISTORTIONS"
    MediaManager.AddLocalMedia(MediaManager.KEY_DEFAULT_ERROR, misc.FontToBitmap(misc.Chr32(0xF1B48),30,xui.Color_White), "image/*")
    MediaManager.AddLocalMedia(MediaManager.KEY_DEFAULT_LOADING, File.ReadBytes(File.DirAssets, "loading.gif"), "image/gif")
 
    #if b4a
    CreateLayout
    #End If
 
End Sub

Private Sub btnBack_Click
    totalAnnouncements = 0
    clvNotifications.Clear
    B4XPages.ClosePage(Me)
End Sub

Sub B4XPage_CloseRequest As ResumableSub
    totalAnnouncements = 0
    clvNotifications.Clear
    Return True
End Sub

Sub B4XPage_Resize (Width As Int, Height As Int)
 
    misc.ShowProgressBar("Loading...")
 
    #if b4i
    Dim r As Rect = B4XPages.GetNativeParent(Me).SafeAreaInsets
    r.Top = Max(20, r.Top)
    Root.SetLayoutAnimated(0, r.Left, r.Top, Width - r.Right - r.Left, Height - r.Bottom - r.Top)
    If Root.NumberOfViews = 0 Then CreateLayout
    #end if
 
End Sub

Sub CreateLayout As ResumableSub
 
    Root.LoadLayout("notifications")
 
    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
    btnDeleteAll.CustomLabel.Font = Font.CreateNew2("materialdesignicons",24)
    btnFollows.CustomLabel.Font = Font.CreateNew2("materialdesignicons",24)
    #End If
 
    Return Null
 
End Sub


Sub getNotifications
 
    Dim req As dbrequestmanager = misc.CreateRequest(Me)
    Dim cmd1 As DBCommand = misc.CreateCommand("getNotifications", Array(B4XPages.MainPage.user.id))
    Wait For (req.ExecuteQuery(cmd1, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(rs As DBResult)
        'work with result
 
        If rs.Rows.Size = 0 And clvNotifications.Size = 0 Then
            lblNoNotifications.BringToFront
            lblNoNotifications.Visible=True
        Else
            lblNoNotifications.SendToBack
            lblNoNotifications.Visible=False
        End If
 
        For i=0 To rs.Rows.Size-1
     
            Dim Record() As Object
            Record = rs.Rows.Get(i)
     
            Private n As notificationsData
            n.Initialize
            n.id = Record(rs.Columns.Get("id"))
            n.id_user = Record(rs.Columns.Get("id_user"))
            n.id_user_sent = Record(rs.Columns.Get("id_user_sent"))
            n.surname = Record(rs.Columns.Get("surname"))
            n.name = Record(rs.Columns.Get("name"))
            n.typeNotification = Record(rs.Columns.Get("typeNotification"))
            n.id_workout = Record(rs.Columns.Get("id_workout"))
            n.photo = Record(rs.Columns.Get("photo"))
            n.timestamp = Record(rs.Columns.Get("timestamp"))
 
             
            #If b4a
            lblNotificationDummy.Height = su.MeasureMultilineTextHeight(lblNotificationDummy,cs)
            pnlNotificationDummy.Height = lblNotificationDummy.Top + lblNotificationDummy.Height + 10dip
            PCLVnotifications.AddItem(pnlNotificationDummy.Height + 20dip,xui.Color_Transparent,n)
            #else
            lblNotificationDummy.Width = Root.Width - 80
            lblNotificationDummy.AttributedText = cs
            lblNotificationDummy.SizeToFit
            pnlNotificationDummy.Height = lblNotificationDummy.Top + lblNotificationDummy.Height + 10
            PCLVnotifications.AddItem(pnlNotificationDummy.Height + 20dip,xui.Color_Transparent,n)
            #end if
 
        Next
 
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
 
    j.Release
 
    PCLVnotifications.ShowScrollBar = False 'no fast scrolling
    PCLVnotifications.ExtraItems = 5
    PCLVnotifications.Commit
 
    misc.HideProgressBar
 
End Sub

Sub clvNotifications_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLVnotifications.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clvNotifications.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
 
        'Create the item layout
        pnl.LoadLayout("clvNotification")
 
            Dim n As notificationsData = item.Value
            If n.photo <> Null Then MediaManager.SetMediaWithExtra(pnl.GetView(0).Getview(1),$"${B4XPages.MainPage.downloadLink}?name=${n.photo}.jpg"$,"image/*",CreateMap(MediaManager.REQUEST_ROUNDIMAGE:True, MediaManager.REQUEST_HEADERS: CreateMap("command":"image","id": B4XPages.MainPage.user.id,"token":B4XPages.MainPage.user.token)))

            #If b4a
 
            pnl.GetView(0).GetView(0).Height = su.MeasureMultilineTextHeight(pnl.GetView(0).GetView(0),cs)
            pnl.GetView(0).GetView(0).Text=cs
            pnl.GetView(0).Height = pnl.GetView(0).GetView(0).Top + pnl.GetView(0).GetView(0).Height + 10dip
 
            #else

 
            pnl.GetView(0).GetView(0).As(Label).Width = Root.Width - 80
            pnl.GetView(0).GetView(0).As(Label).AttributedText=cs
            pnl.GetView(0).GetView(0).As(Label).SizeToFit
            pnl.GetView(0).Height = pnl.GetView(0).GetView(0).Top + pnl.GetView(0).GetView(0).Height + 10
            #end if

 
    Next
 
    MediaManager.TrimMediaCache
 
End Sub

As you see at iOS video, when going back, images disappeares ΤΟΟ from previous page, for no reason.

I load mediamanager in every b4xpage that is needed. I tried to load it once and call it from B4XMainPage but with same output.

Any ideas are welcome.

Thank you.
 
Last edited:

yiankos1

Well-Known Member
Licensed User
Longtime User
export the project so we can better analyze your case, I had a similar problem on android, it was a lack of starting the smm simplemediamanager on each page
Hello Lucas,

Thank you for your answer.
I had a similar problem on android, it was a lack of starting the smm simplemediamanager on each page
I encountered too in android and fixed it this way. But in b4i it is really a strange behavior.

I attach you the "Notification" page
 

Attachments

  • test.zip
    10.8 KB · Views: 19
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
B4X:
Type notificationsData (id As String, id_user As String, id_user_sent As String, surname As String, name As String, typeNotification As String, id_workout As String, timestamp As Long, photo As String, bitmap As B4XBitmap)

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public HUD As HUD
End Sub

Public Sub ShowProgressBar (Text As String)
    
    #if b4i
    HUD.ProgressDialogShow(Text)
    #else
    ProgressDialogShow(Text)
    #End If
    
End Sub

Public Sub HideProgressBar
    
    #if b4i
    HUD.ProgressDialogHide
    #else
    ProgressDialogHide
    #End If
    
End Sub

Sub CreateRequest(module As Object) As dbrequestmanager
    Dim req As dbrequestmanager
    req.Initialize(module, B4XPages.MainPage.rdcLink)
    Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
    Dim cmd1 As DBCommand
    cmd1.Initialize
    cmd1.Name = Name
    If Parameters <> Null Then cmd1.Parameters = Parameters
    Return cmd1
End Sub

I am afraid that you will not achieve to fetch an image because you will need the file name and a token in order to access files from server
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
First suspect is the layout being loaded in B4XPage_Resize. It can be called multiple times and it will cause all kinds of problems if you load the layout like this.
Thank you for your answer Erel. I followed your recommendation here and I assure you that is the only way I managed to get working everything fine. When I say everything, I mean: safe area intent, variable custom list view item's height, views not jumping around in order to resize and one more I can't remember.

Your post was a fix for everything.

Do you have any suggestion where should I start?

Moreover, I tried SMM's second example and I used this approach (CreateLayout and Wait for as per my example), everything was working fine!

Thank you for your time.
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
I couldn't simulate your error, do one last test for us, change mediaManager.SetMediaWithExtra to mediaManager.SetMedia

Also try commenting on the changes in the mediaManager

B4X:
     mediaManager.Initialize
'    mediaManager.SleepDurationBeforeDownload = 0
'    mediaManager.DefaultRequestTimeout = 60000
'    mediaManager.DefaultBackgroundColor = xui.Color_Transparent
'    mediaManager.DefaultForegroundColor = xui.Color_Transparent
'    mediaManager.DefaultErrorRequest.Extra.Put(mediaManager.REQUEST_BACKGROUND, xui.Color_Transparent)
'    mediaManager.DefaultLoadingRequest.Extra.Put(mediaManager.REQUEST_BACKGROUND, xui.Color_Transparent)
'    mediaManager.DefaultResizeMode = "FILL_NO_DISTORTIONS"
'    mediaManager.AddLocalMedia(mediaManager.KEY_DEFAULT_ERROR, B4XPages.mainpage.FontToBitmap(Chr(0xF1B4),30,xui.Color_White), "image/*")
'    mediaManager.AddLocalMedia(mediaManager.KEY_DEFAULT_LOADING, File.ReadBytes(File.DirAssets, "loading.gif"), "image/gif")
'    mediaManager.MaxMediaCacheSize = 500
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
I made an example and it is working perfectly, if you have any questions you can call me

View attachment 159711
Thank you very much for your time.

I have already switched to BitmapAsync because i have very strict deadline for this project.

Maybe at next update I will switch again at SMM.

As i see at your project, it is exact the same code with different server right? or am I missing something?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…