Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ class EntityWidgetConfigureActivity : BaseWidgetConfigureActivity<StaticWidgetEn
throw IllegalStateException("Selected entity is unknown on server")
}

val selectedBackgroundOption = binding.backgroundType.selectedItem as String? ?: ""
val selectedBackgroundType = WidgetUtils.getWidgetBackgroundType(this, selectedBackgroundOption)
Comment on lines +345 to +346

return StaticWidgetEntity(
id = appWidgetId,
serverId = serverId,
Expand All @@ -363,14 +366,8 @@ class EntityWidgetConfigureActivity : BaseWidgetConfigureActivity<StaticWidgetEn
0 -> WidgetTapAction.TOGGLE
else -> WidgetTapAction.REFRESH
},
backgroundType = when (binding.backgroundType.selectedItem as String?) {
getString(commonR.string.widget_background_type_dynamiccolor) -> WidgetBackgroundType.DYNAMICCOLOR
getString(commonR.string.widget_background_type_transparent) -> WidgetBackgroundType.TRANSPARENT
else -> WidgetBackgroundType.DAYNIGHT
},
textColor = if (binding.backgroundType.selectedItem as String? ==
getString(commonR.string.widget_background_type_transparent)
) {
backgroundType = selectedBackgroundType,
textColor = if (selectedBackgroundType == WidgetBackgroundType.TRANSPARENT) {
getHexForColor(
if (binding.textColorWhite.isChecked) {
android.R.color.white
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.homeassistant.companion.android.widgets.common

import androidx.test.core.app.ApplicationProvider
import dagger.hilt.android.testing.HiltTestApplication
import io.homeassistant.companion.android.common.R
import io.homeassistant.companion.android.database.widget.WidgetBackgroundType
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(application = HiltTestApplication::class)
class WidgetUtilsTest {
private val context = ApplicationProvider.getApplicationContext<HiltTestApplication>()

@Test
fun `Given dynamic color background option when getting widget background type then returns dynamic color`() {
assertWidgetBackgroundType(
context.getString(R.string.widget_background_type_dynamiccolor),
WidgetBackgroundType.DYNAMICCOLOR,
)
}

@Test
fun `Given transparent background option when getting widget background type then returns transparent`() {
assertWidgetBackgroundType(
context.getString(R.string.widget_background_type_transparent),
WidgetBackgroundType.TRANSPARENT,
)
}

@Test
fun `Given day night background option when getting widget background type then returns day night`() {
assertWidgetBackgroundType(
context.getString(R.string.widget_background_type_daynight),
WidgetBackgroundType.DAYNIGHT,
)
}

@Test
fun `Given unknown background option when getting widget background type then returns day night`() {
assertWidgetBackgroundType("unknown", WidgetBackgroundType.DAYNIGHT)
}

private fun assertWidgetBackgroundType(
selectedOption: String,
expectedType: WidgetBackgroundType,
) {
val result = WidgetUtils.getWidgetBackgroundType(context, selectedOption)

assertEquals(expectedType, result)
}
}
Loading