Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
reverting from Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitandroid committed May 19, 2017
1 parent 40e8cc5 commit 5f045e3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ android {
}
productFlavors {
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

buildscript {
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public void doOnBackground() {
Log.d(Salut.TAG, "Registered Host | " + salutInstance.registeredHost.deviceName);

salutInstance.thisDevice.isRegistered = true;
new Handler(Looper.getMainLooper()).post(() -> {
if (onRegistered != null)
onRegistered.call();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (onRegistered != null)
onRegistered.call();
}
});

salutInstance.startListeningForData();
Expand All @@ -82,7 +85,12 @@ public void doOnBackground() {
salutInstance.disconnectFromDevice();

if (onUnregisterSuccess != null) { //Success Callback.
new Handler(Looper.getMainLooper()).post(() -> onUnregisterSuccess.call());
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
onUnregisterSuccess.call();
}
});
}

Log.d(Salut.TAG, "This device has successfully been unregistered from the server.");
Expand All @@ -96,11 +104,14 @@ public void doOnBackground() {
ex.printStackTrace();

Log.e(Salut.TAG, "An error occurred while attempting to register or unregister.");
new Handler(Looper.getMainLooper()).post(() -> {
if (onRegistrationFail != null && !salutInstance.thisDevice.isRegistered) //Prevents both callbacks from being called.
onRegistrationFail.call();
if (onUnregisterFailure != null)
onUnregisterFailure.call();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (onRegistrationFail != null && !salutInstance.thisDevice.isRegistered) //Prevents both callbacks from being called.
onRegistrationFail.call();
if (onUnregisterFailure != null)
onUnregisterFailure.call();
}
});

if (salutInstance.thisDevice.isRegistered && salutInstance.isConnectedToAnotherDevice) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/peak/salut/BackgroundDataJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public void doOnBackground() {

if (!data.isEmpty()) {
new Handler(Looper.getMainLooper()).post(
() -> salutInstance.dataReceiver.dataCallback.onDataReceived(data));
new Runnable() {
@Override
public void run() {
salutInstance.dataReceiver.dataCallback.onDataReceived(data);
}
});
}
} catch (Exception ex) {
Log.e(Salut.TAG, "An error occurred while trying to receive data.");
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public void doOnBackground() {

if (salutInstance.onDeviceRegisteredWithHost != null) {
new Handler(Looper.getMainLooper()).post(
() -> salutInstance.onDeviceRegisteredWithHost.call(finalDevice));
new Runnable() {
@Override
public void run() {
salutInstance.onDeviceRegisteredWithHost.call(finalDevice);
}
});
}

} else {
Expand All @@ -63,16 +68,22 @@ public void doOnBackground() {
toClient.writeUTF(Salut.UNREGISTER_CODE);
toClient.flush();

salutInstance.registeredClients.stream().filter(
registered -> registered.serviceAddress.equals(clientSocket.getInetAddress()
.toString().replace("/", ""))).forEach(registered -> {
salutInstance.registeredClients.remove(registered);
if (salutInstance.onDeviceUnregistered != null) {
new Handler(Looper.getMainLooper()).post(
() -> salutInstance.onDeviceUnregistered.call(registered));
for (final SalutDevice registered : salutInstance.registeredClients) {
if (registered.serviceAddress.equals(clientSocket.getInetAddress()
.toString().replace("/", ""))) {
salutInstance.registeredClients.remove(registered);
if (salutInstance.onDeviceUnregistered != null) {
new Handler(Looper.getMainLooper()).post(
new Runnable() {
@Override
public void run() {
salutInstance.onDeviceUnregistered.call(registered);
}
});
}
Log.d(Salut.TAG, "\nSuccesfully unregistered device.\n");
}
Log.d(Salut.TAG, "\nSuccesfully unregistered device.\n");
});
}
}

fromClient.close();
Expand Down

0 comments on commit 5f045e3

Please sign in to comment.