Skip to content

Commit

Permalink
* get rid of onStopped overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ink committed Apr 6, 2024
1 parent b1cee95 commit 5b43d76
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public void onConnectionLost(@Nullable String error) {
Toast.LENGTH_LONG).show();
stopSelf(); // do not restart for now
}

@Override
public void onShutdown() {
// already stopped in onConnectionLost
}
});
} else {
mLiveCard.navigate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.concurrent.LinkedBlockingDeque;


public abstract class BluetoothHost implements IRPCHost {
public class BluetoothHost implements IRPCHost {

private static final String NAME = "AnotherGlass";
private static final String TAG = "GlassHost";
Expand Down Expand Up @@ -69,10 +69,10 @@ public void stop() {
}
}

@Override
@CallSuper
public void onStopped() {
private void onStopped() {
mQueue.clear();
mHandler.onShutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ public void onConnectionLost(@Nullable String error) {
mGPS.stop();
mNotifications.stop();
}
}) {

@Override
public void onStopped() {
super.onStopped();
log.i(TAG, "BluetoothClient has stopped, terminating GlassService");
Toast.makeText(GlassService.this, "BluetoothClient has stopped, terminating GlassService", Toast.LENGTH_SHORT).show();
public void onShutdown() {
log.i(TAG, "BluetoothHost has stopped, terminating GlassService");
Toast.makeText(GlassService.this, "BluetoothHost has stopped, terminating GlassService", Toast.LENGTH_SHORT).show();
stopSelf();
}
};
});

mNotifications = new NotificationExtension(this);
mGPS = new GPSExtension(this);
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android {
}

dependencies {
implementation "androidx.annotation:annotation:1.7.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ public interface IRPCHost {
void start(Context context);
void send(RPCMessage message);
void stop();
@CallSuper
void onStopped();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


public class RPCHandler extends Handler implements RPCMessageListener {
Expand All @@ -15,10 +16,10 @@ public class RPCHandler extends Handler implements RPCMessageListener {
private static final int STATE_CONNECTION_LOST = 1;
private static final int STATE_WAITING_FOR_CONNECT = 2;
private static final int MSG_DATA_RECEIVED = 3;
private static final int MSG_ON_SHUTDOWN = 4;

private static final String TAG = "RPCHandler";


public RPCHandler(RPCMessageListener listener) {
super(Looper.getMainLooper());
this.listener = listener;
Expand All @@ -40,6 +41,8 @@ public void handleMessage(Message msg) {
listener.onConnectionLost(error);
} else if (STATE_WAITING_FOR_CONNECT == msg.what) {
listener.onWaiting();
} else if (MSG_ON_SHUTDOWN == msg.what) {
listener.onShutdown();
}
}

Expand All @@ -59,7 +62,12 @@ public void onDataReceived(@NonNull RPCMessage data) {
}

@Override
public void onConnectionLost(/*@Nullable*/ String error) {
public void onConnectionLost(@Nullable String error) {
obtainMessage(RPCHandler.STATE_CONNECTION_LOST, error).sendToTarget();
}

@Override
public void onShutdown() {
obtainMessage(RPCHandler.MSG_ON_SHUTDOWN).sendToTarget();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface RPCMessageListener {
void onDataReceived(@NonNull RPCMessage data);

void onConnectionLost(@Nullable String error);

void onShutdown();
}

0 comments on commit 5b43d76

Please sign in to comment.