Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ jobs:
- name: Static Analysis
run: flutter analyze

- name: Ensure the Dart code is formatted correctly
run: dart format --set-exit-if-changed --output=none .
- name: Setup Clang
uses: OneSignal/sdk-actions/.github/actions/setup-clang@main

- name: Check formatting (dart,java,c)
run: dart run rps format-check

- name: Run Flutter unit tests
run: dart run rps test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.dart_tool/
.gradle/

.packages
.pub/
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
exclude:
- test/dlcov_references_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,72 @@
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import java.util.HashMap;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import java.util.HashMap;

abstract class FlutterMessengerResponder {
Context context;
protected MethodChannel channel;
BinaryMessenger messenger;
Context context;
protected MethodChannel channel;
BinaryMessenger messenger;

/**
* MethodChannel class is home to success() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate success back to Dart
*/
void replySuccess(final MethodChannel.Result reply, final Object response) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.success(response);
}
});
}
/**
* MethodChannel class is home to success() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate success back to Dart
*/
void replySuccess(final MethodChannel.Result reply, final Object response) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.success(response);
}
});
}

/**
* MethodChannel class is home to error() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate error back to Dart
*/
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.error(tag, message, response);
}
});
}
/**
* MethodChannel class is home to error() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate error back to Dart
*/
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.error(tag, message, response);
}
});
}

/**
* MethodChannel class is home to notImplemented() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate not implemented back to Dart
*/
void replyNotImplemented(final MethodChannel.Result reply) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.notImplemented();
}
});
}
/**
* MethodChannel class is home to notImplemented() method used by Result class
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
* This will communicate not implemented back to Dart
*/
void replyNotImplemented(final MethodChannel.Result reply) {
runOnMainThread(new Runnable() {
@Override
public void run() {
reply.notImplemented();
}
});
}

private void runOnMainThread(final Runnable runnable) {
if (Looper.getMainLooper().getThread() == Thread.currentThread())
runnable.run();
else {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(runnable);
}
}
private void runOnMainThread(final Runnable runnable) {
if (Looper.getMainLooper().getThread() == Thread.currentThread()) runnable.run();
else {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(runnable);
}
}

void invokeMethodOnUiThread(final String methodName, final HashMap map) {
//final MethodChannel channel = this.channel;
runOnMainThread(new Runnable() {
@Override
public void run() {
channel.invokeMethod(methodName, map);
}
});
}
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
// final MethodChannel channel = this.channel;
runOnMainThread(new Runnable() {
@Override
public void run() {
channel.invokeMethod(methodName, map);
}
});
}
}
26 changes: 10 additions & 16 deletions android/src/main/java/com/onesignal/flutter/OneSignalDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import com.onesignal.OneSignal;
import com.onesignal.debug.LogLevel;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;

public class OneSignalDebug extends FlutterMessengerResponder implements MethodCallHandler {
static void registerWith(BinaryMessenger messenger) {

static void registerWith(BinaryMessenger messenger) {
OneSignalDebug controller = new OneSignalDebug();
controller.messenger = messenger;
controller.channel = new MethodChannel(messenger, "OneSignal#debug");
Expand All @@ -20,12 +19,9 @@ static void registerWith(BinaryMessenger messenger) {

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.contentEquals("OneSignal#setLogLevel"))
this.setLogLevel(call, result);
else if (call.method.contentEquals("OneSignal#setAlertLevel"))
this.setAlertLevel(call, result);
else
replyNotImplemented(result);
if (call.method.contentEquals("OneSignal#setLogLevel")) this.setLogLevel(call, result);
else if (call.method.contentEquals("OneSignal#setAlertLevel")) this.setAlertLevel(call, result);
else replyNotImplemented(result);
}

private void setLogLevel(MethodCall call, Result reply) {
Expand All @@ -34,21 +30,19 @@ private void setLogLevel(MethodCall call, Result reply) {
LogLevel consoleLogLevel = LogLevel.fromInt(console);
OneSignal.getDebug().setLogLevel(consoleLogLevel);
replySuccess(reply, null);
}
catch(ClassCastException e) {
} catch (ClassCastException e) {
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
}
}
}

private void setAlertLevel(MethodCall call, Result reply) {
private void setAlertLevel(MethodCall call, Result reply) {
try {
int visual = call.argument("visualLevel");
LogLevel visualLogLevel = LogLevel.fromInt(visual);
OneSignal.getDebug().setAlertLevel(visualLogLevel);
replySuccess(reply, null);
}
catch(ClassCastException e) {
} catch (ClassCastException e) {
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
}
}
}
}
Loading