Skip to content

Commit 469681b

Browse files
authored
ci: add rps format scripts and spotless checks (#1099)
1 parent 71870d8 commit 469681b

34 files changed

Lines changed: 1156 additions & 1016 deletions

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
- name: Static Analysis
2323
run: flutter analyze
2424

25-
- name: Ensure the Dart code is formatted correctly
26-
run: dart format --set-exit-if-changed --output=none .
25+
- name: Setup Clang
26+
uses: OneSignal/sdk-actions/.github/actions/setup-clang@main
27+
28+
- name: Check formatting (dart,java,c)
29+
run: dart run rps format-check
2730

2831
- name: Run Flutter unit tests
2932
run: dart run rps test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.dart_tool/
3+
.gradle/
34

45
.packages
56
.pub/

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
analyzer:
2+
exclude:
3+
- test/dlcov_references_test.dart

android/src/main/java/com/onesignal/flutter/FlutterMessengerResponder.java

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,72 @@
33
import android.content.Context;
44
import android.os.Handler;
55
import android.os.Looper;
6-
7-
import java.util.HashMap;
8-
96
import io.flutter.plugin.common.BinaryMessenger;
107
import io.flutter.plugin.common.MethodChannel;
8+
import java.util.HashMap;
119

1210
abstract class FlutterMessengerResponder {
13-
Context context;
14-
protected MethodChannel channel;
15-
BinaryMessenger messenger;
11+
Context context;
12+
protected MethodChannel channel;
13+
BinaryMessenger messenger;
1614

17-
/**
18-
* MethodChannel class is home to success() method used by Result class
19-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
20-
* This will communicate success back to Dart
21-
*/
22-
void replySuccess(final MethodChannel.Result reply, final Object response) {
23-
runOnMainThread(new Runnable() {
24-
@Override
25-
public void run() {
26-
reply.success(response);
27-
}
28-
});
29-
}
15+
/**
16+
* MethodChannel class is home to success() method used by Result class
17+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
18+
* This will communicate success back to Dart
19+
*/
20+
void replySuccess(final MethodChannel.Result reply, final Object response) {
21+
runOnMainThread(new Runnable() {
22+
@Override
23+
public void run() {
24+
reply.success(response);
25+
}
26+
});
27+
}
3028

31-
/**
32-
* MethodChannel class is home to error() method used by Result class
33-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
34-
* This will communicate error back to Dart
35-
*/
36-
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
37-
runOnMainThread(new Runnable() {
38-
@Override
39-
public void run() {
40-
reply.error(tag, message, response);
41-
}
42-
});
43-
}
29+
/**
30+
* MethodChannel class is home to error() method used by Result class
31+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
32+
* This will communicate error back to Dart
33+
*/
34+
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
35+
runOnMainThread(new Runnable() {
36+
@Override
37+
public void run() {
38+
reply.error(tag, message, response);
39+
}
40+
});
41+
}
4442

45-
/**
46-
* MethodChannel class is home to notImplemented() method used by Result class
47-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
48-
* This will communicate not implemented back to Dart
49-
*/
50-
void replyNotImplemented(final MethodChannel.Result reply) {
51-
runOnMainThread(new Runnable() {
52-
@Override
53-
public void run() {
54-
reply.notImplemented();
55-
}
56-
});
57-
}
43+
/**
44+
* MethodChannel class is home to notImplemented() method used by Result class
45+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
46+
* This will communicate not implemented back to Dart
47+
*/
48+
void replyNotImplemented(final MethodChannel.Result reply) {
49+
runOnMainThread(new Runnable() {
50+
@Override
51+
public void run() {
52+
reply.notImplemented();
53+
}
54+
});
55+
}
5856

59-
private void runOnMainThread(final Runnable runnable) {
60-
if (Looper.getMainLooper().getThread() == Thread.currentThread())
61-
runnable.run();
62-
else {
63-
Handler handler = new Handler(Looper.getMainLooper());
64-
handler.post(runnable);
65-
}
66-
}
57+
private void runOnMainThread(final Runnable runnable) {
58+
if (Looper.getMainLooper().getThread() == Thread.currentThread()) runnable.run();
59+
else {
60+
Handler handler = new Handler(Looper.getMainLooper());
61+
handler.post(runnable);
62+
}
63+
}
6764

68-
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
69-
//final MethodChannel channel = this.channel;
70-
runOnMainThread(new Runnable() {
71-
@Override
72-
public void run() {
73-
channel.invokeMethod(methodName, map);
74-
}
75-
});
76-
}
65+
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
66+
// final MethodChannel channel = this.channel;
67+
runOnMainThread(new Runnable() {
68+
@Override
69+
public void run() {
70+
channel.invokeMethod(methodName, map);
71+
}
72+
});
73+
}
7774
}

android/src/main/java/com/onesignal/flutter/OneSignalDebug.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import com.onesignal.OneSignal;
44
import com.onesignal.debug.LogLevel;
5-
65
import io.flutter.plugin.common.BinaryMessenger;
76
import io.flutter.plugin.common.MethodCall;
87
import io.flutter.plugin.common.MethodChannel;
98
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
109
import io.flutter.plugin.common.MethodChannel.Result;
1110

1211
public class OneSignalDebug extends FlutterMessengerResponder implements MethodCallHandler {
13-
14-
static void registerWith(BinaryMessenger messenger) {
12+
13+
static void registerWith(BinaryMessenger messenger) {
1514
OneSignalDebug controller = new OneSignalDebug();
1615
controller.messenger = messenger;
1716
controller.channel = new MethodChannel(messenger, "OneSignal#debug");
@@ -20,12 +19,9 @@ static void registerWith(BinaryMessenger messenger) {
2019

2120
@Override
2221
public void onMethodCall(MethodCall call, Result result) {
23-
if (call.method.contentEquals("OneSignal#setLogLevel"))
24-
this.setLogLevel(call, result);
25-
else if (call.method.contentEquals("OneSignal#setAlertLevel"))
26-
this.setAlertLevel(call, result);
27-
else
28-
replyNotImplemented(result);
22+
if (call.method.contentEquals("OneSignal#setLogLevel")) this.setLogLevel(call, result);
23+
else if (call.method.contentEquals("OneSignal#setAlertLevel")) this.setAlertLevel(call, result);
24+
else replyNotImplemented(result);
2925
}
3026

3127
private void setLogLevel(MethodCall call, Result reply) {
@@ -34,21 +30,19 @@ private void setLogLevel(MethodCall call, Result reply) {
3430
LogLevel consoleLogLevel = LogLevel.fromInt(console);
3531
OneSignal.getDebug().setLogLevel(consoleLogLevel);
3632
replySuccess(reply, null);
37-
}
38-
catch(ClassCastException e) {
33+
} catch (ClassCastException e) {
3934
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
40-
}
35+
}
4136
}
4237

43-
private void setAlertLevel(MethodCall call, Result reply) {
38+
private void setAlertLevel(MethodCall call, Result reply) {
4439
try {
4540
int visual = call.argument("visualLevel");
4641
LogLevel visualLogLevel = LogLevel.fromInt(visual);
4742
OneSignal.getDebug().setAlertLevel(visualLogLevel);
4843
replySuccess(reply, null);
49-
}
50-
catch(ClassCastException e) {
44+
} catch (ClassCastException e) {
5145
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
52-
}
46+
}
5347
}
5448
}

0 commit comments

Comments
 (0)