• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_PATTERNS_RATING_RATING_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RATING_RATING_MODEL_H
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 #include "core/common/resource/resource_object.h"
25 #include "base/utils/macros.h"
26 
27 namespace OHOS::Ace {
28 using RatingChangeEvent = std::function<void(const std::string&)>;
29 enum class RatingUriType {
30     BACKGROUND_URI,
31     FOREGROUND_URI,
32     SECONDARY_URI
33 };
34 class ACE_FORCE_EXPORT RatingModel {
35 public:
36     static RatingModel* GetInstance();
37     virtual ~RatingModel() = default;
38 
39     virtual void Create(double rating, bool indicator) = 0;
40     virtual void SetRatingScore(double value) = 0;
41     virtual void SetIndicator(bool value) = 0;
42     virtual void SetStars(int32_t value) = 0;
43     virtual void SetStepSize(double value) = 0;
44     virtual void SetForegroundSrc(const std::string& value, bool flag) = 0;
45     virtual void SetSecondarySrc(const std::string& value, bool flag) = 0;
46     virtual void SetBackgroundSrc(const std::string& value, bool flag) = 0;
47     virtual void SetOnChange(RatingChangeEvent&& onChange) = 0;
48     virtual void SetOnChangeEvent(RatingChangeEvent&& onChangeEvent) = 0;
49     virtual void CreateWithMediaResourceObj(const RefPtr<ResourceObject>& resObj,
50         const RatingUriType ratingUriType) = 0;
51 
52 private:
53     static std::unique_ptr<RatingModel> instance_;
54     static std::mutex mutex_;
55 };
56 } // namespace OHOS::Ace
57 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RATING_RATING_MODEL_H
58