• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export enum CategoryId {
17  Fruit = 0,
18  Vegetable,
19  Nut,
20  Seafood,
21  Dessert
22}
23
24export type Category = {
25  name: Resource
26  id: CategoryId
27}
28
29export type FoodInfo = {
30  id: number
31  letter: string
32  name: string | Resource
33  image: Resource
34  categoryId: CategoryId
35  calories: number
36  protein: number
37  fat: number
38  carbohydrates: number
39  vitaminC: number
40}
41
42export enum MealTimeId {
43  Breakfast = 0,
44  Lunch,
45  Dinner,
46  Supper,
47}
48
49export class MealTime {
50  name: Resource
51  id: MealTimeId
52
53  constructor(id: MealTimeId) {
54    this.id = id
55    switch (id) {
56      case MealTimeId.Breakfast:
57        this.name = $r('app.string.meal_time_breakfast')
58        break
59      case MealTimeId.Lunch:
60        this.name = $r('app.string.meal_time_lunch')
61        break
62      case MealTimeId.Dinner:
63        this.name = $r('app.string.meal_time_dinner')
64        break
65      case MealTimeId.Supper:
66        this.name = $r('app.string.meal_time_supper')
67        break
68    }
69  }
70}
71
72export class DietRecord {
73  id: number
74  foodId: number
75  mealTime: MealTime
76  weight: number
77
78  constructor(id: number, foodId: number, mealTime: MealTime, weight: number) {
79    this.id = id
80    this.foodId = foodId
81    this.mealTime = mealTime
82    this.weight = weight
83  }
84}
85
86@Observed
87export class OneMealStatisticsInfo {
88  mealTime: MealTime
89  mealFoods: Array<MealFoodInfo> = []
90  totalCalories: number = 0
91  totalFat: number = 0
92  totalCarbohydrates: number = 0
93  totalProtein: number = 0
94
95  constructor(mealTime: MealTime) {
96    this.mealTime = mealTime
97  }
98}
99
100export class MealFoodInfo {
101  recordId: number
102  name: string | Resource
103  image: Resource
104  calories: number
105  protein: number
106  fat: number
107  carbohydrates: number
108  weight: number
109
110  constructor(recordId: number, name: string | Resource, image: Resource, calories: number, protein: number, fat: number, carbohydrates: number, weight: number) {
111    this.recordId = recordId
112    this.name = name
113    this.image = image
114    this.calories = calories
115    this.protein = protein
116    this.fat = fat
117    this.carbohydrates = carbohydrates
118    this.weight = weight
119  }
120}