mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 13:59:48 +01:00
let current user be null-able
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
209c1a90ba
commit
3c865364ac
@ -25,7 +25,7 @@ import com.nextcloud.talk.data.user.model.User
|
|||||||
import com.nextcloud.talk.models.json.capabilities.Capabilities
|
import com.nextcloud.talk.models.json.capabilities.Capabilities
|
||||||
|
|
||||||
interface ServerThemeProvider {
|
interface ServerThemeProvider {
|
||||||
fun getServerThemeForUser(user: User): ServerTheme
|
fun getServerThemeForUser(user: User?): ServerTheme
|
||||||
fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme
|
fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme
|
||||||
fun getServerThemeForCurrentUser(): ServerTheme
|
fun getServerThemeForCurrentUser(): ServerTheme
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ internal class ServerThemeProviderImpl @Inject constructor(
|
|||||||
|
|
||||||
// TODO move this logic to currentUserProvider or something
|
// TODO move this logic to currentUserProvider or something
|
||||||
private var _currentUser: User? = null
|
private var _currentUser: User? = null
|
||||||
private val currentUser: User
|
private val currentUser: User?
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
get() {
|
get() {
|
||||||
return when (_currentUser) {
|
return when (_currentUser) {
|
||||||
@ -49,19 +49,26 @@ internal class ServerThemeProviderImpl @Inject constructor(
|
|||||||
_currentUser = userProvider.currentUser.blockingGet()
|
_currentUser = userProvider.currentUser.blockingGet()
|
||||||
// start observable for auto-updates
|
// start observable for auto-updates
|
||||||
userProvider.currentUserObservable.subscribe { _currentUser = it }
|
userProvider.currentUserObservable.subscribe { _currentUser = it }
|
||||||
_currentUser!!
|
_currentUser
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
_currentUser!!
|
_currentUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getServerThemeForUser(user: User): ServerTheme {
|
override fun getServerThemeForUser(user: User?): ServerTheme {
|
||||||
if (user.baseUrl != null && !themeCache.containsKey(user.baseUrl)) {
|
val url: String = if (user?.baseUrl != null) {
|
||||||
themeCache[user.baseUrl!!] = getServerThemeForCapabilities(user.capabilities)
|
user.baseUrl!!
|
||||||
|
} else {
|
||||||
|
FALLBACK_URL
|
||||||
}
|
}
|
||||||
return themeCache[user.baseUrl]!!
|
|
||||||
|
if (!themeCache.containsKey(url)) {
|
||||||
|
themeCache[url] = getServerThemeForCapabilities(user?.capabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
return themeCache[url]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getServerThemeForCurrentUser(): ServerTheme {
|
override fun getServerThemeForCurrentUser(): ServerTheme {
|
||||||
@ -71,4 +78,8 @@ internal class ServerThemeProviderImpl @Inject constructor(
|
|||||||
override fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme {
|
override fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme {
|
||||||
return ServerThemeImpl(context, capabilities?.themingCapability)
|
return ServerThemeImpl(context, capabilities?.themingCapability)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FALLBACK_URL = "NULL"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user