From 7905dc5e344ff7768599b66914d612267566b6df Mon Sep 17 00:00:00 2001 From: casey langen Date: Thu, 16 Feb 2017 17:01:38 -0800 Subject: [PATCH] Fixed a small bug in the TrackListScrollCache's state management. --- .../remote/TrackListScrollCache.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/TrackListScrollCache.java b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/TrackListScrollCache.java index 3b6a6baac..aa859e588 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/TrackListScrollCache.java +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/TrackListScrollCache.java @@ -21,6 +21,7 @@ public class TrackListScrollCache { private int scrollState = RecyclerView.SCROLL_STATE_IDLE; private int queryOffset = -1, queryLimit = -1; private int initialPosition = -1; + boolean connected = false; private static class CacheEntry { TrackType value; @@ -55,21 +56,24 @@ public class TrackListScrollCache { } public void requery() { - cancelMessages(); + if (connected) { + cancelMessages(); - final SocketMessage message = queryFactory.getRequeryMessage(); + final SocketMessage message = queryFactory.getRequeryMessage(); - wss.send(message, this.client, (SocketMessage response) -> { - setCount(response.getIntOption(Messages.Key.COUNT, 0)); + wss.send(message, this.client, (SocketMessage response) -> { + setCount(response.getIntOption(Messages.Key.COUNT, 0)); - if (initialPosition != -1) { - recyclerView.scrollToPosition(initialPosition); - initialPosition = -1; - } - }); + if (initialPosition != -1) { + recyclerView.scrollToPosition(initialPosition); + initialPosition = -1; + } + }); + } } public void pause() { + connected = false; this.recyclerView.removeOnScrollListener(scrollListener); this.wss.removeClient(this.client); } @@ -77,6 +81,7 @@ public class TrackListScrollCache { public void resume() { this.recyclerView.addOnScrollListener(scrollListener); this.wss.addClient(this.client); + connected = true; } public void setInitialPosition(int initialIndex) { @@ -118,6 +123,10 @@ public class TrackListScrollCache { } private void getPageAround(int index) { + if (!connected) { + return; + } + if (index >= queryOffset && index <= queryOffset + queryLimit) { return; /* already in flight */ }