From c6dbac06574a178cc0efc9b72b317e1a9cdb44a3 Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 21 Jan 2023 10:16:33 +0530 Subject: [PATCH] WTA #71: Added composable for project details page header. --- .../jacob/wakatimeapp/core/ui/WtaPreviews.kt | 6 ++ .../ui/components/DetailsPageHeader.kt | 67 +++++++++++++++++++ .../com/jacob/wakatimeapp/home/ui/HomePage.kt | 16 +---- tools/detekt-config.yml | 2 +- 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 details/src/main/java/com/jacob/wakatimeapp/details/ui/components/DetailsPageHeader.kt diff --git a/core/ui/src/main/java/com/jacob/wakatimeapp/core/ui/WtaPreviews.kt b/core/ui/src/main/java/com/jacob/wakatimeapp/core/ui/WtaPreviews.kt index 937ef6c6..db59d8ea 100644 --- a/core/ui/src/main/java/com/jacob/wakatimeapp/core/ui/WtaPreviews.kt +++ b/core/ui/src/main/java/com/jacob/wakatimeapp/core/ui/WtaPreviews.kt @@ -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, @@ -28,4 +30,8 @@ import androidx.compose.ui.tooling.preview.Preview showSystemUi = true, group = "full", ) +annotation class WtaDevicePreviews + +@WtaComponentPreviews +@WtaDevicePreviews annotation class WtaPreviews diff --git a/details/src/main/java/com/jacob/wakatimeapp/details/ui/components/DetailsPageHeader.kt b/details/src/main/java/com/jacob/wakatimeapp/details/ui/components/DetailsPageHeader.kt new file mode 100644 index 00000000..804d0080 --- /dev/null +++ b/details/src/main/java/com/jacob/wakatimeapp/details/ui/components/DetailsPageHeader.kt @@ -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( + listOf( + "Project Name", + "Some very long project name" + ), +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt b/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt index c3cec6c1..41c93498 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt @@ -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 @@ -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 @@ -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, diff --git a/tools/detekt-config.yml b/tools/detekt-config.yml index 0e121c9c..51f366fa 100644 --- a/tools/detekt-config.yml +++ b/tools/detekt-config.yml @@ -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