-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #687 from mes-indesign/fix/419
Fix out-of-order notifications on Android
- Loading branch information
Showing
4 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Inspiration taken from cordova-plugin-ble-central | ||
|
||
package com.randdusing.bluetoothle; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.PluginResult; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.json.JSONObject; | ||
|
||
public class SequentialCallbackContext { | ||
private int sequence; | ||
private CallbackContext context; | ||
|
||
public SequentialCallbackContext(CallbackContext context) { | ||
this.context = context; | ||
this.sequence = 0; | ||
} | ||
|
||
private int getNextSequenceNumber() { | ||
synchronized(this) { | ||
return this.sequence++; | ||
} | ||
} | ||
|
||
public CallbackContext getContext() { | ||
return this.context; | ||
} | ||
|
||
public PluginResult createSequentialResult(JSONObject returnObj) { | ||
List<PluginResult> resultList = new ArrayList<PluginResult>(2); | ||
|
||
PluginResult dataResult = new PluginResult(PluginResult.Status.OK, returnObj); | ||
PluginResult sequenceResult = new PluginResult(PluginResult.Status.OK, this.getNextSequenceNumber()); | ||
|
||
resultList.add(dataResult); | ||
resultList.add(sequenceResult); | ||
|
||
return new PluginResult(PluginResult.Status.OK, resultList); | ||
} | ||
|
||
public void sendSequentialResult(JSONObject returnObj) { | ||
PluginResult result = this.createSequentialResult(returnObj); | ||
result.setKeepCallback(true); | ||
|
||
this.context.sendPluginResult(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters