A couple tweaks to ensure clients are properly disconnected when the

device sleeps -- this prevents unnecessary auto-reconnects.
This commit is contained in:
casey langen 2017-02-16 09:32:48 -08:00
parent 2a7dbf4089
commit c8497f9524
4 changed files with 29 additions and 12 deletions

View File

@ -48,9 +48,15 @@ public class PlayQueueActivity extends WebSocketActivityBase {
}
@Override
protected void onDestroy() {
super.onDestroy();
this.tracks.destroy();
protected void onPause() {
super.onPause();
this.tracks.pause();
}
@Override
protected void onResume() {
this.tracks.resume(); /* needs to happen before */
super.onResume();
}
@Override

View File

@ -65,9 +65,15 @@ public class TrackListActivity extends WebSocketActivityBase implements Filterab
}
@Override
protected void onDestroy() {
super.onDestroy();
this.tracks.destroy();
protected void onPause() {
super.onPause();
this.tracks.pause();
}
@Override
protected void onResume() {
this.tracks.resume(); /* needs to happen before */
super.onResume();
}
@Override

View File

@ -52,9 +52,6 @@ public class TrackListScrollCache<TrackType> {
this.wss = wss;
this.queryFactory = queryFactory;
this.mapper = mapper;
this.recyclerView.addOnScrollListener(scrollListener);
this.wss.addClient(this.client);
}
public void requery() {
@ -72,11 +69,16 @@ public class TrackListScrollCache<TrackType> {
});
}
public void destroy() {
public void pause() {
this.recyclerView.removeOnScrollListener(scrollListener);
this.wss.removeClient(this.client);
}
public void resume() {
this.recyclerView.addOnScrollListener(scrollListener);
this.wss.addClient(this.client);
}
public void setInitialPosition(int initialIndex) {
this.initialPosition = initialIndex;
}

View File

@ -331,8 +331,11 @@ public class WebSocketService {
disconnect(autoReconnect);
handler.removeMessages(MESSAGE_AUTO_RECONNECT);
setState(State.Connecting);
thread = new ConnectThread();
thread.start();
if (this.clients.size() > 0) {
thread = new ConnectThread();
thread.start();
}
}
}