From 5b011cae333af3c2e1f00f1c0f5f1d61a6b315a1 Mon Sep 17 00:00:00 2001 From: XinyueZ Date: Sun, 7 Oct 2018 00:28:17 +0200 Subject: [PATCH] Fix lint warnings and optimize for CloudImageLabelingProcessor - Lint-warning at `onSuccess()` - detector with by-lazy. I know people will mind that no need for performance improve here, however, for enthusiast :) --- .../CloudImageLabellingProcessor.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/kotlin/cloudimagelabeling/CloudImageLabellingProcessor.kt b/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/kotlin/cloudimagelabeling/CloudImageLabellingProcessor.kt index 76f060b019..a344e3c830 100644 --- a/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/kotlin/cloudimagelabeling/CloudImageLabellingProcessor.kt +++ b/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/kotlin/cloudimagelabeling/CloudImageLabellingProcessor.kt @@ -14,37 +14,36 @@ import com.google.firebase.samples.apps.mlkit.kotlin.VisionProcessorBase /** Cloud Label Detector Demo. */ class CloudImageLabelingProcessor : VisionProcessorBase>() { - private val detector: FirebaseVisionCloudLabelDetector - - init { - val options = FirebaseVisionCloudDetectorOptions.Builder() - .setMaxResults(10) - .setModelType(FirebaseVisionCloudDetectorOptions.STABLE_MODEL) - .build() - - detector = FirebaseVision.getInstance().getVisionCloudLabelDetector(options) + private val detector: FirebaseVisionCloudLabelDetector by lazy { + FirebaseVisionCloudDetectorOptions.Builder() + .setMaxResults(10) + .setModelType(FirebaseVisionCloudDetectorOptions.STABLE_MODEL) + .build().let { options -> + FirebaseVision.getInstance().getVisionCloudLabelDetector(options) + } } + override fun detectInImage(image: FirebaseVisionImage): Task> { return detector.detectInImage(image) } override fun onSuccess( - labels: List, + results: List, frameMetadata: FrameMetadata, graphicOverlay: GraphicOverlay) { graphicOverlay.clear() - Log.d(TAG, "cloud label size: ${labels.size}") + Log.d(TAG, "cloud label size: ${results.size}") val labelsStr = ArrayList() - for (i in labels.indices) { - val label = labels[i] + for (i in results.indices) { + val result = results[i] - Log.d(TAG, "cloud label: $label") + Log.d(TAG, "cloud label: $result") - label.label?.let { + result.label?.let { labelsStr.add(it) } }