1 /*
2  * Copyright (c) 2024 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_PATTERNS_OVERLAY_GROUP_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_GROUP_MANAGER_H
18 
19 #include <cstdint>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "core/components_ng/base/frame_node.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 class GroupManager : public virtual AceType {
28     DECLARE_ACE_TYPE(GroupManager, AceType)
29 
30 public:
31     GroupManager() = default;
32     ~GroupManager() override = default;
33 
34     void AddRadioToGroup(const std::string& group, int32_t radioId);
35     void RemoveRadioFromGroup(const std::string& group, int32_t radioId);
36     bool HasRadioId(const std::string& group, int32_t radioId);
37     void UpdateRadioGroupValue(const std::string& group, int32_t radioId);
38 
39     void AddCheckBoxToGroup(const std::string& group, const WeakPtr<FrameNode>& checkBoxNode);
40     void RemoveCheckBoxFromGroup(const std::string& group, int32_t checkBoxId);
41     void AddCheckBoxGroup(const std::string& group, const WeakPtr<FrameNode>& checkBoxGroupNode);
42     void RemoveCheckBoxGroup(const std::string& group, int32_t checkBoxGroupId);
43     std::list<RefPtr<FrameNode>> GetCheckboxList(const std::string& group);
44     RefPtr<FrameNode> GetCheckboxGroup(const std::string& group);
GetCheckboxGroupIsChange(const std::string & group)45     bool GetCheckboxGroupIsChange(const std::string& group)
46     {
47         return checkboxChangedMap_[group];
48     };
49 
SetCheckboxGroupIsChange(const std::string & group,bool flag)50     void SetCheckboxGroupIsChange(const std::string& group, bool flag)
51     {
52         checkboxChangedMap_[group] = flag;
53     };
54 
GetLastNavId()55     std::string GetLastNavId()
56     {
57         return lastNavId_.value_or("");
58     }
59 
SetLastNavId(std::optional<std::string> lastNavId)60     void SetLastNavId(std::optional<std::string> lastNavId)
61     {
62         lastNavId_ = lastNavId;
63     }
64 
65     static WeakPtr<GroupManager> GetGroupManager();
66 
67 private:
68     std::unordered_map<std::string, std::list<int32_t>> radioGroupNotify_;
69     std::unordered_map<std::string, std::list<WeakPtr<FrameNode>>> checkBoxListMap_;
70     std::unordered_map<std::string, WeakPtr<FrameNode>> checkBoxGroupMap_;
71     std::optional<std::string> lastNavId_;
72     std::unordered_map<std::string, bool> checkboxChangedMap_;
73 };
74 
75 } // namespace OHOS::Ace::NG
76 
77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_GROUP_MANAGER_H
78