Skip to content

Commit

Permalink
WTA #71: Added composable for project details page header.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Sep 9, 2023
1 parent ee50115 commit c6dbac0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.ui.tooling.preview.Preview
uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL,
group = "component",
)
annotation class WtaComponentPreviews

@Preview(
name = "Full Device Light ",
showBackground = true,
Expand All @@ -28,4 +30,8 @@ import androidx.compose.ui.tooling.preview.Preview
showSystemUi = true,
group = "full",
)
annotation class WtaDevicePreviews

@WtaComponentPreviews
@WtaDevicePreviews
annotation class WtaPreviews
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.jacob.wakatimeapp.details.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.jacob.wakatimeapp.core.ui.WtaComponentPreviews
import com.jacob.wakatimeapp.core.ui.theme.WakaTimeAppTheme
import com.jacob.wakatimeapp.core.ui.theme.assets
import com.jacob.wakatimeapp.core.ui.theme.spacing

@Composable
internal fun DetailsPageHeader(projectName: String, modifier: Modifier = Modifier) {
Row(
modifier = modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.sMedium),
verticalAlignment = Alignment.CenterVertically,
) {
Image(
painter = painterResource(id = MaterialTheme.assets.icons.arrow),
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.surfaceTint),
contentDescription = null,
modifier = Modifier.rotate(degrees = 180f).size(30.dp),
)
Text(
text = projectName,
style = MaterialTheme.typography.displaySmall.copy(
baselineShift = BaselineShift(multiplier = -0.1f),
),
overflow = TextOverflow.Ellipsis,
maxLines = 1,
)
}
}

@WtaComponentPreviews
@Composable
private fun DetailsPageHeaderPreview(
@PreviewParameter(DetailPageHeaderPreviewProvider::class) projectName: String,
) = WakaTimeAppTheme {
Surface {
DetailsPageHeader(projectName)
}
}

private class DetailPageHeaderPreviewProvider : CollectionPreviewParameterProvider<String>(
listOf(
"Project Name",
"Some very long project name"
),
)
16 changes: 2 additions & 14 deletions home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jacob.wakatimeapp.home.ui

import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
Expand All @@ -17,13 +16,13 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import androidx.hilt.navigation.compose.hiltViewModel
import com.jacob.wakatimeapp.core.models.Error
import com.jacob.wakatimeapp.core.models.Project
import com.jacob.wakatimeapp.core.models.Time
import com.jacob.wakatimeapp.core.ui.WtaDevicePreviews
import com.jacob.wakatimeapp.core.ui.components.WtaAnimation
import com.jacob.wakatimeapp.core.ui.components.cards.TimeSpentCard
import com.jacob.wakatimeapp.core.ui.theme.WakaTimeAppTheme
Expand Down Expand Up @@ -166,18 +165,7 @@ private fun HomePageLoading() = WtaAnimation(
text = "Loading..",
)

@Preview(
apiLevel = 31,
showSystemUi = true,
showBackground = true,
uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL,
)
@Preview(
apiLevel = 31,
showSystemUi = true,
showBackground = true,
uiMode = Configuration.UI_MODE_NIGHT_YES,
)
@WtaDevicePreviews
@Composable
private fun HomePagePreview(
@PreviewParameter(HomePagePreviewProvider::class) viewState: HomePageViewState,
Expand Down
2 changes: 1 addition & 1 deletion tools/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ style:
ignoreConstantDeclaration: true
ignoreCompanionObjectPropertyDeclaration: true
ignoreAnnotation: true
ignoreAnnotated: [ 'Preview', 'WtaPreviews' ]
ignoreAnnotated: [ 'Preview', 'WtaPreviews'. 'WtaComponentPreviews', 'WtaDevicePreviews' ]
ignoreNamedArgument: true
ignoreEnums: true
ignoreRanges: false
Expand Down

0 comments on commit c6dbac0

Please sign in to comment.