-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from orcinusbr/feat-ui/registration
Add registration feature
- Loading branch information
Showing
39 changed files
with
1,738 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright © 2024 Orca | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If | ||
* not, see https://www.gnu.org/licenses. | ||
*/ | ||
|
||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
buildFeatures.compose = true | ||
composeOptions.kotlinCompilerExtensionVersion = libs.versions.android.compose.compiler.get() | ||
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
dependencies { | ||
androidTestImplementation(libs.android.compose.ui.test.junit) | ||
androidTestImplementation(libs.android.compose.ui.test.manifest) | ||
androidTestImplementation(libs.assertk) | ||
androidTestImplementation(libs.kotlin.test) | ||
|
||
implementation(project(":core:sample")) | ||
implementation(project(":platform:autos")) | ||
implementation(libs.android.core) | ||
} |
39 changes: 39 additions & 0 deletions
39
...st/java/com/jeanbarrossilva/orca/composite/status/state/StatusCardStateExtensionsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright © 2024 Orca | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If | ||
* not, see https://www.gnu.org/licenses. | ||
*/ | ||
|
||
package com.jeanbarrossilva.orca.composite.status.state | ||
|
||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import assertk.assertThat | ||
import assertk.assertions.isSameAs | ||
import kotlin.test.Test | ||
import org.junit.Rule | ||
|
||
internal class StatusCardStateExtensionsTests { | ||
@get:Rule val composeRule = createComposeRule() | ||
|
||
@Test | ||
fun remembersEverLoadingState() { | ||
composeRule.setContent { | ||
val state = rememberStatusCardState() | ||
|
||
DisposableEffect(state) { | ||
assertThat(state).isSameAs(StatusCardState.EverLoading) | ||
onDispose {} | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../androidTest/java/com/jeanbarrossilva/orca/composite/status/state/StatusCardStateTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright © 2024 Orca | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If | ||
* not, see https://www.gnu.org/licenses. | ||
*/ | ||
|
||
package com.jeanbarrossilva.orca.composite.status.state | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isSameAs | ||
import com.jeanbarrossilva.orca.composite.status.Status | ||
import kotlin.test.Test | ||
|
||
internal class StatusCardStateTests { | ||
@Test | ||
fun changesStatusToNonLoadingOnes() { | ||
Status.entries | ||
.filter { it != Status.Loading } | ||
.forEach { | ||
assertThat(StatusCardState(targetStatus = it).apply(StatusCardState::loadStatus).status) | ||
.isSameAs(it) | ||
} | ||
} | ||
|
||
@Test | ||
fun everLoadingStateNeverLoads() { | ||
StatusCardState.EverLoading.loadStatus() | ||
assertThat(StatusCardState.EverLoading.status).isSameAs(Status.Loading) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright © 2024 Orca | ||
~ | ||
~ This program is free software: you can redistribute it and/or modify it under the terms of the | ||
~ GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
~ License, or (at your option) any later version. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
~ even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
~ General Public License for more details. | ||
~ | ||
~ You should have received a copy of the GNU General Public License along with this program. If | ||
~ not, see https://www.gnu.org/licenses. | ||
--> | ||
|
||
<manifest /> |
122 changes: 122 additions & 0 deletions
122
composite/status/src/main/java/com/jeanbarrossilva/orca/composite/status/Status.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright © 2024 Orca | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If | ||
* not, see https://www.gnu.org/licenses. | ||
*/ | ||
|
||
package com.jeanbarrossilva.orca.composite.status | ||
|
||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.StrokeCap | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.jeanbarrossilva.orca.core.instance.Instance | ||
import com.jeanbarrossilva.orca.platform.autos.colors.asColor | ||
import com.jeanbarrossilva.orca.platform.autos.theme.AutosTheme | ||
|
||
/** Account registration stage that a [StatusCard] can represent. */ | ||
@Immutable | ||
enum class Status { | ||
/** Denotes that an [Instance] at which an account can be registered is being searched for. */ | ||
Loading { | ||
@Composable | ||
override fun Indicator(modifier: Modifier) { | ||
CircularProgressIndicator( | ||
Modifier.size(24.dp), | ||
AutosTheme.colors.secondary.asColor, | ||
strokeCap = StrokeCap.Round | ||
) | ||
} | ||
|
||
@Composable | ||
override fun Description(modifier: Modifier) { | ||
Text(stringResource(R.string.composite_status_loading)) | ||
} | ||
}, | ||
|
||
/** | ||
* Denotes that an available [Instance] has been found and an account been registered | ||
* successfully. | ||
*/ | ||
Succeeded { | ||
@Composable | ||
override fun Indicator(modifier: Modifier) { | ||
StatusIndicator( | ||
com.jeanbarrossilva.orca.platform.autos.R.drawable.icon_selected, | ||
AutosTheme.colors.activation.reposted.asColor, | ||
Color.White | ||
) | ||
} | ||
|
||
@Composable | ||
override fun Description(modifier: Modifier) { | ||
Text(stringResource(R.string.composite_status_succeeded)) | ||
} | ||
}, | ||
|
||
/** Denotes that an account couldn't be registered at a given [Instance]. */ | ||
Failed { | ||
@Composable | ||
override fun Indicator(modifier: Modifier) { | ||
StatusIndicator( | ||
com.jeanbarrossilva.orca.platform.autos.R.drawable.icon_close, | ||
AutosTheme.colors.activation.favorite.asColor, | ||
Color.White | ||
) | ||
} | ||
|
||
@Composable | ||
override fun Description(modifier: Modifier) { | ||
Text(stringResource(R.string.composite_status_failed)) | ||
} | ||
}; | ||
|
||
/** | ||
* [StatusIndicator] that matches the [Description] and helps to easily identify whether an | ||
* account could be registered or if the process itself hasn't yet completed. | ||
*/ | ||
@Composable | ||
fun Indicator() { | ||
Indicator(Modifier) | ||
} | ||
|
||
/** | ||
* [Text] that clearly describes whether an account has been registered, hasn't or the process is | ||
* still ongoing. | ||
*/ | ||
@Composable | ||
fun Description() { | ||
Description(Modifier) | ||
} | ||
|
||
/** | ||
* [StatusIndicator] that matches the [Description] and helps to easily identify whether an | ||
* account could be registered or if the process itself hasn't yet completed. | ||
* | ||
* @param modifier [Modifier] that is applied to the [StatusIndicator]. | ||
*/ | ||
@Composable abstract fun Indicator(modifier: Modifier) | ||
|
||
/** | ||
* [Text] that clearly describes whether an account has been registered, hasn't or the process is | ||
* still ongoing. | ||
* | ||
* @param modifier [Modifier] that is applied to the [Text]. | ||
*/ | ||
@Composable abstract fun Description(modifier: Modifier) | ||
} |
109 changes: 109 additions & 0 deletions
109
composite/status/src/main/java/com/jeanbarrossilva/orca/composite/status/StatusCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright © 2024 Orca | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If | ||
* not, see https://www.gnu.org/licenses. | ||
*/ | ||
|
||
package com.jeanbarrossilva.orca.composite.status | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.ProvideTextStyle | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.jeanbarrossilva.orca.composite.status.state.StatusCardState | ||
import com.jeanbarrossilva.orca.composite.status.state.rememberStatusCardState | ||
import com.jeanbarrossilva.orca.core.instance.domain.Domain | ||
import com.jeanbarrossilva.orca.core.sample.instance.domain.sample | ||
import com.jeanbarrossilva.orca.platform.autos.borders.asBorderStroke | ||
import com.jeanbarrossilva.orca.platform.autos.theme.AutosTheme | ||
import com.jeanbarrossilva.orca.platform.autos.theme.MultiThemePreview | ||
|
||
/** | ||
* [Card] for displaying the progress of an account registration process. | ||
* | ||
* @param state [StatusCardState] that holds the current operation [Status]. | ||
* @param modifier [Modifier] that is applied to the [Card]. | ||
* @param title Message shown alongside an indicator and a description of what the current [Status] | ||
* is. | ||
* @see rememberStatusCardState | ||
* @see Status.Indicator | ||
* @see Status.Description | ||
*/ | ||
@Composable | ||
fun StatusCard( | ||
state: StatusCardState, | ||
modifier: Modifier = Modifier, | ||
title: @Composable () -> Unit | ||
) { | ||
val spacing = AutosTheme.spacings.large.dp | ||
|
||
Card( | ||
modifier, | ||
colors = CardDefaults.outlinedCardColors(), | ||
border = AutosTheme.borders.default.asBorderStroke | ||
) { | ||
Row( | ||
Modifier.padding(spacing).fillMaxWidth(), | ||
Arrangement.spacedBy(spacing), | ||
Alignment.CenterVertically | ||
) { | ||
state.status.Indicator() | ||
|
||
Column(verticalArrangement = Arrangement.spacedBy(AutosTheme.spacings.small.dp)) { | ||
ProvideTextStyle(AutosTheme.typography.titleMedium, title) | ||
ProvideTextStyle(AutosTheme.typography.labelMedium) { state.status.Description() } | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Preview of a [StatusCard] with a loading [Status]. | ||
* | ||
* @see Status.Loading | ||
*/ | ||
@Composable | ||
@MultiThemePreview | ||
private fun LoadingStatusCardPreview() { | ||
AutosTheme { StatusCard(rememberStatusCardState()) { Text("${Domain.sample}") } } | ||
} | ||
|
||
/** | ||
* Preview of a [StatusCard] with a succeeded [Status]. | ||
* | ||
* @see Status.Succeeded | ||
*/ | ||
@Composable | ||
@MultiThemePreview | ||
private fun SucceededStatusCardPreview() { | ||
AutosTheme { StatusCard(rememberStatusCardState(Status.Succeeded)) { Text("${Domain.sample}") } } | ||
} | ||
|
||
/** | ||
* Preview of a [StatusCard] with a failed [Status]. | ||
* | ||
* @see Status.Failed | ||
*/ | ||
@Composable | ||
@MultiThemePreview | ||
private fun FailedStatusCardPreview() { | ||
AutosTheme { StatusCard(rememberStatusCardState(Status.Failed)) { Text("${Domain.sample}") } } | ||
} |
Oops, something went wrong.