harden theming calculations to handle null values

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-28 16:37:18 +02:00
parent d4c07f1278
commit eb967fbf7d
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 10 additions and 10 deletions

View file

@ -27,7 +27,7 @@ import android.content.Context
import com.nextcloud.talk.R
import com.nextcloud.talk.models.json.capabilities.ThemingCapability
internal class ServerThemeImpl(context: Context, themingCapability: ThemingCapability) :
internal class ServerThemeImpl(context: Context, themingCapability: ThemingCapability?) :
ServerTheme {
override val primaryColor: Int
@ -37,12 +37,12 @@ internal class ServerThemeImpl(context: Context, themingCapability: ThemingCapab
override val colorText: Int
init {
primaryColor = ColorUtil.getPrimaryColor(context, themingCapability.color, R.color.colorPrimary)
primaryColor = ColorUtil.getPrimaryColor(context, themingCapability?.color, R.color.colorPrimary)
colorElement = ColorUtil.getNullsafeColor(themingCapability.colorElement, primaryColor)
colorElementBright = ColorUtil.getNullsafeColor(themingCapability.colorElementBright, primaryColor)
colorElementDark = ColorUtil.getNullsafeColor(themingCapability.colorElementDark, primaryColor)
colorElement = ColorUtil.getNullsafeColor(themingCapability?.colorElement, primaryColor)
colorElementBright = ColorUtil.getNullsafeColor(themingCapability?.colorElementBright, primaryColor)
colorElementDark = ColorUtil.getNullsafeColor(themingCapability?.colorElementDark, primaryColor)
colorText = ColorUtil.getTextColor(context, themingCapability.colorText, primaryColor)
colorText = ColorUtil.getTextColor(context, themingCapability?.colorText, primaryColor)
}
}

View file

@ -26,6 +26,6 @@ import com.nextcloud.talk.models.json.capabilities.Capabilities
interface ServerThemeProvider {
fun getServerThemeForUser(user: User): ServerTheme
fun getServerThemeForCapabilities(capabilities: Capabilities): ServerTheme
fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme
fun getServerThemeForCurrentUser(): ServerTheme
}

View file

@ -55,14 +55,14 @@ internal class ServerThemeProviderImpl @Inject constructor(
}
override fun getServerThemeForUser(user: User): ServerTheme {
return getServerThemeForCapabilities(user.capabilities!!)
return getServerThemeForCapabilities(user.capabilities)
}
override fun getServerThemeForCurrentUser(): ServerTheme {
return getServerThemeForUser(currentUser)
}
override fun getServerThemeForCapabilities(capabilities: Capabilities): ServerTheme {
return ServerThemeImpl(context, capabilities.themingCapability!!)
override fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme {
return ServerThemeImpl(context, capabilities?.themingCapability)
}
}