Only refresh the command recycler if we need to

Stephen Paul Weber created

Otherwise every UI refresh of any kind causes text boxes to lose focus.

Change summary

src/main/java/eu/siacs/conversations/entities/Conversation.java | 8 ++
1 file changed, 7 insertions(+), 1 deletion(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/Conversation.java 🔗

@@ -1769,6 +1769,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
                             if (mimeType.startsWith("image/") && "https".equals(uri.getScheme())) {
                                 final Drawable d = cache.get(uri.toString());
                                 if (d == null) {
+                                    synchronized (CommandSession.this) {
+                                        waitingForRefresh = true;
+                                    }
                                     int size = (int)(xmppConnectionService.getResources().getDisplayMetrics().density * 288);
                                     Message dummy = new Message(Conversation.this, uri.toString(), Message.ENCRYPTION_NONE);
                                     dummy.setFileParams(new Message.FileParams(uri.toString()));
@@ -2589,6 +2592,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
             protected WebView actionToWebview = null;
             protected int fillableFieldCount = 0;
             protected IqPacket pendingResponsePacket = null;
+            protected boolean waitingForRefresh = false;
 
             CommandSession(String title, String node, XmppConnectionService xmppConnectionService) {
                 loading();
@@ -3063,7 +3067,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
             }
 
             public void refresh() {
-                notifyDataSetChanged();
+                synchronized(this) {
+                    if (waitingForRefresh) notifyDataSetChanged();
+                }
             }
 
             protected void loading() {