Skip to content

Commit 556e81e

Browse files
committed
test
1 parent 5aa67b8 commit 556e81e

8 files changed

Lines changed: 144 additions & 95 deletions

File tree

.github/workflows/code-analysis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ jobs:
128128

129129
# Statically analyze the Dart code for any errors.
130130
- run: flutter analyze .
131+
132+
# Statically analyze Kotlin code (e.g. google_mlkit_commons Android) with ktlint.
133+
- name: Install ktlint
134+
run: brew install ktlint
135+
- name: Run ktlint on Kotlin code
136+
run: ktlint

packages/example/android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ android {
3333
}
3434

3535
aaptOptions {
36-
noCompress("tflite") // Your model's file extension: "tflite", "lite", etc.
36+
noCompress("tflite") // Your model's file extension: "tflite", "lite", etc.
3737
}
3838
}
3939

packages/example/android/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ allprojects {
55
}
66
}
77

8-
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
8+
val newBuildDir: Directory =
9+
rootProject.layout.buildDirectory
10+
.dir("../../build")
11+
.get()
912
rootProject.layout.buildDirectory.value(newBuildDir)
1013

1114
subprojects {

packages/example/android/settings.gradle.kts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
pluginManagement {
2-
val flutterSdkPath = run {
3-
val properties = java.util.Properties()
4-
file("local.properties").inputStream().use { properties.load(it) }
5-
val flutterSdkPath = properties.getProperty("flutter.sdk")
6-
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
7-
flutterSdkPath
8-
}
2+
val flutterSdkPath =
3+
run {
4+
val properties = java.util.Properties()
5+
file("local.properties").inputStream().use { properties.load(it) }
6+
val flutterSdkPath = properties.getProperty("flutter.sdk")
7+
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
8+
flutterSdkPath
9+
}
910

1011
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
1112

packages/google_mlkit_commons/android/src/main/kotlin/com/google_mlkit_commons/GenericModelManager.kt

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import io.flutter.plugin.common.MethodChannel
88
import java.lang.reflect.Method
99

1010
class GenericModelManager {
11-
12-
interface CheckModelIsDownloadedCallback {
11+
interface CheckModelIsDownloadedCallback {
1312
fun onCheckResult(isDownloaded: Boolean?)
13+
1414
fun onError(e: Exception)
1515
}
1616

@@ -22,7 +22,11 @@ class GenericModelManager {
2222
private const val CHECK = "check"
2323
}
2424

25-
fun manageModel(model: RemoteModel, call: MethodCall, result: MethodChannel.Result) {
25+
fun manageModel(
26+
model: RemoteModel,
27+
call: MethodCall,
28+
result: MethodChannel.Result,
29+
) {
2630
val task: String? = call.argument("task")
2731

2832
if (task == null) {
@@ -33,87 +37,103 @@ class GenericModelManager {
3337
when (task) {
3438
DOWNLOAD -> {
3539
val isWifiReqRequired: Boolean = call.argument("wifi") ?: false
36-
val downloadConditions = if (isWifiReqRequired) {
37-
DownloadConditions.Builder().requireWifi().build()
38-
} else {
39-
DownloadConditions.Builder().build()
40-
}
40+
val downloadConditions =
41+
if (isWifiReqRequired) {
42+
DownloadConditions.Builder().requireWifi().build()
43+
} else {
44+
DownloadConditions.Builder().build()
45+
}
4146
downloadModel(model, downloadConditions, result)
4247
}
4348

44-
DELETE -> deleteModel(model, result)
45-
CHECK -> isModelDownloaded(
46-
model,
47-
object: CheckModelIsDownloadedCallback {
48-
override fun onCheckResult (isDownloaded: Boolean?) {
49-
result.success(isDownloaded)
50-
}
49+
DELETE -> {
50+
deleteModel(model, result)
51+
}
5152

52-
override fun onError(e: Exception) {
53-
result.error("error", e.toString(), null)
54-
}
55-
}
56-
)
57-
else -> result.notImplemented()
53+
CHECK -> {
54+
isModelDownloaded(
55+
model,
56+
object : CheckModelIsDownloadedCallback {
57+
override fun onCheckResult(isDownloaded: Boolean?) {
58+
result.success(isDownloaded)
59+
}
60+
61+
override fun onError(e: Exception) {
62+
result.error("error", e.toString(), null)
63+
}
64+
},
65+
)
66+
}
67+
68+
else -> {
69+
result.notImplemented()
70+
}
5871
}
5972
}
6073

61-
fun downloadModel (
74+
fun downloadModel(
6275
remoteModel: RemoteModel,
6376
downloadConditions: DownloadConditions,
64-
result: MethodChannel.Result
77+
result: MethodChannel.Result,
6578
) {
6679
isModelDownloaded(
6780
remoteModel,
68-
object: CheckModelIsDownloadedCallback {
81+
object : CheckModelIsDownloadedCallback {
6982
override fun onCheckResult(isDownloaded: Boolean?) {
7083
if (isDownloaded == true) {
7184
result.success("success")
7285
return
7386
}
7487

75-
remoteModelManager.download(remoteModel, downloadConditions)
88+
remoteModelManager
89+
.download(remoteModel, downloadConditions)
7690
.addOnSuccessListener { result.success("success") }
77-
.addOnFailureListener { exception -> result.error("error", exception.toString(), null) }
78-
91+
.addOnFailureListener { exception -> result.error("error", exception.toString(), null) }
7992
}
8093

8194
override fun onError(e: Exception) {
8295
result.error("error", e.toString(), null)
8396
}
84-
}
97+
},
8598
)
8699
}
87100

88-
89-
fun isModelDownloaded (model: RemoteModel, callback: CheckModelIsDownloadedCallback) {
101+
fun isModelDownloaded(
102+
model: RemoteModel,
103+
callback: CheckModelIsDownloadedCallback,
104+
) {
90105
try {
91-
remoteModelManager.isModelDownloaded(model)
92-
.addOnFailureListener { exception -> callback.onError(exception) }
106+
remoteModelManager
107+
.isModelDownloaded(model)
108+
.addOnFailureListener { exception -> callback.onError(exception) }
93109
.addOnSuccessListener { isModelDownloaded -> callback.onCheckResult(isModelDownloaded) }
94110
} catch (e: Exception) {
95111
callback.onError(e)
96112
}
97113
}
98114

99-
fun deleteModel(remoteModel: RemoteModel, result: MethodChannel.Result) {
115+
fun deleteModel(
116+
remoteModel: RemoteModel,
117+
result: MethodChannel.Result,
118+
) {
100119
isModelDownloaded(
101120
remoteModel,
102-
object: CheckModelIsDownloadedCallback {
121+
object : CheckModelIsDownloadedCallback {
103122
override fun onCheckResult(isDownloaded: Boolean?) {
104123
if (isDownloaded != true) {
105124
result.success("success")
106125
return
107126
}
108-
remoteModelManager.deleteDownloadedModel(remoteModel)
127+
remoteModelManager
128+
.deleteDownloadedModel(remoteModel)
109129
.addOnSuccessListener { result.success("success") }
110-
.addOnFailureListener { exception -> result.error("error", exception.toString(), null) }
130+
.addOnFailureListener { exception -> result.error("error", exception.toString(), null) }
111131
}
112132

113133
override fun onError(e: Exception) {
114134
result.error("error", e.toString(), null)
115135
}
116-
}
136+
},
117137
)
118138
}
119139
}

packages/google_mlkit_commons/android/src/main/kotlin/com/google_mlkit_commons/GoogleMlKitCommonsPlugin.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
44
import io.flutter.plugin.common.MethodCall
55
import io.flutter.plugin.common.MethodChannel
66

7-
class GoogleMlKitCommonsPlugin: FlutterPlugin, MethodChannel.MethodCallHandler {
7+
class GoogleMlKitCommonsPlugin :
8+
FlutterPlugin,
9+
MethodChannel.MethodCallHandler {
810
private lateinit var channel: MethodChannel
911

1012
companion object {
@@ -17,12 +19,13 @@ class GoogleMlKitCommonsPlugin: FlutterPlugin, MethodChannel.MethodCallHandler {
1719
}
1820

1921
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
20-
channel.setMethodCallHandler(null)
22+
channel.setMethodCallHandler(null)
2123
}
2224

23-
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
25+
override fun onMethodCall(
26+
call: MethodCall,
27+
result: MethodChannel.Result,
28+
) {
2429
result.notImplemented()
2530
}
26-
27-
28-
}
31+
}

0 commit comments

Comments
 (0)