Skip to content
Merged
7 changes: 7 additions & 0 deletions api/anilist/src/main/graphql/mutations/UpdateUser.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation UpdateUser($profileColor: String) {
UpdateUser(profileColor: $profileColor) {
options {
profileColor
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@
.filter { it.exception == null }
.asResult { User.MediaCollection(it, type, language, mediaListOrder) }
}

fun updateUser(profileColor: String?): Flow<Result<String?>> {

Check warning

Code scanning / detekt

Public functions require documentation. Warning

The function updateUser is missing documentation.
return apolloClient
.mutation(UpdateUserMutation(Optional.presentIfNotNull(profileColor)))
.fetchPolicy(FetchPolicy.NetworkOnly)
.toFlow()
.asResult { it.UpdateUser?.options?.profileColor }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.imashnake.animite.api.anilist.sanitize.media.Media.Language
import com.imashnake.animite.api.anilist.sanitize.media.Media.Small.Type
import com.imashnake.animite.api.anilist.sanitize.profile.User.ListNames.Companion.sanitize
import com.imashnake.animite.api.anilist.sanitize.profile.User.ProfileColors.Companion.toHexString
import com.imashnake.animite.api.anilist.type.MediaType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
Expand Down Expand Up @@ -172,7 +171,8 @@
description = query.about,
avatar = query.avatar?.large,
banner = query.bannerImage,
color = query.options?.profileColor?.toHexString(),
color = query.options?.profileColor,
// TODO: Replace with string resources.

Check warning

Code scanning / detekt

Flags a forbidden comment. Warning

Forbidden TODO todo marker in comment, please do the changes.
stats = listOfNotNull(
query.statistics?.anime?.count?.toString()?.let {
Stat("TOTAL\nANIME", it)
Expand Down Expand Up @@ -205,36 +205,6 @@
).toImmutableList()
)

/** Profile highlight color (blue, purple, pink, orange, red, green, gray) */
enum class ProfileColors {
BLUE, PURPLE, PINK, ORANGE, RED, GREEN, GRAY;

companion object {
fun safeValueOf(rawValue: String): ProfileColors? = try {
ProfileColors.valueOf(rawValue)
} catch (e: IllegalArgumentException) {
Log.e(EXCEPTION_TAG, "safeValueOf: $e; Profile color $rawValue doesn't exist!.")
null
}

internal fun String?.toHexString(): String {
val color = when(this?.let { ProfileColors.safeValueOf(it.uppercase()) }) {
BLUE -> "#007BA7"
PURPLE -> "#E0AFFF"
PINK -> "#F2BDCD"
ORANGE -> "#F2B949"
RED -> "#FA5053"
GREEN -> "#0BDA51"
GRAY -> "#D9D9D9"
null -> "#FF8DA1"
}
Log.d("whatiscolor", "toHexString: $color")

return color
}
}
}

enum class Favouritables {
Anime,
Manga,
Expand Down Expand Up @@ -268,4 +238,17 @@
fun String?.sanitize() = safeValueOf(this)
}
}

companion object {
fun profileColorToHex(profileColor: String?) = when(profileColor) {

Check warning

Code scanning / detekt

Public functions require documentation. Warning

The function profileColorToHex is missing documentation.
"blue" -> "#007BA7"
"purple" -> "#E0AFFF"
"pink" -> "#F2BDCD"
"orange" -> "#F2B949"
"red" -> "#FA5053"
"green" -> "#0BDA51"
"gray" -> "#D9D9D9"
else -> "#007BA7"
}
}

Check warning

Code scanning / detekt

Public classes, interfaces and objects require documentation. Warning

Companion is missing required documentation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private const val IS_NSFW_ENABLED = false
private const val DEFAULT_LANGUAGE_KEY = "DEFAULT"
private const val SHOW_USER_DESCRIPTION = true
private const val USE_PROFILE_COLOR = true
private const val PROFILE_COLOR = "blue"
private const val IS_DEV_OPTIONS_ENABLED = false

/**
Expand Down Expand Up @@ -163,6 +164,12 @@ class PreferencesRepository internal constructor(
dataStore.setValue(useProfileColorKey, useProfileColor)
}

private val profileColorKey = stringPreferencesKey("profile_color")
val profileColor = dataStore.getValue(profileColorKey, PROFILE_COLOR)
suspend fun setProfileColor(profileColor: String?) {
dataStore.setValue(profileColorKey, profileColor)
}

// region developer options
private val isDevOptionsEnabledKey = booleanPreferencesKey("dev_options_enabled")
val isDevOptionsEnabled = dataStore.getValue(isDevOptionsEnabledKey, IS_DEV_OPTIONS_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import androidx.core.graphics.toColorInt
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import coil3.compose.AsyncImage
import com.imashnake.animite.api.anilist.sanitize.profile.User
import com.imashnake.animite.api.anilist.sanitize.profile.User.Companion.profileColorToHex
import com.imashnake.animite.banner.NestedScrollBannerLayout
import com.imashnake.animite.core.resource.Resource
import com.imashnake.animite.core.ui.LocalPaddings
Expand Down Expand Up @@ -140,6 +141,7 @@ fun ProfileScreen(

val isLoggedIn by viewModel.isLoggedIn.collectAsState(initial = false)
val useProfileColor by viewModel.useProfileColor.collectAsState(initial = true)
val profileColor by viewModel.profileColor.collectAsState(initial = "blue")
val viewerAvatar by viewModel.viewerAvatar.collectAsState(initial = "")
val viewer by viewModel.viewer.collectAsState()
val viewerAnimeLists by viewModel.viewerAnimeLists.collectAsState()
Expand Down Expand Up @@ -168,7 +170,7 @@ fun ProfileScreen(
MaterialTheme(
colorScheme = if (useProfileColor) {
rememberColorSchemeFor(
color = color?.toColorInt(),
color = profileColorToHex(profileColor).toColorInt(),
useDarkTheme = useDarkTheme,
isAmoled = isAmoled
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
.map { !it.isNullOrEmpty() }

val useProfileColor = preferencesRepository.useProfileColor.filterNotNull()
val profileColor = preferencesRepository.profileColor.filterNotNull()

Check warning

Code scanning / detekt

Public properties require documentation. Warning

The property profileColor is missing documentation.

val viewer = combine(
flow = refreshTrigger.onStart { emit(Unit) },
Expand All @@ -56,6 +57,10 @@
}.asResource().onEach {
it.data?.let { user ->
preferencesRepository.setViewerId(user.id)
// Don't update with cached color
if (useNetwork) {
preferencesRepository.setProfileColor(user.color)
}
preferencesRepository.setAnimeListOrder(user.animeListOrder)
preferencesRepository.setMangaListOrder(user.mangaListOrder)
}
Expand Down
1 change: 1 addition & 0 deletions settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation(projects.api.anilist)
implementation(projects.api.preferences)
implementation(projects.core.model)
implementation(projects.core.resource)
implementation(projects.core.ui)
implementation(projects.banner)
implementation(projects.media)
Expand Down
Loading
Loading