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 DATE_TIME_FORMAT_ADAPTER_IMPL_H 17 #define DATE_TIME_FORMAT_ADAPTER_IMPL_H 18 19 #include <string> 20 #include <vector> 21 #include <map> 22 23 #include "date_time_format_adapter.h" 24 25 #include "common_event_manager.h" 26 #include "common_event_subscriber.h" 27 #include "common_event_support.h" 28 #include "matching_skills.h" 29 #include "want.h" 30 31 namespace OHOS::NWeb { 32 class WebTimezoneInfoImpl final : public WebTimezoneInfo { 33 public: WebTimezoneInfoImpl(std::string tzId,bool isValid)34 WebTimezoneInfoImpl(std::string tzId, bool isValid) 35 : tzId_(tzId), isValid_(isValid) {} 36 37 ~WebTimezoneInfoImpl() override = default; 38 39 std::string GetTzId() override; 40 41 bool GetIsValid(); 42 43 private: 44 std::string tzId_; 45 46 bool isValid_; 47 }; 48 49 class NWebTimeZoneEventSubscriber : public EventFwk::CommonEventSubscriber { 50 public: 51 NWebTimeZoneEventSubscriber(EventFwk::CommonEventSubscribeInfo& in, 52 std::shared_ptr<TimezoneEventCallbackAdapter> cb); 53 54 ~NWebTimeZoneEventSubscriber() override = default; 55 56 void OnReceiveEvent(const EventFwk::CommonEventData& data) override; 57 58 private: 59 std::shared_ptr<TimezoneEventCallbackAdapter> eventCallback_; 60 }; 61 62 class DateTimeFormatAdapterImpl : public DateTimeFormatAdapter { 63 public: 64 DateTimeFormatAdapterImpl() = default; 65 66 ~DateTimeFormatAdapterImpl() override = default; 67 68 void RegTimezoneEvent(const std::shared_ptr<TimezoneEventCallbackAdapter> eventCallback) override; 69 70 bool StartListen() override; 71 72 void StopListen() override; 73 74 std::string GetTimezone() override; 75 76 private: 77 std::shared_ptr<TimezoneEventCallbackAdapter> cb_ = nullptr; 78 std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber_ = nullptr; 79 }; 80 } // namespace OHOS::NWeb 81 82 #endif // DATE_TIME_FORMAT_ADAPTER_IMPL_H 83