From 5828ec9ddc5c1048e41158b54f2ac621a77ec92b Mon Sep 17 00:00:00 2001 From: Yelin Jeong Date: Tue, 11 Jun 2024 16:28:15 +0900 Subject: [PATCH] App: Use RecyclerView and map to support various model This patch replaces buttons and textView to RecyclerView for supporting various model. Also, MainService's class variable tensorQueryServer is replaced to MutableMap. Signed-off-by: Yelin Jeong --- ml_inference_offloading/build.gradle.kts | 1 + .../ml/inference/offloading/MainActivity.kt | 73 ++++++++++++++----- .../ml/inference/offloading/MainService.kt | 18 +++-- .../src/main/res/layout/activity_main.xml | 18 +---- .../src/main/res/layout/models.xml | 21 ++++++ 5 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 ml_inference_offloading/src/main/res/layout/models.xml diff --git a/ml_inference_offloading/build.gradle.kts b/ml_inference_offloading/build.gradle.kts index c5de3c5..0708a4f 100644 --- a/ml_inference_offloading/build.gradle.kts +++ b/ml_inference_offloading/build.gradle.kts @@ -59,6 +59,7 @@ dependencies { implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.material3) implementation(project(":nnstreamer-api")) + implementation("androidx.recyclerview:recyclerview:1.3.2") testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/ml_inference_offloading/src/main/java/ai/nnstreamer/ml/inference/offloading/MainActivity.kt b/ml_inference_offloading/src/main/java/ai/nnstreamer/ml/inference/offloading/MainActivity.kt index 646865a..abf09ca 100644 --- a/ml_inference_offloading/src/main/java/ai/nnstreamer/ml/inference/offloading/MainActivity.kt +++ b/ml_inference_offloading/src/main/java/ai/nnstreamer/ml/inference/offloading/MainActivity.kt @@ -8,7 +8,9 @@ import android.content.ServiceConnection import android.os.Bundle import android.os.IBinder import android.util.Log +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import android.widget.Button import android.widget.TextView import androidx.activity.ComponentActivity @@ -17,17 +19,56 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.ui.Modifier +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import java.io.File import java.io.FileOutputStream import java.io.IOException import java.io.OutputStream +// todo: Define DTO with generality and extensibility +data class ModelInfo( + val name: String, + val filter: String +) + class MainActivity : ComponentActivity() { private val TAG = "MainActivity" private var mService: MainService? = null - private val connection = object : ServiceConnection { + inner class ModelViewHolder(itemView: View) : + RecyclerView.ViewHolder(itemView) { + fun bind(info: ModelInfo) { + val start = itemView.findViewById