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

Chore: Exercise Overview adjustments and PR cleanup #100

Merged
merged 12 commits into from
Nov 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -29,6 +29,7 @@ import de.tum.informatics.www1.artemis.native_app.core.model.exercise.latestPart
import de.tum.informatics.www1.artemis.native_app.core.model.exercise.participation.Participation
import de.tum.informatics.www1.artemis.native_app.core.ui.R
import de.tum.informatics.www1.artemis.native_app.core.ui.date.hasPassed
import de.tum.informatics.www1.artemis.native_app.core.ui.material.colors.ParticipationNotPossibleInfoMessageCardColors

/**
* This composable composes up to two buttons. The modifier parameter is applied to every button
Expand Down Expand Up @@ -96,43 +97,50 @@ fun ExerciseActionButtons(
}

if (templateStatus != null) {
if (exercise is TextExercise) {
if (latestParticipation?.initializationState == Participation.InitializationState.INITIALIZED) {
Button(
modifier = modifier,
onClick = {
actions.onClickOpenTextExercise(
latestParticipation.id ?: return@Button
when (exercise) {
is TextExercise -> {
if (latestParticipation?.initializationState == Participation.InitializationState.INITIALIZED) {
Button(
modifier = modifier,
onClick = {
actions.onClickOpenTextExercise(
latestParticipation.id ?: return@Button
)
},
enabled = !exercise.teamMode
) {
Text(
text = stringResource(id = R.string.exercise_actions_open_exercise_button)
)
},
enabled = !exercise.teamMode
) {
Text(
text = stringResource(id = R.string.exercise_actions_open_exercise_button)
)
}
}
}

if (latestParticipation?.initializationState == Participation.InitializationState.FINISHED &&
(latestParticipation.results.isNullOrEmpty() || !showResult)
) {
Button(
modifier = modifier,
onClick = {
actions.onClickOpenTextExercise(
latestParticipation.id ?: return@Button
)
},
enabled = !exercise.teamMode
if (latestParticipation?.initializationState == Participation.InitializationState.FINISHED &&
(latestParticipation.results.isNullOrEmpty() || !showResult)
) {
Text(
text = stringResource(id = R.string.exercise_actions_view_submission_button)
)
Button(
modifier = modifier,
onClick = {
actions.onClickOpenTextExercise(
latestParticipation.id ?: return@Button
)
},
enabled = !exercise.teamMode
) {
Text(
text = stringResource(id = R.string.exercise_actions_view_submission_button)
)
}
}
}
} else {
Row(modifier=Modifier.padding(top=2.dp, bottom = 2.dp)) {
InfoMessageCard()
// TODO: The following code is temporarily disabled. See https://github.com/ls1intum/artemis-android/issues/107
//is QuizExercise -> {
// Do not show participation not possible info card for quiz exercises
//}
else -> {
Row(modifier=Modifier.padding(top=2.dp, bottom = 2.dp)) {
ParticipationNotPossibleInfoMessageCard()
}
}
}

Expand Down Expand Up @@ -209,25 +217,29 @@ class BoundExerciseActions(


@Composable
fun InfoMessageCard() {
fun ParticipationNotPossibleInfoMessageCard() {
Box(
modifier = Modifier
.border(width = 2.dp, color = Color.LightGray)
.background(Color(0xFFB3E5FC)) // Light sky blue background
.padding(10.dp)
.border(
width = 1.dp,
color = ParticipationNotPossibleInfoMessageCardColors.border,
shape = RoundedCornerShape(4.dp)
)
.background(ParticipationNotPossibleInfoMessageCardColors.background)
.padding(8.dp)
.fillMaxWidth()
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
imageVector = Icons.Filled.Info,
contentDescription = "Information",
imageVector = Icons.Outlined.Info,
contentDescription = null,
modifier = Modifier.padding(end = 8.dp),
tint = Color(0xFF0288D1)
tint = ParticipationNotPossibleInfoMessageCardColors.text
)
Text(
text = stringResource(id = R.string.exercise_participation_not_possible),
fontSize = 16.sp,
color = Color.Black
color = ParticipationNotPossibleInfoMessageCardColors.text
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import de.tum.informatics.www1.artemis.native_app.core.model.exercise.Exercise
import de.tum.informatics.www1.artemis.native_app.core.ui.R
import de.tum.informatics.www1.artemis.native_app.core.ui.date.getRelativeTime
import de.tum.informatics.www1.artemis.native_app.core.ui.getWindowSizeClass
import de.tum.informatics.www1.artemis.native_app.core.ui.material.easyColor
import de.tum.informatics.www1.artemis.native_app.core.ui.material.hardColor
import de.tum.informatics.www1.artemis.native_app.core.ui.material.mediumColor
import de.tum.informatics.www1.artemis.native_app.core.ui.material.colors.DifficultyColors

/**
* Display a single exercise.
Expand Down Expand Up @@ -113,13 +111,13 @@ private fun DifficultyRectangle(modifier: Modifier, difficulty: Exercise.Difficu
.background(
color = when (difficulty) {
Exercise.Difficulty.EASY ->
easyColor
DifficultyColors.easy

Exercise.Difficulty.MEDIUM ->
mediumColor
DifficultyColors.medium

Exercise.Difficulty.HARD ->
hardColor
DifficultyColors.hard
}
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.material.colors

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

object DifficultyColors {
val hard: Color
@Composable get() = Color(0xffdc3545)
val medium: Color
@Composable get() = Color(0xffffc107)
val easy: Color
@Composable get() = Color(0xff28a745)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.material.colors

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

object ParticipationNotPossibleInfoMessageCardColors {
val background: Color
@Composable get() = if(isSystemInDarkTheme()) Color(0xFF062A30) else Color(0xFFD1ECF1)
val border: Color
@Composable get() = if(isSystemInDarkTheme()) Color(0xFF148EA1) else Color(0xFFA2DAE3)
val text: Color
@Composable get() = if(isSystemInDarkTheme()) Color(0xFF36CEE6) else Color(0xFF09414A)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.material
package de.tum.informatics.www1.artemis.native_app.core.ui.material.colors

import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.Composable
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions core/ui/src/main/res/values/exercise_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

<!-- Exercise action buttons -->
<string name="exercise_actions_view_result_button">View result</string>
<string name="exercise_participation_not_possible">Participating this exercise is currently
not possible in the mobile app.</string>
<string name="exercise_participation_not_possible">Participating in this exercise is currently
not possible in the mobile app</string>
<string name="exercise_actions_start_exercise_button">Start exercise</string>
<string name="exercise_actions_open_exercise_button">Open exercise</string>
<string name="exercise_actions_view_submission_button">View submission</string>
Expand Down
Loading
Loading