mirror of
https://github.com/usetrmnl/trmnl-android.git
synced 2026-04-29 13:35:26 -07:00
Merge pull request #225 from usetrmnl/feature/device-model-selector-screen
Add Device Model Selector Screen with Circuit Navigation Results
This commit is contained in:
@@ -20,6 +20,6 @@ class RepositoryConfigProvider
|
||||
// To change this value, update the `buildConfigField` in the app's build.gradle file
|
||||
// Or, change the value here for local development. Do not commit this change.
|
||||
// Return value should always be `BuildConfig.USE_FAKE_API`
|
||||
return BuildConfig.USE_FAKE_API
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import ink.trmnl.android.BuildConfig.USE_FAKE_API
|
||||
import ink.trmnl.android.data.fake.generateFakeDeviceSetupInfo
|
||||
import ink.trmnl.android.data.fake.generateFakeTrmnlDisplayInfo
|
||||
import ink.trmnl.android.di.AppScope
|
||||
import ink.trmnl.android.model.SupportedDeviceModel
|
||||
import ink.trmnl.android.model.TrmnlDeviceConfig
|
||||
import ink.trmnl.android.model.TrmnlDeviceType
|
||||
import ink.trmnl.android.network.TrmnlApiService
|
||||
import ink.trmnl.android.network.TrmnlApiService.Companion.CURRENT_PLAYLIST_SCREEN_API_PATH
|
||||
import ink.trmnl.android.network.TrmnlApiService.Companion.MODELS_API_PATH
|
||||
import ink.trmnl.android.network.TrmnlApiService.Companion.NEXT_PLAYLIST_SCREEN_API_PATH
|
||||
import ink.trmnl.android.network.model.TrmnlDeviceModel
|
||||
import ink.trmnl.android.network.model.TrmnlDisplayResponse
|
||||
import ink.trmnl.android.network.util.constructApiUrl
|
||||
import ink.trmnl.android.network.util.extractHttpResponseMetadata
|
||||
@@ -255,4 +258,58 @@ class TrmnlDisplayRepository
|
||||
// -- "filename": "setup.png"
|
||||
// -- "image_url": "https://my-trmnl-hub.com/assets/screens/ABCDEF123/setup.png",
|
||||
(response.imageUrl?.contains("screens", ignoreCase = true) == false)
|
||||
|
||||
/**
|
||||
* Fetches the list of available device models from the TRMNL API.
|
||||
*
|
||||
* This provides information about all supported device models including
|
||||
* display specifications, supported palettes, and device characteristics.
|
||||
*
|
||||
* The API response is converted to simplified [SupportedDeviceModel] DTOs containing
|
||||
* only the essential information needed for device selection.
|
||||
*
|
||||
* @param serverBaseUrl The base URL of the server to fetch models from (defaults to TRMNL API).
|
||||
* @return A list of [SupportedDeviceModel] objects, or an empty list on failure.
|
||||
*/
|
||||
suspend fun getDeviceModels(serverBaseUrl: String): List<SupportedDeviceModel> {
|
||||
Timber.i("Fetching device models from server: $serverBaseUrl")
|
||||
|
||||
val result =
|
||||
apiService.getDeviceModels(
|
||||
fullApiUrl = constructApiUrl(serverBaseUrl, MODELS_API_PATH),
|
||||
)
|
||||
|
||||
return when (result) {
|
||||
is ApiResult.Failure -> {
|
||||
Timber.e("Failed to fetch device models: ${result.exceptionOrNull()}")
|
||||
emptyList()
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
Timber.i("Successfully fetched ${result.value.data.size} device models")
|
||||
// Convert API models to simplified SupportedDeviceModel DTOs
|
||||
result.value.data.map { it.toSupportedDeviceModel() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a [TrmnlDeviceModel] API response to a simplified [SupportedDeviceModel] DTO.
|
||||
*
|
||||
* This extension function extracts only the essential device information needed
|
||||
* for UI purposes, making it Parcelable for navigation results.
|
||||
*/
|
||||
private fun TrmnlDeviceModel.toSupportedDeviceModel() =
|
||||
SupportedDeviceModel(
|
||||
name = name,
|
||||
label = label,
|
||||
description = description,
|
||||
width = width,
|
||||
height = height,
|
||||
colors = colors,
|
||||
bitDepth = bitDepth,
|
||||
scaleFactor = scaleFactor,
|
||||
rotation = rotation,
|
||||
mimeType = mimeType,
|
||||
kind = kind,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package ink.trmnl.android.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Simplified device configuration DTO for UI purposes.
|
||||
*
|
||||
* This is a lightweight, Parcelable version of [ink.trmnl.android.network.model.TrmnlDeviceModel]
|
||||
* containing only the essential information needed for device selection and display.
|
||||
*
|
||||
* @property name Unique identifier for the model (e.g., "v2", "kindle", "byod")
|
||||
* @property label Human-readable label for the model (e.g., "TRMNL X")
|
||||
* @property description Description of the model
|
||||
* @property width Display width in pixels
|
||||
* @property height Display height in pixels
|
||||
* @property colors Number of colors supported
|
||||
* @property bitDepth Bit depth of the display
|
||||
* @property scaleFactor Scale factor for rendering
|
||||
* @property rotation Display rotation in degrees
|
||||
* @property mimeType MIME type of the image format (e.g., "image/png")
|
||||
* @property kind Device kind (e.g., "trmnl", "kindle", "byod", "tidbyt")
|
||||
*/
|
||||
@Parcelize
|
||||
data class SupportedDeviceModel(
|
||||
val name: String,
|
||||
val label: String,
|
||||
val description: String,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val colors: Int,
|
||||
val bitDepth: Int,
|
||||
val scaleFactor: Double,
|
||||
val rotation: Int,
|
||||
val mimeType: String,
|
||||
val kind: String,
|
||||
) : Parcelable
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user