From c06b9a48351859ddf63a649c220499cafe7d8e8b Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 13 Nov 2020 17:39:24 -0800 Subject: [PATCH] fix tiny list item due to missing thumbnail When thumbnail was required but couldn't be produced list item showed up tiny as height followed thumbnail's. Instead, when there's no thumbnail behave as if it's disabled, a layout that looks ok. --- .../eehouse/android/xw4/BoardDelegate.java | 2 +- .../org/eehouse/android/xw4/GameListItem.java | 46 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 2ff0e0b05..7b1c968b7 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -1,6 +1,6 @@ /* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */ /* - * Copyright 2009 - 2019 by Eric House (xwords@eehouse.org). All rights + * Copyright 2009 - 2020 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java index 1c223e2be..1b26688aa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java @@ -1,6 +1,6 @@ /* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */ /* - * Copyright 2009-2012 by Eric House (xwords@eehouse.org). All rights + * Copyright 2009-2020 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -56,7 +56,8 @@ public class GameListItem extends LinearLayout private boolean m_loaded; private long m_rowid; private View m_hideable; - private ImageView m_thumb; + private ImageView mThumbView; + private Bitmap mThumb; private ExpiringTextView m_name; private TextView m_viewUnloaded; private View m_viewLoaded; @@ -211,8 +212,8 @@ public class GameListItem extends LinearLayout m_state = (TextView)findViewById( R.id.state ); m_modTime = (TextView)findViewById( R.id.modtime ); m_gameTypeImage = (ImageView)findViewById( R.id.game_type_marker ); - m_thumb = (ImageView)findViewById( R.id.thumbnail ); - m_thumb.setOnClickListener( this ); + mThumbView = (ImageView)findViewById( R.id.thumbnail ); + mThumbView.setOnClickListener( this ); m_role = (TextView)findViewById( R.id.role ); findViewById( R.id.right_side ).setOnClickListener( this ); @@ -238,9 +239,15 @@ public class GameListItem extends LinearLayout m_expandButton.setExpanded( m_expanded ); m_hideable.setVisibility( m_expanded? View.VISIBLE : View.GONE ); - int vis = m_expanded && XWPrefs.getThumbEnabled( m_context ) - ? View.VISIBLE : View.GONE; - m_thumb.setVisibility( vis ); + boolean showThumb = null != mThumb + && XWPrefs.getThumbEnabled( m_context ) + && m_expanded; + if ( showThumb ) { + mThumbView.setVisibility( View.VISIBLE ); + mThumbView.setImageBitmap( mThumb ); + } else { + mThumbView.setVisibility( View.GONE ); + } m_name.setBackgroundColor( android.R.color.transparent ); m_name.setPct( m_handler, m_haveTurn && !m_expanded, @@ -490,7 +497,6 @@ public class GameListItem extends LinearLayout } long m_rowid; GameListItem m_item; - int m_nTries = 0; } private static LinkedBlockingQueue s_queue = new LinkedBlockingQueue<>(); @@ -515,14 +521,9 @@ public class GameListItem extends LinearLayout public void run() { for ( ; ; ) { - ThumbQueueElem elem; + final ThumbQueueElem elem; try { elem = s_queue.take(); - if ( 0 < elem.m_nTries ) { - // This is a second pass. give whatever caused - // failure time to go away - Thread.sleep(200); - } } catch ( InterruptedException ie ) { Log.w( TAG, "interrupted; killing s_thumbThread" ); break; @@ -535,19 +536,14 @@ public class GameListItem extends LinearLayout thumb = GameUtils.loadMakeBitmap( activity, rowid ); } - if ( null == thumb ) { - if ( ++elem.m_nTries < 3 ) { - s_queue.add( elem ); - } - } else { - final GameListItem item = elem.m_item; - final Bitmap ft = thumb; + if ( null != thumb ) { + final Bitmap fThumb = thumb; activity.runOnUiThread( new Runnable() { + @Override public void run() { - ImageView iview = item.m_thumb; - if ( null != iview ) { - iview.setImageBitmap( ft ); - } + GameListItem item = elem.m_item; + item.mThumb = fThumb; + item.showHide(); } }); }