openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
599 stars 317 forks source link

Icons flash when sitemap is reloaded #541

Closed mueller-ma closed 6 years ago

mueller-ma commented 6 years ago

Navigate to any page in your sitemap and wait until some item changes. All icons in the sitemap flash.

Reported here: https://community.openhab.org/t/android-and-ios-2-0-releases/37405/3?u=mueller-ma

mueller-ma commented 6 years ago

One issue is that the whole sitemap is refreshed and not just the one item that changed.

lolodomo commented 6 years ago

Apparently not exactly the whole sitemap but only the updated pages. If you have 2 pages displayed, you can see the "flashing" only in the page that has to be refreshed.

ghost commented 6 years ago

Hey,

Just update UI elements if necessary.

You can't compare ImageURL information, because state sometimes contains random like information (/icon/time?state=3.0 or /icon/time?state=3.6, ...).

So compare the drawables itself (the new one and that from the cache).

Change your OpenHABWidgetAdapter adapter and replace:

widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword);

with

Drawable currentWidgetImageDrawable = widgetImage.getDrawable();
    WebImageCache webImageCache = MyWebImage.getWebImageCache(getContext());
    Bitmap cachedImageBitmap = webImageCache.get(iconUrl);
    Drawable cachedDrawable = new BitmapDrawable(getContext().getResources(), cachedImageBitmap);

    if (currentWidgetImageDrawable == null || ! currentWidgetImageDrawable.equals(cachedDrawable)) {
        widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon,
            openHABUsername, openHABPassword);
    }        

This will fix the flicker/flashing problem :)

Best regards, Mario Adamo