mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 06:35:48 +03:00
Generate MaterialSchemes from colorPrimary when there's no logged in user
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
46fef5c883
commit
8078fe0ee0
3 changed files with 27 additions and 3 deletions
|
@ -355,7 +355,7 @@ dependencies {
|
|||
gplayImplementation "com.google.firebase:firebase-messaging:23.0.7"
|
||||
|
||||
// TODO change back to tag before merging
|
||||
implementation 'com.github.nextcloud.android-common:ui:05edc813295567d24ea468ac1b32c3ab1e950dfb'
|
||||
implementation 'com.github.nextcloud.android-common:ui:f552591b604ef03a4540455069f4baf4ff2c3b9b'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
|
|
|
@ -26,9 +26,13 @@ import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
|||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
|
||||
// TODO schema for non-logged-in user? login and what's new screens
|
||||
interface MaterialSchemesProvider {
|
||||
fun getMaterialSchemesForUser(user: User): MaterialSchemes
|
||||
fun getMaterialSchemesForCapability(capability: OCCapability): MaterialSchemes
|
||||
fun getMaterialSchemesForCurrentUser(): MaterialSchemes
|
||||
|
||||
/**
|
||||
* Color schemes for when there's no logged in user
|
||||
*/
|
||||
fun getDefaultMaterialSchemes(): MaterialSchemes
|
||||
}
|
||||
|
|
|
@ -23,9 +23,13 @@
|
|||
package com.owncloud.android.utils.theme.newm3
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.client.account.AnonymousUser
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.logger.Logger
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import com.owncloud.android.utils.theme.CapabilityUtils
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
@ -34,6 +38,7 @@ import javax.inject.Inject
|
|||
// TODO think about assisted inject to pass user instead of fetching it from userAccountManager,
|
||||
// thus making it more efficient, or cache the user, IDK
|
||||
internal class MaterialSchemesProviderImpl @Inject constructor(
|
||||
private val logger: Logger,
|
||||
private val context: Context,
|
||||
private val userAccountManager: UserAccountManager,
|
||||
private val themeFactory: ServerThemeImpl.Factory
|
||||
|
@ -58,6 +63,21 @@ internal class MaterialSchemesProviderImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override fun getMaterialSchemesForCurrentUser(): MaterialSchemes {
|
||||
return getMaterialSchemesForUser(userAccountManager.user)
|
||||
return when (val user = userAccountManager.user) {
|
||||
is AnonymousUser -> {
|
||||
logger.d(TAG, "User is anonymous, using default schemes")
|
||||
getDefaultMaterialSchemes()
|
||||
}
|
||||
else -> getMaterialSchemesForUser(user)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDefaultMaterialSchemes(): MaterialSchemes {
|
||||
val primaryColor = ContextCompat.getColor(context, R.color.primary)
|
||||
return MaterialSchemes.fromColor(primaryColor)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = MaterialSchemesProviderImpl::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue