Skip to content

Commit

Permalink
Merge pull request #268 from orcinusbr/feat-ui/registration
Browse files Browse the repository at this point in the history
Add registration feature
  • Loading branch information
jeanbarrossilva authored Apr 1, 2024
2 parents ae3d0c3 + d67a098 commit e01d3ac
Show file tree
Hide file tree
Showing 39 changed files with 1,738 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Note that Orca isn't a fork of the official app. Its overall structure has been
## Structure

<div align="center">
<img src="https://github.com/orcaformastodon/android/assets/38408390/d5e5fc0a-7f62-442c-a34f-9d4eb7070ef0" />
<img src="https://github.com/orcinusbr/orca-android/assets/38408390/95f934e2-155a-415a-81c7-b13095d6d1b2" />
</div>

Each module represents the context to which its underlying structures are related.
Expand Down
36 changes: 36 additions & 0 deletions composite/status/build.gradle.kts
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)
}
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 {}
}
}
}
}
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)
}
}
16 changes: 16 additions & 0 deletions composite/status/src/main/AndroidManifest.xml
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 />
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)
}
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}") } }
}
Loading

0 comments on commit e01d3ac

Please sign in to comment.