Skip to content
Merged
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
3 changes: 3 additions & 0 deletions api/anilist/src/main/graphql/fragments/User.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ fragment User on User {
large
}
bannerImage
options {
profileColor
}
statistics {
anime {
count
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.imashnake.animite.api.anilist.sanitize.media

import android.graphics.Color
import android.util.Log
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
Expand Down Expand Up @@ -49,7 +48,7 @@ data class Media(
/** @see MediaQuery.Media.coverImage */
val coverImage: String?,
/** @see MediaQuery.CoverImage.color */
val color: Int,
val color: String,
/** @see MediaQuery.Media.title */
val title: String?,
/** @see MediaQuery.Media.description */
Expand Down Expand Up @@ -584,7 +583,7 @@ data class Media(
id = query.id,
bannerImage = query.bannerImage,
coverImage = query.coverImage?.extraLarge ?: query.coverImage?.large ?: query.coverImage?.medium,
color = query.coverImage?.color?.let { Color.parseColor(it) } ?: Color.TRANSPARENT,
color = query.coverImage?.color ?: "#00000000",
title = when (language) {
Language.DEFAULT -> query.title?.userPreferred
Language.ROMAJI -> query.title?.romaji
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
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
import kotlin.collections.indexOf
import kotlin.time.Duration.Companion.minutes
import kotlin.time.DurationUnit

Expand Down Expand Up @@ -41,6 +41,8 @@
val avatar: String?,
/** @see User.bannerImage */
val banner: String?,
/** @see User.Options.profileColor */
val color: String?,

// region About
/** User Stats */
Expand Down Expand Up @@ -170,6 +172,7 @@
description = query.about,
avatar = query.avatar?.large,
banner = query.bannerImage,
color = query.options?.profileColor?.toHexString(),
stats = listOfNotNull(
query.statistics?.anime?.count?.toString()?.let {
Stat("TOTAL\nANIME", it)
Expand Down Expand Up @@ -202,6 +205,36 @@
).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
}
}
Comment on lines +212 to +235
}

enum class Favouritables {
Anime,
Manga,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private const val IS_AMOLED = false
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 IS_DEV_OPTIONS_ENABLED = false

/**
Expand Down Expand Up @@ -156,6 +157,12 @@ class PreferencesRepository internal constructor(
dataStore.setValue(showUserDescriptionKey, showUserDescription)
}

private val useProfileColorKey = booleanPreferencesKey("use_profile_color")
val useProfileColor = dataStore.getValue(useProfileColorKey, USE_PROFILE_COLOR)
suspend fun setUseProfileColor(useProfileColor: Boolean) {
dataStore.setValue(useProfileColorKey, useProfileColor)
}

// region developer options
private val isDevOptionsEnabledKey = booleanPreferencesKey("dev_options_enabled")
val isDevOptionsEnabled = dataStore.getValue(isDevOptionsEnabledKey, IS_DEV_OPTIONS_ENABLED)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/com/imashnake/animite/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ fun MainScreen(
onNavigateToSettings = navController::navigate,
showUserDescription = showUserDescription,
deviceScreenCornerRadius = deviceScreenCornerRadius,
useDarkTheme = useDarkTheme,
isAmoled = isAmoled,
sharedTransitionScope = this@SharedTransitionLayout,
animatedVisibilityScope = this,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.imashnake.animite.media
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.graphics.toColorInt
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -56,7 +57,7 @@ class MediaPageViewModel @Inject constructor(
uiState = uiState.copy(
bannerImage = media?.bannerImage,
coverImage = media?.coverImage,
color = media?.color,
color = media?.color?.toColorInt(),
description = media?.description,
nextAiring = media?.nextAiring,
info = media?.info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.materialkolor.PaletteStyle
import com.materialkolor.rememberDynamicColorScheme

// TODO: Move this to core:ui and reuse in profile screen.
/**
* Remembers a new Material3 [ColorScheme] based on the given color, or falls back to the default
* color scheme.
Expand Down
Loading
Loading