1 /*
2  * Copyright (c) 2021 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_PICKER_PICKER_DATETIME_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_DATETIME_COMPONENT_H
18 
19 #include "core/components/picker/picker_date_component.h"
20 #include "core/components/picker/picker_time_component.h"
21 
22 namespace OHOS::Ace {
23 
24 class PickerDateTimeComponent : public PickerTimeComponent {
25     DECLARE_ACE_TYPE(PickerDateTimeComponent, PickerTimeComponent);
26 
27 public:
28     PickerDateTimeComponent();
29     ~PickerDateTimeComponent() override = default;
30 
SetSelectedDateTime(const PickerDateTime & value)31     void SetSelectedDateTime(const PickerDateTime& value)
32     {
33         selectedDate_ = value.GetDate();
34         SetSelectedTime(value.GetTime());
35     }
36 
SetShowLunar(bool value)37     void SetShowLunar(bool value)
38     {
39         lunar_ = value;
40     }
41 
SubsidiaryShowed()42     bool SubsidiaryShowed() const override
43     {
44         if (!datePicker_) {
45             return false;
46         }
47         return datePicker_->IsDialogShowed();
48     }
49 
IsShowLunar()50     bool IsShowLunar() const override
51     {
52         return lunar_;
53     }
54 
55     void OnTitleBuilding() override;
56 
57     void OnColumnsBuilding() override;
58 
59     void OnSelectedSaving() override;
60 
61     std::string GetSelectedObject(bool isColumnChange,
62         const std::string& changeColumnTag, int32_t status = -1) const override;
63 
64     void OnLunarCallback(bool checked, std::vector<std::string>& resultTags) override;
65 
66     void OnTriangleCallback(bool value) override;
67 
68     void OnColumnsCreating() override;
69 
70     void OnDataLinking(const std::string& tag, bool isAdd, uint32_t index,
71         std::vector<std::string>& resultTags) override;
72 
73 private:
74     std::string GetMonthDayFormatString(bool lunar, uint32_t days) const;
75 
76     void FillSolarLunarDays(bool lunar, const PickerDate& currentDate);
77 
78     void InitDatePicker();
79     void ShowDatePicker();
80     void HideDatePicker();
81     void OnSubsidiaryChange(const PickerDate& date);
82 
83     RefPtr<PickerDateComponent> datePicker_;
84     PickerDate selectedDate_ = PickerDate::Current();
85     PickerDate currentDate_ = PickerDate::Current();
86     bool lunar_ = false;
87 };
88 
89 } // namespace OHOS::Ace
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_DATETIME_COMPONENT_H
92