Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Tests

on: [ pull_request_target ]
on: [ pull_request ]

env:
GITHUB_ACTOR: ${{ github.actor }}
Expand Down Expand Up @@ -33,8 +33,8 @@ jobs:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}
key: gradle-v2-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/libs.versions.toml') }}
restore-keys: gradle-v2-${{ runner.os }}

- name: Run Tests
run: ./gradlew test --no-daemon
Expand Down
5 changes: 4 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ kotlin {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.koin.android)
implementation(project.dependencies.platform(libs.android.firebase.bom))
}
commonMain.dependencies {
implementation(compose.runtime)
Expand Down Expand Up @@ -184,6 +183,10 @@ android {
}
dependencies {
debugImplementation(compose.uiTooling)
implementation(platform(libs.android.firebase.bom))
implementation("com.google.firebase:firebase-auth")
implementation("com.google.firebase:firebase-common")
implementation("com.google.firebase:firebase-firestore")
}
}
dependencies {
Expand Down
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/kotlin/modules/ViewModelModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import view.admin.recipes.RecipeManagementViewModel

val viewModelModules = module {
single { ViewModelEventOverview(get(), get()) }
single { CategorizedShoppingListViewModel(get(), get()) }
single { CategorizedShoppingListViewModel(get(), get(), get()) }
single { ViewModelNewParticipant(get()) }
single { SharedEventViewModel(get(), get(), get()) }
single { RecipeViewModel(get()) }
single { IngredientViewModel(get()) }
single { AllParticipantsViewModel(get()) }
single { RecipeOverviewViewModel(get(), get()) }
single { MaterialListViewModel(get(), get()) }
single { MaterialListViewModel(get(), get(), get()) }
single { CsvImportViewModel(get(), get()) }
single { CookingGroupIngredientsViewModel(get()) }
single { RecipeManagementViewModel(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ data class ShoppingListState(

class CategorizedShoppingListViewModel(
private val calculateShoppingList: CalculateShoppingList,
private val eventRepository: EventRepository
private val eventRepository: EventRepository,
private val pdfServiceModule: services.pdfService.PdfServiceModule
) :
ViewModel() {

Expand Down Expand Up @@ -66,6 +67,8 @@ class CategorizedShoppingListViewModel(
editShoppingListActions.date
)

is EditShoppingListActions.ExportPdf -> exportPdf()

}
} catch (e: Exception) {
_state.value = ResultState.Error("Fehler beim laden der Einkaufsliste")
Expand Down Expand Up @@ -237,5 +240,12 @@ class CategorizedShoppingListViewModel(
)
)
}

private fun exportPdf() {
val successData = state.value.getSuccessData() ?: return
viewModelScope.launch {
pdfServiceModule.createPdf(successData.eventId)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ interface EditShoppingListActions : BaseAction {
class DeleteShoppingItem(val shoppingIngredient: ShoppingIngredient) : EditShoppingListActions {

}
data object ExportPdf : EditShoppingListActions
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.KeyboardArrowLeft
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Save
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -49,6 +51,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import getPlatformName
import kotlinx.datetime.LocalDate
import model.Ingredient
import model.MultiDayShoppingList
Expand Down Expand Up @@ -105,16 +108,34 @@ fun ShoppingListCategorized(
items = ingredientList,
onItemAdded = { text -> onAction(EditShoppingListActions.AddNewIngredient(text)) },
topBar = {
TopAppBar(title = {
Text(text = "Einkaufsliste")
}, navigationIcon = {
NavigationIconButton(
onLeave = {
onAction(EditShoppingListActions.SaveToEvent)
onAction(NavigationActions.GoBack)
TopAppBar(
title = { Text(text = "Einkaufsliste") },
navigationIcon = {
NavigationIconButton(
onLeave = {
onAction(EditShoppingListActions.SaveToEvent)
onAction(NavigationActions.GoBack)
}
)
},
actions = {
IconButton(
onClick = { onAction(EditShoppingListActions.ExportPdf) },
modifier = Modifier.clip(RoundedCornerShape(75))
.background(MaterialTheme.colorScheme.tertiary)
) {
val imageVector = when (getPlatformName()) {
"desktop" -> Icons.Default.Save
else -> Icons.Default.Share
}
Icon(
imageVector = imageVector,
contentDescription = "Export PDF",
tint = MaterialTheme.colorScheme.onTertiary
)
}
)
})
}
)
},
content = {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ interface EditMaterialListActions : BaseAction {
data class Add(val materialName: String) : EditMaterialListActions
data class Delete(val material: Material) : EditMaterialListActions
data object SaveMaterialList : EditMaterialListActions
data object ExportPdf : EditMaterialListActions
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.background
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Save
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Card
import androidx.compose.material3.IconButton
import androidx.compose.material3.Icon
Expand All @@ -28,8 +32,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.Modifier
import getPlatformName
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
Expand Down Expand Up @@ -84,17 +90,34 @@ fun MaterialList(
},
onItemAdded = { text -> onAction(EditMaterialListActions.Add(text)) },
topBar = {
TopAppBar(title = {
Text(text = "Materialliste")
}, navigationIcon = {
NavigationIconButton(
onLeave = {
onAction(EditMaterialListActions.SaveMaterialList)
onAction(NavigationActions.GoBack)
TopAppBar(
title = { Text(text = "Materialliste") },
navigationIcon = {
NavigationIconButton(
onLeave = {
onAction(EditMaterialListActions.SaveMaterialList)
onAction(NavigationActions.GoBack)
}
)
},
actions = {
IconButton(
onClick = { onAction(EditMaterialListActions.ExportPdf) },
modifier = Modifier.clip(RoundedCornerShape(75))
.background(MaterialTheme.colorScheme.tertiary)
) {
val imageVector = when (getPlatformName()) {
"desktop" -> Icons.Default.Save
else -> Icons.Default.Share
}
Icon(
imageVector = imageVector,
contentDescription = "Export PDF",
tint = MaterialTheme.colorScheme.onTertiary
)
}

)
})
}
)
})

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ data class MaterialListState(

class MaterialListViewModel(
private val calculateMaterialList: CalculateMaterialList,
private val eventRepository: EventRepository
private val eventRepository: EventRepository,
private val pdfServiceModule: services.pdfService.PdfServiceModule
) :
ViewModel() {

Expand Down Expand Up @@ -55,6 +56,10 @@ class MaterialListViewModel(
is EditMaterialListActions.Delete -> {
deleteMaterial(materialListActions.material)
}

is EditMaterialListActions.ExportPdf -> {
exportPdf()
}
}
} catch (e: Exception) {
_state.value = ResultState.Error("Fehler beim Laden der Materialliste")
Expand Down Expand Up @@ -124,5 +129,12 @@ class MaterialListViewModel(
)
}
}

private fun exportPdf() {
val state = _state.value.getSuccessData() ?: return
viewModelScope.launch {
pdfServiceModule.createPdf(state.eventId)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private fun ShoppingAndMaterialList(
}
Button(
onClick = {
onAction(EditEventActions.ShareRecipePlanPdf)
onAction(NavigationActions.GoToRoute(Routes.RecipePlan))
},
modifier = Modifier.padding(8.dp).height(IntrinsicSize.Min),
colors = ButtonColors(
Expand Down Expand Up @@ -381,103 +381,6 @@ fun TopBarEventPage(
onAction(NavigationActions.GoBack)
onAction(EditEventActions.SaveEvent)
})
}, actions = {
Row(
horizontalArrangement = Arrangement.End,
) {

IconButton(
onClick = {
if (sharedState is ResultState.Success) {
onAction(EditShoppingListActions.Initialize(sharedState.data.event.uid))
onAction(
NavigationActions.GoToRoute(
Routes.ShoppingList(sharedState.data.event.uid)
)
)
}
},
modifier = Modifier.clip(shape = RoundedCornerShape(75))
.background(MaterialTheme.colorScheme.secondary),

) {
Icon(
imageVector = Icons.Default.ShoppingCart,
contentDescription = "Shopping Cart Icon",
tint = MaterialTheme.colorScheme.onSecondary
)
}
Spacer(modifier = Modifier.width(8.dp))
ShareRecipePlanPdfButton(onAction)
Spacer(modifier = Modifier.width(8.dp))
SharePdfButton(onAction)
}
})

}

@Composable
private fun SharePdfButton(onAction: (BaseAction) -> Unit) {
var isButtonEnabled by remember { mutableStateOf(true) }

LaunchedEffect(isButtonEnabled) {
if (isButtonEnabled) return@LaunchedEffect
else delay(2000L)
isButtonEnabled = true
}

IconButton(
onClick = {
if (isButtonEnabled) {
isButtonEnabled = false
onAction(EditEventActions.SharePdf)
}
},
enabled = isButtonEnabled,
modifier = Modifier.clip(shape = RoundedCornerShape(75))
.background(MaterialTheme.colorScheme.tertiary),
) {
val imageVector = when (getPlatformName()) {
"desktop" -> Icons.Default.Save
else -> Icons.Default.Share
}
Icon(
imageVector = imageVector,
contentDescription = "Printer Icon",
tint = MaterialTheme.colorScheme.onTertiary
)

}
}

@Composable
private fun ShareRecipePlanPdfButton(onAction: (BaseAction) -> Unit) {
var isButtonEnabled by remember { mutableStateOf(true) }

LaunchedEffect(isButtonEnabled) {
if (isButtonEnabled) return@LaunchedEffect
else delay(2000L)
isButtonEnabled = true
}

IconButton(
onClick = {
if (isButtonEnabled) {
isButtonEnabled = false
onAction(EditEventActions.ShareRecipePlanPdf)
}
},
enabled = isButtonEnabled,
modifier = Modifier.clip(shape = RoundedCornerShape(75))
.background(MaterialTheme.colorScheme.tertiary),
) {
Icon(
imageVector = Icons.Default.RestaurantMenu,
contentDescription = "Rezeptplan exportieren",
tint = MaterialTheme.colorScheme.onTertiary
)
}
}



Loading
Loading