diff --git a/src/i18n.ts b/src/i18n.ts index 48adfda..9d108e5 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -22,6 +22,7 @@ const i18n = new I18n({ ACTIVITY_TYPE_WATERED: 'gegossen', ACTIVITY_TYPE_FERTILISED: 'gedüngt', ACTIVITY_TYPE_SPRAYED: 'gespritzt', + ACTIVITY_TYPE_SWITCH_AUTO_WATERING: 'Automatische Bewässerung aktualisieren', LAST_TIME_WATERED: 'Letztes Mal gegossen', LAST_TIME_FERTILISED: 'Letztes Mal gedüngt', LAST_TIME_SPRAYED: 'Letztes Mal gespritzt', diff --git a/src/model/ActivityType.ts b/src/model/ActivityType.ts index f7b16d8..7c4baa0 100644 --- a/src/model/ActivityType.ts +++ b/src/model/ActivityType.ts @@ -1,5 +1,6 @@ export enum ActivityType { ACTIVITY_TYPE_WATERED, ACTIVITY_TYPE_FERTILISED, - ACTIVITY_TYPE_SPRAYED + ACTIVITY_TYPE_SPRAYED, + ACTIVITY_TYPE_SWITCH_AUTO_WATERING } \ No newline at end of file diff --git a/src/stacks/default/tabs/activities/ActivitiesStackRoute.ts b/src/stacks/default/tabs/activities/ActivitiesStackRoute.ts index 71a7cb0..42f950c 100644 --- a/src/stacks/default/tabs/activities/ActivitiesStackRoute.ts +++ b/src/stacks/default/tabs/activities/ActivitiesStackRoute.ts @@ -17,7 +17,7 @@ export type ActivitiesStackRouteParams = { } "activity-plant-selection": { activityType: ActivityType, - activityDate: string + activityDate?: string } } diff --git a/src/stacks/default/tabs/activities/screens/ActivitiesOverviewScreen.tsx b/src/stacks/default/tabs/activities/screens/ActivitiesOverviewScreen.tsx index b81cbbf..8e3a67f 100644 --- a/src/stacks/default/tabs/activities/screens/ActivitiesOverviewScreen.tsx +++ b/src/stacks/default/tabs/activities/screens/ActivitiesOverviewScreen.tsx @@ -14,11 +14,22 @@ export default () => { const navigation = useNavigation>(); const route = useRoute>(); + function needsDate(activityType: ActivityType) { + return activityType !== ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING; + } + function executeActivity(activityType: ActivityType) { - navigation.navigate({ - name: ActivitiesStackRoute.ACTIVITY_DATE_SELECTION, - params: {activityType} - }); + if (needsDate(activityType)) { + navigation.navigate({ + name: ActivitiesStackRoute.ACTIVITY_DATE_SELECTION, + params: {activityType} + }); + } else { + navigation.navigate({ + name: ActivitiesStackRoute.ACTIVITY_PLANT_SELECTION, + params: {activityType} + }); + } } const renderActivityButtons = enumValues(ActivityType) diff --git a/src/stacks/default/tabs/activities/screens/ActivityPlantSelectionScreen.tsx b/src/stacks/default/tabs/activities/screens/ActivityPlantSelectionScreen.tsx index aeb9e20..5abc5c9 100644 --- a/src/stacks/default/tabs/activities/screens/ActivityPlantSelectionScreen.tsx +++ b/src/stacks/default/tabs/activities/screens/ActivityPlantSelectionScreen.tsx @@ -44,11 +44,22 @@ export default () => { case ActivityType.ACTIVITY_TYPE_SPRAYED: plant.lastTimeSprayed = activityDate; break; + case ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING: + plant.automaticallyWatered = true; + break; } await PlantService.savePlant(plant); } + if (activityType === ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING) { + const deselectedPlants = plants.filter(plant => !selectedPlants.find(selectedPlant => plant.id === selectedPlant.id)); + for (const plant of deselectedPlants) { + plant.automaticallyWatered = false; + await PlantService.savePlant(plant); + } + } + navigation.dispatch(StackActions.popToTop()); }