Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 336b804

Browse files
authored
support v2 and multiple plgd instances (#32)
1 parent 06736f6 commit 336b804

File tree

84 files changed

+1328
-1142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1328
-1142
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
3232
}
3333

3434
android {
35-
compileSdkVersion 29
35+
compileSdkVersion 30
3636

3737
sourceSets {
3838
main.java.srcDirs += 'src/main/kotlin'
@@ -45,7 +45,7 @@ android {
4545
defaultConfig {
4646
applicationId "dev.plgd.client"
4747
minSdkVersion 17
48-
targetSdkVersion 29
48+
targetSdkVersion 30
4949
versionCode flutterVersionCode.toInteger()
5050
versionName flutterVersionName
5151
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

android/app/src/main/kotlin/dev/plgd/mobile/MainActivity.kt

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import kotlinx.coroutines.withContext
1313

1414
class MainActivity: FlutterActivity() {
1515
private val CHANNEL = "plgd.dev/client"
16-
private var sdkClient: ocfclient.Ocfclient_? = null;
16+
private var sdkClient: Ocfclient.Ocfclient_? = null;
1717
private val _mainScope = CoroutineScope(Dispatchers.Main)
1818

1919
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
2020
GeneratedPluginRegistrant.registerWith(flutterEngine)
2121
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
2222
when (call.method) {
2323
"initialize" -> this.initializeOCFClient(call, result)
24+
"close" -> this.closeOCFClient(result)
25+
"getOwnerId" -> this.getOwnerId(result)
2426
"discoverDevices" -> this.discoverDevices(call, result)
27+
"getResource" -> this.getResource(call, result)
2528
"ownDevice" -> this.ownDevice(call, result)
2629
"setAccessForCloud" -> this.setAccessForCloud(call, result)
2730
"onboardDevice" -> this.onboardDevice(call, result)
@@ -34,11 +37,12 @@ class MainActivity: FlutterActivity() {
3437
private fun initializeOCFClient(call: MethodCall, result: MethodChannel.Result) {
3538
var accessToken = call.argument<String>("accessToken");
3639
var cloudConfiguration = call.argument<String>("cloudConfiguration")
40+
var signingServerAddress = call.argument<String>("signingServerAddress")
3741
_mainScope.launch {
3842
try {
39-
sdkClient = ocfclient.Ocfclient_()
43+
sdkClient = Ocfclient.Ocfclient_()
4044
withContext(Dispatchers.IO) {
41-
sdkClient!!.initialize(accessToken, cloudConfiguration)
45+
sdkClient!!.initialize(accessToken, cloudConfiguration, signingServerAddress)
4246
}
4347
result.success(true)
4448
} catch (e: Exception) {
@@ -48,6 +52,32 @@ class MainActivity: FlutterActivity() {
4852
}
4953
}
5054

55+
private fun closeOCFClient(result: MethodChannel.Result) {
56+
_mainScope.launch {
57+
try {
58+
withContext(Dispatchers.IO) {
59+
sdkClient!!.close()
60+
}
61+
result.success(true)
62+
} catch (e: Exception) {
63+
result.error("-1", e.message, "")
64+
}
65+
}
66+
}
67+
68+
private fun getOwnerId(result: MethodChannel.Result) {
69+
_mainScope.launch {
70+
try {
71+
var ownerId = withContext(Dispatchers.IO) {
72+
sdkClient!!.getOwnerID()
73+
}
74+
result.success(ownerId)
75+
} catch (e: Exception) {
76+
result.error("-1", e.message, "")
77+
}
78+
}
79+
}
80+
5181
private fun discoverDevices(call: MethodCall, result: MethodChannel.Result) {
5282
var discoveryTimeout = call.arguments<Int>()
5383
_mainScope.launch {
@@ -62,6 +92,21 @@ class MainActivity: FlutterActivity() {
6292
}
6393
}
6494

95+
private fun getResource(call: MethodCall, result: MethodChannel.Result) {
96+
var deviceId = call.argument<String>("deviceID")
97+
var href = call.argument<String>("href")
98+
_mainScope.launch {
99+
try {
100+
var resourceContent = withContext(Dispatchers.IO) {
101+
sdkClient!!.getResource(deviceId, href)
102+
}
103+
result.success(resourceContent)
104+
} catch (e: Exception) {
105+
result.error("-1", e.message, "")
106+
}
107+
}
108+
}
109+
65110
private fun ownDevice(call: MethodCall, result: MethodChannel.Result) {
66111
var deviceId = call.argument<String>("deviceID")
67112
var accessToken = call.argument<String>("accessToken")
@@ -94,10 +139,12 @@ class MainActivity: FlutterActivity() {
94139
private fun onboardDevice(call: MethodCall, result: MethodChannel.Result) {
95140
var deviceId = call.argument<String>("deviceID")
96141
var authCode = call.argument<String>("authCode")
142+
var authorizationProvider = call.argument<String>("authorizationProvider")
143+
97144
_mainScope.launch {
98145
try {
99146
withContext(Dispatchers.IO) {
100-
sdkClient!!.onboardDevice(deviceId, authCode)
147+
sdkClient!!.onboardDevice(deviceId, authCode, authorizationProvider)
101148
}
102149
result.success(true)
103150
} catch (e: Exception) {
-1.6 KB
Loading
1.26 KB
Loading
-841 Bytes
Loading
534 Bytes
Loading
-2.37 KB
Loading
2.86 KB
Loading
-3.93 KB
Loading
-3.73 KB
Loading

0 commit comments

Comments
 (0)