• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H
18 
19 #include <mutex>
20 
21 #include "core/components/picker/picker_data.h"
22 #include "core/components/picker/picker_theme.h"
23 #include "core/components_ng/pattern/picker/picker_type_define.h"
24 
25 namespace OHOS::Ace {
26 using DateChangeEvent = std::function<void(const BaseEventInfo* info)>;
27 struct PickerDialogInfo {
28     bool isLunar;
29     PickerDate parseStartDate;
30     PickerDate parseEndDate;
31     PickerDate parseSelectedDate;
32     PickerTime pickerTime;
33     bool isUseMilitaryTime;
34     bool isSelectedTime;
35     bool isStartDate;
36     bool isEndDate;
37     bool isSelectedDate;
38     std::optional<DialogAlignment> alignment;
39     std::optional<DimensionOffset> offset;
40     std::optional<DimensionRect> maskRect;
41 };
42 class DatePickerModel {
43 public:
44     static DatePickerModel* GetInstance();
45     virtual ~DatePickerModel() = default;
46 
47     virtual void CreateDatePicker(RefPtr<PickerTheme> theme) = 0;
48     virtual void CreateTimePicker(RefPtr<PickerTheme> theme) = 0;
49     virtual void SetStartDate(const PickerDate& value) = 0;
50     virtual void SetEndDate(const PickerDate& value) = 0;
51     virtual void SetSelectedDate(const PickerDate& value) = 0;
52     virtual void SetShowLunar(bool lunar) = 0;
53     virtual void SetOnChange(DateChangeEvent&& onChange) = 0;
54     virtual void SetOnDateChange(DateChangeEvent&& onChange) = 0;
55     virtual void SetSelectedTime(const PickerTime& selectedTime) = 0;
56     virtual void SetHour24(bool value) = 0;
57     virtual void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0;
58     virtual void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0;
59     virtual void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0;
60     virtual void SetBackgroundColor(const Color& color) = 0;
61     virtual void SetChangeEvent(DateChangeEvent&& onChange) = 0;
62 
63 private:
64     static std::unique_ptr<DatePickerModel> datePickerInstance_;
65     static std::mutex mutex_;
66 };
67 
68 class DatePickerDialogModel {
69 public:
70     static DatePickerDialogModel* GetInstance();
71     virtual ~DatePickerDialogModel() = default;
72 
73     virtual void SetDatePickerDialogShow(PickerDialogInfo& pickerDialog, NG::DatePickerSettingData& settingData,
74         std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept,
75         std::function<void(const std::string&)>&& onChange, std::function<void(const std::string&)>&& onDateAccept,
76         std::function<void(const std::string&)>&& onDateChange, DatePickerType pickerType) = 0;
77 
78 private:
79     static std::unique_ptr<DatePickerDialogModel> datePickerDialogInstance_;
80     static std::mutex mutex_;
81 };
82 } // namespace OHOS::Ace
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H
84