• 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 
16 #include "bridge/declarative_frontend/jsview/models/text_clock_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 
20 namespace OHOS::Ace::Framework {
Create()21 RefPtr<TextClockController> TextClockModelImpl::Create()
22 {
23     auto clockComponent = AceType::MakeRefPtr<TextClockComponent>(std::string(""));
24     CHECK_NULL_RETURN(clockComponent, nullptr);
25     clockComponent->SetTextClockController(AceType::MakeRefPtr<TextClockController>());
26     ViewStackProcessor::GetInstance()->Push(clockComponent);
27     return clockComponent->GetTextClockController();
28 }
29 
SetFormat(const std::string & format)30 void TextClockModelImpl::SetFormat(const std::string& format)
31 {
32     auto component = GetComponent();
33     CHECK_NULL_VOID(component);
34     component->SetFormat(format);
35 }
36 
SetHoursWest(const int32_t & hoursWest)37 void TextClockModelImpl::SetHoursWest(const int32_t& hoursWest)
38 {
39     auto component = GetComponent();
40     CHECK_NULL_VOID(component);
41     component->SetHoursWest(hoursWest);
42 }
43 
SetOnDateChange(std::function<void (const std::string)> && onChange)44 void TextClockModelImpl::SetOnDateChange(std::function<void(const std::string)>&& onChange)
45 {
46     auto component = GetComponent();
47     CHECK_NULL_VOID(component);
48     component->SetOnDateChange(std::move(onChange));
49 }
50 
GetComponent()51 RefPtr<TextClockComponent> TextClockModelImpl::GetComponent()
52 {
53     auto* stack = ViewStackProcessor::GetInstance();
54     if (!stack) {
55         return nullptr;
56     }
57     auto component = AceType::DynamicCast<TextClockComponent>(stack->GetMainComponent());
58     return component;
59 }
60 } // namespace OHOS::Ace::Framework