Remove reconnect callback
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
package com.github.gotify.service;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import com.github.gotify.log.Log;
|
|
||||||
|
|
||||||
public class ReconnectListener extends BroadcastReceiver {
|
|
||||||
|
|
||||||
private Runnable reconnected;
|
|
||||||
|
|
||||||
ReconnectListener(Runnable reconnected) {
|
|
||||||
this.reconnected = reconnected;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
ConnectivityManager cm =
|
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
|
|
||||||
NetworkInfo network = cm.getActiveNetworkInfo();
|
|
||||||
|
|
||||||
if (network != null && network.isConnected()) {
|
|
||||||
Log.i("Network reconnected");
|
|
||||||
reconnected.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,6 @@ class WebSocketConnection {
|
|||||||
private OnNetworkFailureRunnable onNetworkFailure;
|
private OnNetworkFailureRunnable onNetworkFailure;
|
||||||
private Runnable onReconnected;
|
private Runnable onReconnected;
|
||||||
private State state;
|
private State state;
|
||||||
private Runnable onDisconnect;
|
|
||||||
|
|
||||||
WebSocketConnection(
|
WebSocketConnection(
|
||||||
String baseUrl,
|
String baseUrl,
|
||||||
@@ -84,11 +83,6 @@ class WebSocketConnection {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized WebSocketConnection onDisconnect(Runnable onDisconnect) {
|
|
||||||
this.onDisconnect = onDisconnect;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized WebSocketConnection onNetworkFailure(OnNetworkFailureRunnable onNetworkFailure) {
|
synchronized WebSocketConnection onNetworkFailure(OnNetworkFailureRunnable onNetworkFailure) {
|
||||||
this.onNetworkFailure = onNetworkFailure;
|
this.onNetworkFailure = onNetworkFailure;
|
||||||
return this;
|
return this;
|
||||||
@@ -224,8 +218,6 @@ class WebSocketConnection {
|
|||||||
NetworkInfo network = connectivityManager.getActiveNetworkInfo();
|
NetworkInfo network = connectivityManager.getActiveNetworkInfo();
|
||||||
if (network == null || !network.isConnected()) {
|
if (network == null || !network.isConnected()) {
|
||||||
Log.i("WebSocket(" + id + "): Network not connected");
|
Log.i("WebSocket(" + id + "): Network not connected");
|
||||||
onDisconnect.run();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int minutes = Math.min(errorCount * 2 - 1, 20);
|
int minutes = Math.min(errorCount * 2 - 1, 20);
|
||||||
|
|||||||
@@ -111,15 +111,12 @@ public class WebSocketService extends Service {
|
|||||||
.onBadRequest(this::onBadRequest)
|
.onBadRequest(this::onBadRequest)
|
||||||
.onNetworkFailure(
|
.onNetworkFailure(
|
||||||
(min) -> foreground(getString(R.string.websocket_failed, min)))
|
(min) -> foreground(getString(R.string.websocket_failed, min)))
|
||||||
.onDisconnect(this::onDisconnect)
|
|
||||||
.onMessage(this::onMessage)
|
.onMessage(this::onMessage)
|
||||||
.onReconnected(this::notifyMissedNotifications)
|
.onReconnected(this::notifyMissedNotifications)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
ReconnectListener receiver = new ReconnectListener(this::doReconnect);
|
|
||||||
registerReceiver(receiver, intentFilter);
|
|
||||||
|
|
||||||
picassoHandler.updateAppIds();
|
picassoHandler.updateAppIds();
|
||||||
}
|
}
|
||||||
@@ -142,10 +139,6 @@ public class WebSocketService extends Service {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDisconnect() {
|
|
||||||
foreground(getString(R.string.websocket_no_network));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doReconnect() {
|
private void doReconnect() {
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user