Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/src/main/assets/car_images/m3_PBSB_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PMBL_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PMNG_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PMSS_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PPMR_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PPSB_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/car_images/m3_PPSW_W32D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ object CarImageResolver {
"aeroturbine19" to "W39B",
"stiletto19" to "W39B",
"sport19" to "W39B",
"uberturbine20" to "W32D",
"performance20" to "W32P",
"19" to "W39B",
"20" to "W32P",
Expand Down Expand Up @@ -522,6 +523,7 @@ object CarImageResolver {
"W38B" to "18\" Aero",
"W39B" to "19\" Sport",
"W32P" to "20\" Performance",
"W32D" to "20\" Überturbine",
// Highland Model 3
"W38A" to "18\" Photon",
"W30P" to "20\" Performance",
Expand All @@ -548,7 +550,7 @@ object CarImageResolver {

// Available wheel codes per variant
private val VARIANT_WHEELS = mapOf(
"m3" to listOf("W38B", "W39B", "W32P"),
"m3" to listOf("W38B", "W39B", "W32P", "W32D"),
"m3h" to listOf("W38A"),
"m3hp" to listOf("W30P"),
"my" to listOf("WY18B", "WY19B", "WY20P"),
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/com/matedroid/widget/CarWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class CarWidget : GlanceAppWidget() {
val CHARGER_CURRENT_KEY = intPreferencesKey("charger_current") // -1 if null
val AC_PHASES_KEY = intPreferencesKey("ac_phases") // -1 if null
val SENTRY_EVENT_COUNT_KEY = intPreferencesKey("sentry_event_count") // 0 = none
val IMAGE_OVERRIDE_VARIANT_KEY = stringPreferencesKey("image_override_variant")
val IMAGE_OVERRIDE_WHEEL_KEY = stringPreferencesKey("image_override_wheel")
}

override val stateDefinition: GlanceStateDefinition<*> = PreferencesGlanceStateDefinition
Expand Down Expand Up @@ -360,6 +362,13 @@ class CarWidget : GlanceAppWidget() {
this[CHARGER_CURRENT_KEY] = data.chargerActualCurrent ?: -1
this[AC_PHASES_KEY] = data.acPhases ?: -1
this[SENTRY_EVENT_COUNT_KEY] = data.sentryEventCount
if (data.imageOverride != null) {
this[IMAGE_OVERRIDE_VARIANT_KEY] = data.imageOverride.variant
this[IMAGE_OVERRIDE_WHEEL_KEY] = data.imageOverride.wheelCode
} else {
remove(IMAGE_OVERRIDE_VARIANT_KEY)
remove(IMAGE_OVERRIDE_WHEEL_KEY)
}
}
}
update(context, glanceId)
Expand Down Expand Up @@ -391,6 +400,8 @@ class CarWidget : GlanceAppWidget() {
val model = prefs[MODEL_KEY]
val trimBadging = prefs[TRIM_BADGING_KEY]
val wheelType = prefs[WHEEL_TYPE_KEY]
val overrideVariant = prefs[IMAGE_OVERRIDE_VARIANT_KEY]
val overrideWheel = prefs[IMAGE_OVERRIDE_WHEEL_KEY]
val state = prefs[STATE_KEY]
val isLocked = prefs[IS_LOCKED_KEY] ?: false
val sentryMode = prefs[SENTRY_MODE_KEY] ?: false
Expand Down Expand Up @@ -428,7 +439,7 @@ class CarWidget : GlanceAppWidget() {
// The larger scale factor ensures neither dimension is left uncovered;
// overflow is clipped by the canvas bounds. The status bar, scrim and
// progress bar are all drawn on top, so no space needs to be reserved.
val carBitmap = loadCarBitmap(context, model, exteriorColor, wheelType, trimBadging)
val carBitmap = loadCarBitmap(context, model, exteriorColor, wheelType, trimBadging, overrideVariant, overrideWheel)
if (carBitmap != null) {
val scaleByWidth = width.toFloat() / carBitmap.width
val scaleByHeight = height.toFloat() / carBitmap.height
Expand Down Expand Up @@ -679,9 +690,16 @@ class CarWidget : GlanceAppWidget() {
model: String?,
exteriorColor: String?,
wheelType: String?,
trimBadging: String?
trimBadging: String?,
overrideVariant: String? = null,
overrideWheel: String? = null
): Bitmap? {
val assetPath = CarImageResolver.getAssetPath(model, exteriorColor, wheelType, trimBadging)
val colorCode = CarImageResolver.mapColor(exteriorColor)
val assetPath = if (overrideVariant != null && overrideWheel != null) {
CarImageResolver.getAssetPathForOverride(overrideVariant, colorCode, overrideWheel)
} else {
CarImageResolver.getAssetPath(model, exteriorColor, wheelType, trimBadging)
}
return try {
context.assets.open(assetPath).use { BitmapFactory.decodeStream(it) }
} catch (_: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.matedroid.widget

import com.matedroid.data.api.models.CarData
import com.matedroid.data.api.models.CarStatus
import com.matedroid.data.local.CarImageOverride

/**
* Data class encapsulating all fields shown on the dashboard battery card.
Expand Down Expand Up @@ -40,6 +41,8 @@ data class CarWidgetDisplayData(
val chargerActualCurrent: Int?,
val acPhases: Int?,
val sentryEventCount: Int = 0,
// --- Image override (from car image picker) ---
val imageOverride: CarImageOverride? = null,
) {
companion object {
fun from(carData: CarData, status: CarStatus): CarWidgetDisplayData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import com.matedroid.BuildConfig
import com.matedroid.data.local.SettingsDataStore
import com.matedroid.data.repository.ApiResult
import com.matedroid.data.repository.SentryStateRepository
import com.matedroid.data.repository.TeslamateRepository
import kotlinx.coroutines.flow.firstOrNull
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import java.util.concurrent.TimeUnit
Expand All @@ -36,6 +38,7 @@ class CarWidgetUpdateWorker @AssistedInject constructor(
@Assisted workerParams: WorkerParameters,
private val teslamateRepository: TeslamateRepository,
private val sentryStateRepository: SentryStateRepository,
private val settingsDataStore: SettingsDataStore,
) : CoroutineWorker(appContext, workerParams) {

companion object {
Expand Down Expand Up @@ -122,6 +125,9 @@ class CarWidgetUpdateWorker @AssistedInject constructor(
return Result.success()
}

// Read image overrides once (same source as the dashboard)
val imageOverrides = settingsDataStore.carImageOverrides.firstOrNull() ?: emptyMap()

// Fetch all cars once to avoid redundant API calls
val carsResult = teslamateRepository.getCars()
val cars = when (carsResult) {
Expand Down Expand Up @@ -150,7 +156,8 @@ class CarWidgetUpdateWorker @AssistedInject constructor(

val sentryEventCount = sentryStateRepository.getEventCount(carId)
val displayData = CarWidgetDisplayData.from(car, status).copy(
sentryEventCount = sentryEventCount
sentryEventCount = sentryEventCount,
imageOverride = imageOverrides[carId]
)
CarWidget().updateWidget(appContext, glanceId, displayData)
Log.d(TAG, "Updated widget for car $carId (${car.displayName})")
Expand Down
2 changes: 1 addition & 1 deletion util/fetch_tesla_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"file_prefix": "m3",
"name": "Model 3 (Legacy)",
"colors": ["PBSB", "PMNG", "PMSS", "PPSW", "PPSB", "PPMR", "PMBL"],
"wheels": ["W38B", "W39B", "W32P"],
"wheels": ["W38B", "W39B", "W32P", "W32D"],
"compositor": "old",
}

Expand Down
Loading