@@ -27,7 +27,6 @@ import com.github.mikephil.charting.formatter.ValueFormatter
2727import com.google.android.material.color.DynamicColors
2828import dagger.hilt.android.AndroidEntryPoint
2929import io.homeassistant.companion.android.R
30- import io.homeassistant.companion.android.common.R as commonR
3130import io.homeassistant.companion.android.common.data.integration.Entity
3231import io.homeassistant.companion.android.common.data.integration.canSupportPrecision
3332import io.homeassistant.companion.android.common.data.integration.friendlyState
@@ -41,9 +40,10 @@ import io.homeassistant.companion.android.database.widget.graph.GraphWidgetWithH
4140import io.homeassistant.companion.android.util.getAttribute
4241import io.homeassistant.companion.android.widgets.BaseWidgetProvider
4342import io.homeassistant.companion.android.widgets.entity.EntityWidget.Companion.EXTRA_STATE_SEPARATOR
44- import javax.inject.Inject
4543import kotlinx.coroutines.flow.first
4644import kotlinx.coroutines.launch
45+ import javax.inject.Inject
46+ import io.homeassistant.companion.android.common.R as commonR
4747
4848@AndroidEntryPoint
4949class GraphWidget : BaseWidgetProvider () {
@@ -69,13 +69,13 @@ class GraphWidget : BaseWidgetProvider() {
6969 }
7070
7171 @Inject
72- lateinit var graphWidgetRepository : GraphWidgetRepository
72+ lateinit var repository : GraphWidgetRepository
7373
7474 override fun getWidgetProvider (context : Context ): ComponentName =
7575 ComponentName (context, GraphWidget ::class .java)
7676
7777 override suspend fun getWidgetRemoteViews (context : Context , appWidgetId : Int , suggestedEntity : Entity <Map <String , Any >>? ): RemoteViews {
78- val historicData = graphWidgetRepository .getGraphWidgetWithHistories(appWidgetId)
78+ val historicData = repository .getGraphWidgetWithHistories(appWidgetId)
7979 val widget = historicData?.graphWidget
8080
8181 val intent = Intent (context, GraphWidget ::class .java).apply {
@@ -221,14 +221,15 @@ class GraphWidget : BaseWidgetProvider() {
221221
222222 private fun createLineChart (context : Context , label : String , timeRange : String , entries : List <Entry >, width : Int , height : Int ): LineChart {
223223 val lineChart = LineChart (context).apply {
224- setBackgroundColor(Color .WHITE )
225224
225+ val dynTextColor = ContextCompat .getColor(context, commonR.color.colorWidgetButtonLabel)
226+ setBackgroundResource(commonR.color.colorWidgetButtonBackground)
226227 setDrawBorders(false )
227228
228229 xAxis.apply {
229230 setDrawGridLines(true )
230231 position = XAxis .XAxisPosition .BOTTOM
231- textColor = Color . DKGRAY
232+ textColor = dynTextColor
232233 textSize = 12F
233234 granularity = 2F
234235 setAvoidFirstLastClipping(true )
@@ -237,7 +238,7 @@ class GraphWidget : BaseWidgetProvider() {
237238
238239 axisLeft.apply {
239240 setDrawGridLines(true )
240- textColor = Color . DKGRAY
241+ textColor = dynTextColor
241242 textSize = 12F
242243 }
243244
@@ -248,7 +249,7 @@ class GraphWidget : BaseWidgetProvider() {
248249
249250 legend.apply {
250251 isEnabled = true
251- textColor = Color . DKGRAY
252+ textColor = dynTextColor
252253 textSize = 12F
253254 verticalAlignment = Legend .LegendVerticalAlignment .BOTTOM
254255 horizontalAlignment = Legend .LegendHorizontalAlignment .RIGHT
@@ -262,6 +263,7 @@ class GraphWidget : BaseWidgetProvider() {
262263
263264 legend.isEnabled = true
264265 description.isEnabled = true
266+ description.textColor = dynTextColor
265267 }
266268
267269 val mainGraphColor = ContextCompat .getColor(context, commonR.color.colorPrimary)
@@ -301,7 +303,7 @@ class GraphWidget : BaseWidgetProvider() {
301303 }
302304
303305 override suspend fun getAllWidgetIdsWithEntities (context : Context ): Map <Int , Pair <Int , List <String >>> =
304- graphWidgetRepository .getAllFlow()
306+ repository .getAllFlow()
305307 .first()
306308 .associate { it.id to (it.serverId to listOf (it.entityId)) }
307309
@@ -336,11 +338,11 @@ class GraphWidget : BaseWidgetProvider() {
336338 null
337339 }
338340 if (attributeIds == null ) {
339- graphWidgetRepository .updateWidgetLastUpdate(
341+ repository .updateWidgetLastUpdate(
340342 appWidgetId,
341- entity?.friendlyState(context, entityOptions) ? : graphWidgetRepository .get(appWidgetId)?.lastUpdate ? : " "
343+ entity?.friendlyState(context, entityOptions) ? : repository .get(appWidgetId)?.lastUpdate ? : " "
342344 )
343- return ResolvedText (graphWidgetRepository .get(appWidgetId)?.lastUpdate, entityCaughtException)
345+ return ResolvedText (repository .get(appWidgetId)?.lastUpdate, entityCaughtException)
344346 }
345347
346348 try {
@@ -350,12 +352,12 @@ class GraphWidget : BaseWidgetProvider() {
350352 val lastUpdate =
351353 entity?.friendlyState(context, entityOptions).plus(if (attributeValues.isNotEmpty()) stateSeparator else " " )
352354 .plus(attributeValues.joinToString(attributeSeparator))
353- graphWidgetRepository .updateWidgetLastUpdate(appWidgetId, lastUpdate)
355+ repository .updateWidgetLastUpdate(appWidgetId, lastUpdate)
354356 return ResolvedText (lastUpdate)
355357 } catch (e: Exception ) {
356358 Log .e(TAG , " Unable to fetch entity state and attributes" , e)
357359 }
358- return ResolvedText (graphWidgetRepository .get(appWidgetId)?.lastUpdate, true )
360+ return ResolvedText (repository .get(appWidgetId)?.lastUpdate, true )
359361 }
360362
361363 override fun saveEntityConfiguration (context : Context , extras : Bundle ? , appWidgetId : Int ) {
@@ -386,8 +388,8 @@ class GraphWidget : BaseWidgetProvider() {
386388 " entity id: " + entitySelection + System .lineSeparator() +
387389 " attribute: " + (attributeSelection ? : " N/A" )
388390 )
389- if (graphWidgetRepository .get(appWidgetId) == null ) {
390- graphWidgetRepository .add(
391+ if (repository .get(appWidgetId) == null ) {
392+ repository .add(
391393 GraphWidgetEntity (
392394 id = appWidgetId,
393395 serverId = serverId,
@@ -398,7 +400,7 @@ class GraphWidget : BaseWidgetProvider() {
398400 stateSeparator = stateSeparatorSelection ? : " " ,
399401 attributeSeparator = attributeSeparatorSelection ? : " " ,
400402 tapAction = tapActionSelection,
401- lastUpdate = graphWidgetRepository .get(appWidgetId)?.lastUpdate ? : " " ,
403+ lastUpdate = repository .get(appWidgetId)?.lastUpdate ? : " " ,
402404 backgroundType = backgroundTypeSelection,
403405 textColor = textColorSelection
404406 )
@@ -411,7 +413,7 @@ class GraphWidget : BaseWidgetProvider() {
411413
412414 override suspend fun onEntityStateChanged (context : Context , appWidgetId : Int , entity : Entity <* >) {
413415 widgetScope?.launch {
414- val graphEntity = graphWidgetRepository .get(appWidgetId)
416+ val graphEntity = repository .get(appWidgetId)
415417
416418 if (graphEntity != null ) {
417419 val currentTimeMillis = System .currentTimeMillis()
@@ -420,9 +422,9 @@ class GraphWidget : BaseWidgetProvider() {
420422 val timeRangeInMillis = graphEntity.timeRange * 60 * 60 * 1000
421423 val cutoffTimeMillis = currentTimeMillis - timeRangeInMillis
422424
423- graphWidgetRepository .deleteEntriesOlderThan(appWidgetId, cutoffTimeMillis)
425+ repository .deleteEntriesOlderThan(appWidgetId, cutoffTimeMillis)
424426
425- graphWidgetRepository .insertGraphWidgetHistory(
427+ repository .insertGraphWidgetHistory(
426428 GraphWidgetHistoryEntity (
427429 entityId = entity.entityId,
428430 graphWidgetId = appWidgetId,
@@ -448,7 +450,7 @@ class GraphWidget : BaseWidgetProvider() {
448450 appWidgetManager.partiallyUpdateAppWidget(appWidgetId, loadingViews)
449451
450452 var success = false
451- graphWidgetRepository .get(appWidgetId)?.let {
453+ repository .get(appWidgetId)?.let {
452454 try {
453455 onEntityPressedWithoutState(
454456 it.entityId,
@@ -479,7 +481,7 @@ class GraphWidget : BaseWidgetProvider() {
479481
480482 override fun onDeleted (context : Context , appWidgetIds : IntArray ) {
481483 widgetScope?.launch {
482- graphWidgetRepository .deleteAll(appWidgetIds)
484+ repository .deleteAll(appWidgetIds)
483485 appWidgetIds.forEach { removeSubscription(it) }
484486 }
485487 }
0 commit comments