Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 16
Registered: ‎12-01-2012
My Device: Z10
My Carrier: Play

WebImageView duplicated images

[ Edited ]

Hi,

I have a problem with images displayed from internet in the ListVIew. I'm using this class to display images: https://github.com/RileyGB/BlackBerry10-Samples/tree/master/WebImageViewSample/src but sometimes images in the list are duplicated without no reason. I'm just scrooling list down and up and those images are changing... I found also this topic: http://supportforums.blackberry.com/t5/Native-Development/How-to-detect-when-ListView-recycles-an-Im... but even after read it I have still no idea how to fix it.. Any idea how to fix it ?

Visitor
Posts: 1
Registered: ‎10-16-2013
My Device: Z10, Q10
My Carrier: H3G

Re: WebImageView duplicated images

Hi,
Here's my solution.
QNetworkDiskCache uses the Expires header of the http response to establish if the resource is fresh. In my case the server response does not have this header and so the images were not saved in the cache. So I modified WebImageView.h to add this information:

        // Create request
	QNetworkRequest request;
	request.setUrl(url);
	request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);

	// Create reply
	QNetworkReply * reply = mNetManager->get(request);
	QNetworkCacheMetaData metaData = mNetworkDiskCache->metaData(url);
	if (metaData.expirationDate().toString() == "") {
		QDateTime now = QDateTime::currentDateTime();
		now = now.addDays(1);
		metaData.setExpirationDate(now);
		mNetworkDiskCache->updateMetaData(metaData);
		qDebug() << "EXPIRES : " << metaData.expirationDate().toString();
	}

 You also need to know if a ListView listitem is initialized, so in the ListItemComponent where the WebImageView lives i did

WebImageView {
            verticalAlignment: VerticalAlignment.Fill
            horizontalAlignment: HorizontalAlignment.Fill
            id: webImage
            visible: loading == 1.0
            imageSource: ListItem.initialized ? "http://.../image.jpg": ""
        }

Finally in the WebImageVIew::setUrl use this code. In this way you don't fire a http request if the url is ""

	if (url.toString() == "") {
		resetImage();
		emit urlChanged();
		return;
	}