Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile Screen #126

Merged
merged 38 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
15241f9
Use cache if available
imashnake0 Feb 17, 2024
2f28759
Created a basic banner layout
imashnake0 Feb 17, 2024
03252a7
Stole `compose-markdown`
imashnake0 Feb 18, 2024
74cf53e
Use `compose-markdown`
imashnake0 Feb 18, 2024
ee07631
Moved resource
imashnake0 Feb 18, 2024
cc08e08
Cleanup
imashnake0 Feb 18, 2024
c45663f
Revert "Stole `compose-markdown`"
imashnake0 Feb 18, 2024
7223b8a
Revert "Revert "Stole `compose-markdown`""
imashnake0 Feb 18, 2024
08c804a
Added block quote bar
imashnake0 Feb 19, 2024
1563c50
Added two more properties
imashnake0 Feb 19, 2024
ce0b7bd
Cleanup
imashnake0 Feb 19, 2024
67b0c00
Dp to Float
imashnake0 Feb 19, 2024
2092b65
Added `animiteBlockQuoteStyle`
imashnake0 Feb 19, 2024
2d05c87
Updated `compose-markdown`
imashnake0 Feb 19, 2024
3f8c1ad
Clip bar from `compose-markdown`
imashnake0 Feb 19, 2024
7b0611e
More updates to `compose-markdown`
imashnake0 Feb 19, 2024
02a7fe2
Cleanup
imashnake0 Feb 24, 2024
3360b37
Imported Compose Markdown as a library
imashnake0 Feb 24, 2024
9f89ac3
Limit height of `about`
imashnake0 Feb 24, 2024
3cdf191
`maxHeight` extension
imashnake0 Feb 24, 2024
5cef1ed
Create `animiteBlockQuoteStyle `
imashnake0 Feb 24, 2024
cc6356a
Created `animiteCodeBlockStyle `
imashnake0 Feb 24, 2024
07a1979
Add padding for landscape mode
imashnake0 Feb 24, 2024
39811bb
Add padding for cutouts
imashnake0 Feb 24, 2024
132e121
`when` is neater
imashnake0 Feb 26, 2024
1666ec1
Created tabs
imashnake0 Feb 26, 2024
71be5d1
Updated selection colors
imashnake0 Feb 26, 2024
2f01d45
Coming Soon placeholder text
imashnake0 Feb 27, 2024
346ad20
Moved `Constants` to core
imashnake0 Feb 27, 2024
a0e4bd1
Created extension for crossfading images
imashnake0 Feb 27, 2024
33a536a
Cleanup
imashnake0 Feb 27, 2024
dd83c41
Rename accessors
imashnake0 Feb 27, 2024
db42911
Rename file
imashnake0 Feb 27, 2024
4c7d527
Compose Markdown core is not used
imashnake0 Feb 27, 2024
e5da085
Cleanup
imashnake0 Feb 27, 2024
90087ad
Fix detekt
imashnake0 Feb 27, 2024
9cb127b
Revert "Use cache if available"
imashnake0 Feb 27, 2024
25db65d
Resolve comments
imashnake0 Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,7 +42,7 @@ class AnilistMediaRepository @Inject constructor(
seasonYear = Optional.presentIfNotNull(seasonYear)
)
)
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.fetchPolicy(FetchPolicy.CacheFirst)
imashnake0 marked this conversation as resolved.
Show resolved Hide resolved
.toFlow()
.asResult {
it.page!!.media.orEmpty().filterNotNull().map { query -> Media.Medium(query) }
Expand All @@ -57,7 +57,7 @@ class AnilistMediaRepository @Inject constructor(
type = Optional.presentIfNotNull(mediaType)
)
)
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.fetchPolicy(FetchPolicy.CacheFirst)
.toFlow()
.asResult { Media(it.media!!) }
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ class AnilistUserRepository @Inject constructor(
fun fetchViewer(): Flow<Result<ViewerQuery.Viewer>> {
return apolloClient
.query(ViewerQuery())
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.fetchPolicy(FetchPolicy.CacheFirst)
.toFlow()
.asResult { it.viewer!! }
}
Expand Down
Expand Up @@ -61,6 +61,7 @@ import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.imashnake.animite.R
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.ui.layouts.BannerLayout
import com.imashnake.animite.core.R as coreR
imashnake0 marked this conversation as resolved.
Show resolved Hide resolved

@Destination
@Composable
Expand Down Expand Up @@ -174,7 +175,7 @@ fun HomeScreen(
},
contentModifier = Modifier.padding(
top = LocalPaddings.current.large,
bottom = dimensionResource(R.dimen.navigation_bar_height)
bottom = dimensionResource(coreR.dimen.navigation_bar_height)
)
)
}
Expand Down
Expand Up @@ -10,7 +10,7 @@ import com.imashnake.animite.core.data.Resource
import com.imashnake.animite.core.data.Resource.Companion.asResource
import com.imashnake.animite.dev.ext.nextSeason
import com.imashnake.animite.dev.ext.season
import com.imashnake.animite.dev.internal.Constants
import com.imashnake.animite.core.Constants
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.SharingStarted
Expand Down
Expand Up @@ -75,7 +75,8 @@ import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.ui.NestedScrollableContent
import com.imashnake.animite.core.ui.layouts.BannerLayout
import com.imashnake.animite.core.ui.layouts.TranslucentStatusBarLayout
import com.imashnake.animite.dev.internal.Constants
import com.imashnake.animite.core.Constants
import com.imashnake.animite.core.extensions.crossfadeModel
import com.imashnake.animite.features.ui.MediaSmall
import com.imashnake.animite.features.ui.MediaSmallRow
import com.ramcosta.composedestinations.annotation.Destination
Expand Down Expand Up @@ -218,10 +219,7 @@ fun MediaBanner(
) {
if (!imageUrl.isNullOrEmpty()) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.crossfade(Constants.CROSSFADE_DURATION)
.build(),
model = crossfadeModel(imageUrl),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier,
Expand Down
Expand Up @@ -32,7 +32,8 @@ import com.ramcosta.composedestinations.spec.DestinationSpec
import com.ramcosta.composedestinations.utils.currentDestinationAsState
import com.ramcosta.composedestinations.utils.isRouteOnBackStack
import com.ramcosta.composedestinations.utils.startDestination
import com.imashnake.animite.R as Res
import com.imashnake.animite.R
import com.imashnake.animite.core.R as coreR

// TODO: Ripple where?
@Composable
Expand All @@ -42,7 +43,7 @@ fun NavigationBar(
// TODO: Can we use `navigationBarsPadding()` instead?
NavigationBar(
Modifier.height(
dimensionResource(Res.dimen.navigation_bar_height) + WindowInsets
dimensionResource(coreR.dimen.navigation_bar_height) + WindowInsets
.navigationBars
.asPaddingValues()
.calculateBottomPadding()
Expand Down Expand Up @@ -87,10 +88,10 @@ enum class NavigationBarPaths(
{
Icon(
imageVector = ImageVector.vectorResource(
id = Res.drawable.rslash
id = R.drawable.rslash
),
contentDescription = stringResource(
id = Res.string.rslash
id = R.string.rslash
)
)
}
Expand All @@ -100,10 +101,10 @@ enum class NavigationBarPaths(
{
Icon(
imageVector = ImageVector.vectorResource(
id = Res.drawable.home
id = R.drawable.home
),
contentDescription = stringResource(
id = Res.string.home
id = R.string.home
)
)
}
Expand All @@ -114,7 +115,7 @@ enum class NavigationBarPaths(
Icon(
imageVector = Icons.Rounded.AccountCircle,
contentDescription = stringResource(
id = Res.string.profile
id = R.string.profile
),
// TODO: Adding this modifier lets us control the icon's size;
// see how this works and unhardcode the dimensions.
Expand Down
Expand Up @@ -51,8 +51,9 @@ import com.imashnake.animite.api.anilist.sanitize.search.Search
import com.imashnake.animite.api.anilist.type.MediaType
import com.imashnake.animite.core.extensions.landscapeCutoutPadding
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.dev.internal.Constants
import com.imashnake.animite.core.Constants
import com.imashnake.animite.features.ui.MediaSmall
import com.imashnake.animite.core.R as coreR

/**
* Search bar along with a Front Drop list.
Expand All @@ -78,7 +79,7 @@ fun SearchFrontDrop(
var isExpanded by rememberSaveable { mutableStateOf(false) }
val searchBarBottomPadding: Dp by animateDpAsState(
targetValue = if (hasExtraPadding) {
dimensionResource(R.dimen.navigation_bar_height)
dimensionResource(coreR.dimen.navigation_bar_height)
} else 0.dp,
label = "translate_search_bar"
)
Expand Down Expand Up @@ -143,7 +144,7 @@ fun SearchList(
bottom = dimensionResource(R.dimen.search_bar_height)
+ LocalPaddings.current.large
+ LocalPaddings.current.large
+ dimensionResource(R.dimen.navigation_bar_height)
+ dimensionResource(coreR.dimen.navigation_bar_height)
+ WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
),
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.small)
Expand Down
Expand Up @@ -7,7 +7,7 @@ import com.imashnake.animite.api.anilist.AnilistSearchRepository
import com.imashnake.animite.api.anilist.type.MediaType
import com.imashnake.animite.core.data.Resource
import com.imashnake.animite.core.data.Resource.Companion.asResource
import com.imashnake.animite.dev.internal.Constants
import com.imashnake.animite.core.Constants
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.SharingStarted
Expand Down
Expand Up @@ -24,19 +24,17 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.imashnake.animite.R
import com.imashnake.animite.api.anilist.MediaListQuery
import com.imashnake.animite.api.anilist.type.MediaType
import com.imashnake.animite.dev.internal.Constants.CROSSFADE_DURATION
import com.imashnake.animite.R
import com.imashnake.animite.core.extensions.crossfadeModel
import com.imashnake.animite.core.ui.LocalPaddings

/**
Expand Down Expand Up @@ -89,10 +87,7 @@ fun MediaSmall(
shape = RoundedCornerShape(dimensionResource(R.dimen.media_card_corner_radius))
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(image)
.crossfade(CROSSFADE_DURATION)
.build(),
model = crossfadeModel(image),
contentDescription = label,
contentScale = ContentScale.Crop,
modifier = Modifier
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/dimens.xml
Expand Up @@ -4,8 +4,6 @@
<dimen name="media_card_text_padding_horizontal">16dp</dimen>
<dimen name="media_card_text_padding_vertical">10dp</dimen>

<dimen name="navigation_bar_height">65dp</dimen>

<dimen name="media_card_width">140dp</dimen>
<dimen name="media_card_height">200dp</dimen>
<dimen name="media_details_height">172dp</dimen>
Expand Down
6 changes: 6 additions & 0 deletions core/build.gradle.kts
Expand Up @@ -39,6 +39,12 @@ dependencies {
debugImplementation(libs.compose.ui.tooling)
implementation(libs.compose.ui.toolingPreview)

// Compose Markdown
implementation(libs.boswelja.composeMarkdown.material3)

// Coil
implementation(libs.coil.compose)

// Kotlin
implementation(libs.kotlin.coroutines.android)
implementation(libs.kotlin.coroutines.core)
Expand Down
@@ -1,4 +1,4 @@
package com.imashnake.animite.dev.internal
package com.imashnake.animite.core

object Constants {
const val ANILIST_BASE_URL = "https://graphql.anilist.co/"
Expand Down
@@ -0,0 +1,18 @@
package com.imashnake.animite.core.extensions

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import coil.request.ImageRequest
import com.imashnake.animite.core.Constants

/**
* Crossfades images after the request succeeds.
*
* @param model is the argument of [ImageRequest.Builder.data].
*/
@Composable
fun crossfadeModel(model: Any?) = ImageRequest
.Builder(LocalContext.current)
.data(model)
.crossfade(Constants.CROSSFADE_DURATION)
.build()
@@ -0,0 +1,42 @@
package com.imashnake.animite.core.extensions

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.boswelja.markdown.style.BlockQuoteStyle
import com.boswelja.markdown.style.CodeBlockStyle
import com.imashnake.animite.core.R

@Composable
fun animiteBlockQuoteStyle(
background: Color = MaterialTheme.colorScheme.surfaceVariant,
barWidth: Dp = dimensionResource(R.dimen.markdown_block_corner_radius),
barColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
barShape: Shape = RectangleShape,
innerPadding: PaddingValues = PaddingValues(8.dp)
) = BlockQuoteStyle(
background = background,
shape = RoundedCornerShape(barWidth),
imashnake0 marked this conversation as resolved.
Show resolved Hide resolved
barShape = barShape,
barWidth = barWidth,
barColor = barColor,
innerPadding = innerPadding
)

@Composable
fun animiteCodeBlockStyle(
background: Color = MaterialTheme.colorScheme.surfaceVariant,
shape: Shape = RoundedCornerShape(dimensionResource(R.dimen.markdown_block_corner_radius)),
imashnake0 marked this conversation as resolved.
Show resolved Hide resolved
innerPadding: PaddingValues = PaddingValues(8.dp)
) = CodeBlockStyle(
background = background,
shape = shape,
innerPadding = innerPadding
)
Expand Up @@ -3,10 +3,13 @@ package com.imashnake.animite.core.extensions
import android.content.res.Configuration
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.displayCutoutPadding
import androidx.compose.foundation.layout.heightIn
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

fun Modifier.landscapeCutoutPadding() = composed {
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Expand All @@ -19,3 +22,5 @@ fun Modifier.landscapeCutoutPadding() = composed {
fun Modifier.bannerParallax(scrollState: ScrollState) = graphicsLayer {
translationY = 0.7f * scrollState.value
}

fun Modifier.maxHeight(max: Dp) = this.heightIn(0.dp, max)
6 changes: 5 additions & 1 deletion core/src/main/res/values/dimens.xml
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="zero">0dp</dimen>
<dimen name="ultra_tiny_padding">4dp</dimen>
<dimen name="ultra_tiny_padding">1dp</dimen>
<dimen name="tiny_padding">4dp</dimen>
<dimen name="small_padding">8dp</dimen>
<dimen name="medium_padding">16dp</dimen>
<dimen name="large_padding">24dp</dimen>

<dimen name="markdown_block_corner_radius">3dp</dimen>

<dimen name="navigation_bar_height">65dp</dimen>

<dimen name="progress_indicator_width">100dp</dimen>
<dimen name="progress_indicator_height">3dp</dimen>

Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Expand Up @@ -79,6 +79,10 @@ junit = "4.13.2"
# https://github.com/detekt/detekt/releases.
detekt = "1.23.4"

# Compose Markdown
# https://github.com/boswelja/compose-markdown.
composeMarkdown = "1.0.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brace for 1.0.4



[libraries]

Expand All @@ -104,6 +108,7 @@ apollo-runtime = { group = "com.apollographql.apollo3", name = "apollo-runtime"
apollo-cache-memory = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache", version.ref = "apollo" }
apollo-cache-sqlite = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache-sqlite", version.ref = "apollo" }
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
boswelja-composeMarkdown-material3 = { group = "io.github.boswelja.markdown", name = "material3", version.ref = "composeMarkdown" }
kotlin-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
kotlin-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
datastore = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastore" }
Expand Down
6 changes: 6 additions & 0 deletions profile/build.gradle.kts
Expand Up @@ -53,6 +53,12 @@ dependencies {
debugImplementation(libs.compose.ui.tooling)
implementation(libs.compose.ui.toolingPreview)

// Compose Markdown
implementation(libs.boswelja.composeMarkdown.material3)

// Coil
implementation(libs.coil.compose)

// Kotlin
implementation(libs.kotlin.coroutines.android)
implementation(libs.kotlin.coroutines.core)
Expand Down