From: Igor Olshevskyi Date: Wed, 21 Jun 2017 11:05:26 +0000 (+0300) Subject: TizenRefApp-8729 [Call UI] Add new Presenter functionality X-Git-Tag: submit/tizen/20170703.150902^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29606e0e3d03a318dbd170fce145c568286568dc;p=profile%2Fwearable%2Fapps%2Fnative%2Fcall-ui.git TizenRefApp-8729 [Call UI] Add new Presenter functionality Change-Id: I048d4f82fdd3baa26ae03ea736bd90dbe254ff8b --- diff --git a/edc/buttons.edc b/edc/buttons.edc index 54b7a18..f20f2d7 100644 --- a/edc/buttons.edc +++ b/edc/buttons.edc @@ -40,11 +40,13 @@ group { "elm/button/base/"_name; \ script { \ public is_pressed; \ public is_expanded; \ + public is_move_blocked; \ public unpress_timer; \ public press(bool:auto_unpress) \ { \ cancel_timer(get_int(unpress_timer)); \ set_int(unpress_timer, 0); \ + set_int(is_move_blocked, 1); \ if (get_int(is_pressed) == 0) { \ set_int(is_pressed, 1); \ run_program(PROGRAM:"pressed"); \ @@ -150,14 +152,14 @@ group { "elm/button/base/"_name; \ } \ programs { \ program { \ - signal: "mouse,down,*"; \ + signal: "mouse,down,1"; \ source: "rect.event"; \ script { \ press(false); \ } \ } \ program { \ - signal: "mouse,up,*"; \ + signal: "mouse,up,1"; \ source: "rect.event"; \ script { \ unpress(); \ @@ -194,12 +196,21 @@ group { "elm/button/base/"_name; \ } \ program { \ name: "pressed"; \ - sequence { \ - action: STATE_SET "pressed_effect"; \ - targets: "image.effect" "image.border"; \ - action: STATE_SET "pressed"; \ - targets: "image.effect" "image.border" "rect.icon_bg"; \ - transition: TRANSITION_GLIDE(CU_BTN_INCOM_CALL_ANIM_TIME); \ + action: STATE_SET "pressed_effect"; \ + targets: "image.effect" "image.border"; \ + after: "on_press"; \ + } \ + program { \ + name: "on_press"; \ + action: STATE_SET "pressed"; \ + targets: "image.effect" "image.border" "rect.icon_bg"; \ + transition: TRANSITION_GLIDE(CU_BTN_INCOM_CALL_ANIM_TIME); \ + after: "reset_move_flag"; \ + } \ + program { \ + name: "reset_move_flag"; \ + script { \ + set_int(is_move_blocked, 0); \ } \ } \ program { \ @@ -235,7 +246,7 @@ group { "elm/button/base/"_name; \ signal: "mouse,move"; \ source: "rect.event"; \ script { \ - if (get_int(is_pressed) == 0 || get_int(is_expanded) == 1) { \ + if (get_int(is_pressed) == 0 || get_int(is_expanded) == 1 || get_int(is_move_blocked) == 1) { \ return; \ } \ new mx, my; \ diff --git a/inc/presenters/AcceptRejectPresenter.h b/inc/presenters/AcceptRejectPresenter.h index 4adf6c6..5268f0d 100644 --- a/inc/presenters/AcceptRejectPresenter.h +++ b/inc/presenters/AcceptRejectPresenter.h @@ -34,11 +34,13 @@ namespace callui { ~Builder(); Builder &setIncomingCall(const IIncomingCallSRef &call); Builder &setAvailableCallsFlag(CallMask calls); - AcceptRejectPresenterSRef build(ucl::ElmWidget &parent) const; + Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); + AcceptRejectPresenterSRef build(Presenter &parent) const; private: IIncomingCallSRef m_call; CallMask m_callMask; + ucl::ElmWidgetSRef m_parentWidget; }; public: @@ -54,7 +56,8 @@ namespace callui { const IIncomingCallSRef &call, CallMask calls); - ucl::Result prepare(ucl::ElmWidget &parent); + ucl::Result prepare(Presenter &parent, + ucl::ElmWidget &parentWidget); ucl::Result createWidget(ucl::ElmWidget &parent); ucl::Result createAcceptBtn(); diff --git a/inc/presenters/AccessoryPresenter.h b/inc/presenters/AccessoryPresenter.h index 4810532..31bc625 100644 --- a/inc/presenters/AccessoryPresenter.h +++ b/inc/presenters/AccessoryPresenter.h @@ -33,11 +33,13 @@ namespace callui { Builder(); Builder &setSoundManager(const ISoundManagerSRef &sm); Builder &setMuteControlDisabled(bool isDisabled); - AccessoryPresenterSRef build(ucl::ElmWidget &parent) const; + Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); + AccessoryPresenterSRef build(Presenter &parent) const; private: ISoundManagerSRef m_sm; bool m_isMuteControlDisabled; + ucl::ElmWidgetSRef m_parentWidget; }; public: @@ -52,7 +54,9 @@ namespace callui { AccessoryPresenter(ucl::IRefCountObj &rc, const ISoundManagerSRef &sm); - ucl::Result prepare(ucl::ElmWidget &parent, bool isMuteControlDisabled = false); + ucl::Result prepare(Presenter &parent, + ucl::ElmWidget &parentWidget, + bool isMuteControlDisabled = false); ucl::Result createWidget(ucl::ElmWidget &parent); ucl::Result createSlider(); diff --git a/inc/presenters/CallInfoPresenter.h b/inc/presenters/CallInfoPresenter.h index 2c203d3..6a836b1 100644 --- a/inc/presenters/CallInfoPresenter.h +++ b/inc/presenters/CallInfoPresenter.h @@ -34,10 +34,12 @@ namespace callui { virtual ~Builder(); Builder &setCallManager(const ICallManagerSRef &cm); Builder &setMode(CallMode mode); - CallInfoPresenterSRef build(ucl::ElmWidget &parent) const; + Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); + CallInfoPresenterSRef build(Presenter &parent) const; private: ICallManagerSRef m_cm; CallMode m_mode; + ucl::ElmWidgetSRef m_parentWidget; }; public: @@ -53,14 +55,15 @@ namespace callui { const ICallManagerSRef &cm, CallMode mode); - ucl::Result prepare(ucl::ElmWidget &parent); + ucl::Result prepare(Presenter &parent, + ucl::ElmWidget &parentWidget); void initCallInfos(const ICallManagerSRef &cm); ucl::Result createWidget(ucl::ElmWidget &parent); ucl::Result createLabel(const std::string &text); ucl::Result createCallerIdImage(const std::string &imagePath); - ucl::Result createCallStatus(); + ucl::Result createCallStatus(Presenter &parent); ucl::Result update(); ucl::Result updateCallerId(); @@ -81,12 +84,13 @@ namespace callui { ucl::LayoutSRef m_widget; ucl::StyledWidgetSRef m_callerId; ucl::StyledWidgetSRef m_label; + PresenterWRef m_parent; CallMode m_mode; ICallInfoSCRef m_incomCallInfo; ICallInfoSCRef m_activeCallInfo; ICallInfoSCRef m_heldCallInfo; ICallInfoSCRef m_endCallInfo; - CallStatusSRef m_callStatus; + CallStatusPresenterSRef m_callStatus; bool m_isSubTxtEnable; bool m_needModifyCallStatus; }; diff --git a/inc/presenters/CallStatus.h b/inc/presenters/CallStatus.h deleted file mode 100644 index b3158a4..0000000 --- a/inc/presenters/CallStatus.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CALLUI_PRESENTERS_CALL_STATUS_H__ -#define __CALLUI_PRESENTERS_CALL_STATUS_H__ - -#include "Presenter.h" - -#include - -#include "ucl/gui/Layout.h" - -#include "types.h" - -namespace callui { - - class CallStatus final : public Presenter { - public: - class Builder { - public: - Builder(); - virtual ~Builder(); - Builder &setMode(CallMode mode); - Builder &setCallInfo(const ICallInfoWCRef &info); - Builder &setCallHoldState(bool isOnHold); - Builder &setLayout(const ucl::LayoutSRef &layout); - CallStatusSRef build() const; - private: - ucl::LayoutSRef m_ly; - CallMode m_mode; - ICallInfoWCRef m_info; - bool m_isOnHold; - }; - public: - virtual ~CallStatus(); - - private: - friend class ucl::ReffedObj; - CallStatus(ucl::IRefCountObj &rc, - const ucl::LayoutSRef &layout, - CallMode mode, - const ICallInfoWCRef &info, - bool isOnHold); - - ucl::Result prepare(); - - ucl::Result processIncomingMode(); - ucl::Result processOutgoingMode(); - ucl::Result processDuringMode(); - ucl::Result processEndMode(); - - Eina_Bool onCallDurationTimerCb(); - Eina_Bool onBlinkingTimerCb(); - - private: - ucl::LayoutSRef m_ly; - CallMode m_mode; - ICallInfoWCRef m_info; - bool m_isOnHold; - Ecore_Timer *m_timer; - struct tm m_duration; - int m_blinkCount; - }; - -} - -#endif // __CALLUI_PRESENTERS_CALL_STATUS_H__ diff --git a/inc/presenters/CallStatusPresenter.h b/inc/presenters/CallStatusPresenter.h new file mode 100644 index 0000000..e4c7b4a --- /dev/null +++ b/inc/presenters/CallStatusPresenter.h @@ -0,0 +1,80 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CALLUI_PRESENTERS_CALL_STATUS_PRESENTER_H__ +#define __CALLUI_PRESENTERS_CALL_STATUS_PRESENTER_H__ + +#include "Presenter.h" + +#include + +#include "ucl/gui/Layout.h" + +#include "types.h" + +namespace callui { + + class CallStatusPresenter final : public Presenter { + public: + class Builder { + public: + Builder(); + virtual ~Builder(); + Builder &setMode(CallMode mode); + Builder &setCallInfo(const ICallInfoWCRef &info); + Builder &setCallHoldState(bool isOnHold); + Builder &setLayout(const ucl::LayoutSRef &layout); + CallStatusPresenterSRef build(Presenter &parent) const; + private: + ucl::LayoutSRef m_ly; + CallMode m_mode; + ICallInfoWCRef m_info; + bool m_isOnHold; + }; + public: + virtual ~CallStatusPresenter(); + + private: + friend class ucl::ReffedObj; + CallStatusPresenter(ucl::IRefCountObj &rc, + const ucl::LayoutSRef &layout, + CallMode mode, + const ICallInfoWCRef &info, + bool isOnHold); + + ucl::Result prepare(Presenter &parent); + + ucl::Result processIncomingMode(); + ucl::Result processOutgoingMode(); + ucl::Result processDuringMode(); + ucl::Result processEndMode(); + + Eina_Bool onCallDurationTimerCb(); + Eina_Bool onBlinkingTimerCb(); + + private: + ucl::LayoutSRef m_ly; + CallMode m_mode; + ICallInfoWCRef m_info; + bool m_isOnHold; + Ecore_Timer *m_timer; + struct tm m_duration; + int m_blinkCount; + }; + +} + +#endif // __CALLUI_PRESENTERS_CALL_STATUS_PRESENTER_H__ diff --git a/inc/presenters/Indicator.h b/inc/presenters/Indicator.h deleted file mode 100644 index 232ed0c..0000000 --- a/inc/presenters/Indicator.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CALLUI_PRESENTERS_INDICATOR_H__ -#define __CALLUI_PRESENTERS_INDICATOR_H__ - -#include "Presenter.h" -#include "model/IIndicatorStateListener.h" - -#include "ucl/gui/Layout.h" -#include "ucl/gui/StyledWidget.h" - -#include "types.h" - -namespace callui { - - class Indicator final : - public IIndicatorStateListener, - public Presenter { - public: - class Builder { - public: - Builder(); - ~Builder(); - Builder &setIndicatorStateProvider(const IIndicatorStateProviderSRef &provider); - IndicatorSRef build(ucl::ElmWidget &parent) const; - private: - IIndicatorStateProviderSRef m_provider; - }; - - public: - virtual ~Indicator(); - - ucl::Widget &getWidget(); - - private: - friend class ucl::ReffedObj; - Indicator(ucl::IRefCountObj &rc, - const IIndicatorStateProviderSRef &provider); - - ucl::Result prepare(ucl::ElmWidget &parent); - - ucl::Result createWidget(ucl::ElmWidget &parent); - ucl::Result createConnectionLayout(); - ucl::Result createRssiLayout(); - ucl::Result createBatteryLayout(); - ucl::Result createSimLayout(); - ucl::Result createHdVoiceLayout(); - - void updateConnectionState(); - void updateRssiState(); - void updateBatteryState(); - void updateSimState(); - void updateHdVoiceState(); - - // IIndicatorStateListener - - virtual void onStateChanged(IndicatorProperty property) override final; - - private: - ucl::LayoutSRef m_widget; - ucl::LayoutSRef m_connLayout; - ucl::LayoutSRef m_rssiLayout; - ucl::LayoutSRef m_batteryLayout; - ucl::LayoutSRef m_simLayout; - ucl::LayoutSRef m_hdCallLayout; - IIndicatorStateProviderSRef m_provider; - }; - - ucl::EdjeSignal getConnectionSignal(ConnectionType type); -} - -#endif // __CALLUI_PRESENTERS_INDICATOR_H__ diff --git a/inc/presenters/IndicatorPresenter.h b/inc/presenters/IndicatorPresenter.h new file mode 100644 index 0000000..6492a11 --- /dev/null +++ b/inc/presenters/IndicatorPresenter.h @@ -0,0 +1,90 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CALLUI_PRESENTERS_INDICATOR_PRESENTER_H__ +#define __CALLUI_PRESENTERS_INDICATOR_PRESENTER_H__ + +#include "Presenter.h" +#include "model/IIndicatorStateListener.h" + +#include "ucl/gui/Layout.h" +#include "ucl/gui/StyledWidget.h" + +#include "types.h" + +namespace callui { + + class IndicatorPresenter final : + public IIndicatorStateListener, + public Presenter { + public: + class Builder { + public: + Builder(); + ~Builder(); + Builder &setIndicatorStateProvider( + const IIndicatorStateProviderSRef &provider); + Builder &setParentWidget(const ucl::ElmWidgetSRef + &parentWidget); + IndicatorPresenterSRef build(Presenter &parent) const; + private: + IIndicatorStateProviderSRef m_provider; + ucl::ElmWidgetSRef m_parentWidget; + }; + + public: + virtual ~IndicatorPresenter(); + + ucl::Widget &getWidget(); + + private: + friend class ucl::ReffedObj; + IndicatorPresenter(ucl::IRefCountObj &rc, + const IIndicatorStateProviderSRef &provider); + + ucl::Result prepare(Presenter &parent, ucl::ElmWidget &parentWidget); + + ucl::Result createWidget(ucl::ElmWidget &parent); + ucl::Result createConnectionLayout(); + ucl::Result createRssiLayout(); + ucl::Result createBatteryLayout(); + ucl::Result createSimLayout(); + ucl::Result createHdVoiceLayout(); + + void updateConnectionState(); + void updateRssiState(); + void updateBatteryState(); + void updateSimState(); + void updateHdVoiceState(); + + // IIndicatorStateListener + + virtual void onStateChanged(IndicatorProperty property) override final; + + private: + ucl::LayoutSRef m_widget; + ucl::LayoutSRef m_connLayout; + ucl::LayoutSRef m_rssiLayout; + ucl::LayoutSRef m_batteryLayout; + ucl::LayoutSRef m_simLayout; + ucl::LayoutSRef m_hdCallLayout; + IIndicatorStateProviderSRef m_provider; + }; + + ucl::EdjeSignal getConnectionSignal(ConnectionType type); +} + +#endif // __CALLUI_PRESENTERS_INDICATOR_PRESENTER_H__ diff --git a/inc/presenters/KeypadPage.h b/inc/presenters/KeypadPage.h index 187fa8e..c00eb23 100644 --- a/inc/presenters/KeypadPage.h +++ b/inc/presenters/KeypadPage.h @@ -20,6 +20,7 @@ #include "Page.h" #include "ucl/gui/Layout.h" +#include "ucl/gui/NaviItem.h" #include "types.h" @@ -44,7 +45,7 @@ namespace callui { const ExitRequestHandler onExitRequest); virtual ~KeypadPage(); - ucl::Result prepare(); + ucl::Result doPrepare(ucl::NaviItem &item); private: ucl::LayoutSRef m_widget; diff --git a/inc/presenters/MainPage.h b/inc/presenters/MainPage.h index 0ac969e..610b789 100644 --- a/inc/presenters/MainPage.h +++ b/inc/presenters/MainPage.h @@ -22,6 +22,8 @@ #include "ucl/gui/Layout.h" #include "ucl/gui/StyledWidget.h" +#include "ucl/gui/NaviItem.h" + #include "types.h" namespace callui { @@ -50,7 +52,7 @@ namespace callui { const ICallSRef &call); virtual ~MainPage(); - ucl::Result prepare(); + ucl::Result doPrepare(ucl::NaviItem &item); ucl::Result showWindow(); void updateCallMode(); @@ -83,11 +85,6 @@ namespace callui { ucl::Result createIndicatorPresenter(); ucl::Result createDisplayPresenter(); - // Presenter - - virtual void onActivateBy(const DeactivatorInfo &info) final override; - virtual void onDeactivateBy(const DeactivatorInfo &info) final override; - // Page virtual void onBackKey() final override; @@ -104,7 +101,7 @@ namespace callui { ICallSRef m_call; ICallManagerSRef m_cm; - IndicatorSRef m_indicator; + IndicatorPresenterSRef m_indicator; CallInfoPresenterSRef m_callInfoPrs; AcceptRejectPresenterSRef m_acceptRejectPrs; RejectMsgPresenterSRef m_rmPrs; diff --git a/inc/presenters/MoreOptionsPresenter.h b/inc/presenters/MoreOptionsPresenter.h index 62d3bd2..f6ab91a 100644 --- a/inc/presenters/MoreOptionsPresenter.h +++ b/inc/presenters/MoreOptionsPresenter.h @@ -37,11 +37,13 @@ namespace callui { Builder &setCallManager(const ICallManagerSRef &cm); Builder &setSoundManager(const ISoundManagerSRef &sm); Builder &setNaviframe(const ucl::NaviframeSRef &navi); - MoreOptionsPresenterSRef build(ucl::ElmWidget &parent) const; + Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); + MoreOptionsPresenterSRef build(Presenter &parent) const; private: ICallManagerSRef m_cm; ISoundManagerSRef m_sm; ucl::NaviframeSRef m_navi; + ucl::ElmWidgetSRef m_parentWidget; }; public: @@ -56,7 +58,8 @@ namespace callui { const ucl::NaviframeSRef &navi); virtual ~MoreOptionsPresenter(); - ucl::Result prepare(ucl::ElmWidget &parent); + ucl::Result prepare(Presenter &parent, + ucl::ElmWidget &parentWidget); ucl::Result createWidget(ucl::ElmWidget &parent); ucl::Result createPanel(); diff --git a/inc/presenters/Page.h b/inc/presenters/Page.h index 8dfdc77..8c63c6e 100644 --- a/inc/presenters/Page.h +++ b/inc/presenters/Page.h @@ -21,11 +21,13 @@ #include "Presenter.h" +#include "types.h" + namespace callui { class Page : public Presenter { public: - using ExitRequestHandler = ucl::Delegate; + using ExitRequestHandler = ucl::WeakDelegate; public: ucl::Naviframe &getNaviframe(); @@ -48,11 +50,11 @@ namespace callui { protected: Page(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi, - ExitRequestHandler onExitRequest); + const ExitRequestHandler &onExitRequest); virtual ~Page(); - template - ucl::Result prepare(ITEM_FACTORY &&makeItem); + template + ucl::Result prepare(ON_PREPARE &&onPrepare); ucl::NaviItem getItem(); diff --git a/inc/presenters/Page.hpp b/inc/presenters/Page.hpp index 7ee2a56..886f114 100644 --- a/inc/presenters/Page.hpp +++ b/inc/presenters/Page.hpp @@ -18,13 +18,14 @@ namespace callui { - template - inline ucl::Result Page::prepare(ITEM_FACTORY &&makeItem) + template + inline ucl::Result Page::prepare(ON_PREPARE &&onPrepare) { - m_item = makeItem(); - if (!m_item) { - UCL_LOG_RETURN(ucl::RES_FAIL, "m_item is NULL"); - } + UCL_FAIL_RETURN(Presenter::prepare(*m_navi), + "Presenter::prepare() failed!"); + + UCL_FAIL_RETURN(onPrepare(m_item), "onPrepare() failed!"); + return preparePart2(); } @@ -56,7 +57,7 @@ namespace callui { return (m_navi->getBottomItem() == m_item); } - // Non-member functions + // Non-member functions // inline bool isLast(const Page &page) { diff --git a/inc/presenters/Presenter.h b/inc/presenters/Presenter.h index c3db2f4..5bf2b3b 100644 --- a/inc/presenters/Presenter.h +++ b/inc/presenters/Presenter.h @@ -25,36 +25,53 @@ namespace callui { + UCL_DECLARE_REF_ALIASES(Presenter); + class Presenter : public ucl::RefCountAware { public: struct DeactivatorInfo { - void *deactivator; + const void *deactivator; bool isBroadcast; }; public: bool isActive() const; - bool isDeactivatedBy(void *deactivator) const; + bool isDeactivatedBy(const void *deactivator) const; + + void activateBy(const void *deactivator); + void deactivateBy(const void *deactivator); + + void addDeactivatorSource(ucl::Widget &source); + void delDeactivatorSource(ucl::Widget &source); - void activateBy(void *deactivator); - void deactivateBy(void *deactivator); + protected: + enum { + PF_ADD_DEACTIVATOR_SOURCES = 1, + PF_ADD_SELF_EXCEPT = 2, + + PF_PASSIVE = 0, + PF_DEACTIVATOR = (PF_ADD_DEACTIVATOR_SOURCES | PF_ADD_SELF_EXCEPT), + PF_DEFAULT = PF_ADD_DEACTIVATOR_SOURCES + }; protected: Presenter(ucl::IRefCountObj &rc); virtual ~Presenter(); - ucl::Result prepare(ucl::ElmWidget &widget); + ucl::Result prepare(ucl::ElmWidget &widget, int flags = PF_DEFAULT); + ucl::Result prepare(Presenter &parent, int flags = PF_DEFAULT); ucl::Window &getWindow(); + bool isWindowReady() const; - void addDeactivatorSource(ucl::Widget &source); - void addDeactivatorException(void *deactivator); + void addDeactivatorException(const void *deactivator); + void setDeactivatorSink(const ucl::WidgetSRef &sink); - void sendActivateBy(ucl::Widget &sender, void *deactivator); - void sendDeactivateBy(ucl::Widget &sender, void *deactivator); + void sendActivate(ucl::Widget &sender); + void sendDeactivate(ucl::Widget &sender); - void broadcastActivateBy(void *deactivator); - void broadcastDeactivateBy(void *deactivator); + void broadcastActivate(); + void broadcastDeactivate(); virtual void onActivate(); virtual void onDeactivate(); @@ -63,8 +80,9 @@ namespace callui { private: void sendDeactivator(ucl::Widget &sender, - ucl::SmartEvent event, void *deactivator); - void broadcastDeactivator(ucl::SmartEvent event, void *deactivator); + ucl::SmartEvent event, const void *deactivator); + void broadcastDeactivator(ucl::SmartEvent event, + const void *deactivator); void sendDeactivatorInfo(ucl::Widget &sender, ucl::SmartEvent event, const DeactivatorInfo &info); @@ -76,9 +94,13 @@ namespace callui { void onDeactivateBySmart(ucl::Widget &widget, void *eventInfo); private: - std::unordered_set m_deactivatorExceptions; - std::unordered_set m_deactivators; + std::unordered_set m_deactivatorExceptions; + std::unordered_set m_deactivators; ucl::WindowSRef m_window; + ucl::WidgetSRef m_sink; + ucl::WidgetWRef m_parentSink; + bool m_hasBuildInSources; + bool m_isChild; bool m_isPrepared; }; } diff --git a/inc/presenters/RejectMsgPresenter.h b/inc/presenters/RejectMsgPresenter.h index 03eacbd..40cb2ae 100644 --- a/inc/presenters/RejectMsgPresenter.h +++ b/inc/presenters/RejectMsgPresenter.h @@ -35,12 +35,14 @@ namespace callui { Builder &setProvider(const IRejectMsgProviderSRef &provider); Builder &setStateHandler(const RejectMsgStateHandler &handler); Builder &setSelectHandler(const RejectMsgSelectHandler &handler); - RejectMsgPresenterSRef build(ucl::ElmWidget &parent) const; + Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); + RejectMsgPresenterSRef build(Presenter &parent) const; private: IRejectMsgProviderSRef m_provider; RejectMsgStateHandler m_stateHandler; RejectMsgSelectHandler m_selectHandler; + ucl::ElmWidgetSRef m_parentWidget; }; public: @@ -65,7 +67,8 @@ namespace callui { const RejectMsgStateHandler &stateHandler, const RejectMsgSelectHandler &selectHandler); - ucl::Result prepare(ucl::ElmWidget &parent); + ucl::Result prepare(Presenter &parent, + ucl::ElmWidget &parentWidget); ucl::Result createWidget(ucl::ElmWidget &parent); ucl::Result createPanel(); diff --git a/inc/presenters/types.h b/inc/presenters/types.h index 297b4e0..4978b78 100644 --- a/inc/presenters/types.h +++ b/inc/presenters/types.h @@ -58,15 +58,16 @@ namespace callui { }; UCL_DECLARE_REF_ALIASES(Page); + UCL_DECLARE_REF_ALIASES(MainPage); UCL_DECLARE_REF_ALIASES(KeypadPage); UCL_DECLARE_REF_ALIASES(AcceptRejectPresenter); UCL_DECLARE_REF_ALIASES(AcceptDialog); - UCL_DECLARE_REF_ALIASES(Indicator); + UCL_DECLARE_REF_ALIASES(IndicatorPresenter); UCL_DECLARE_REF_ALIASES(CallInfoPresenter); - UCL_DECLARE_REF_ALIASES(CallStatus); + UCL_DECLARE_REF_ALIASES(CallStatusPresenter); UCL_DECLARE_REF_ALIASES(RejectMsgPresenter); diff --git a/src/model/CallManager.cpp b/src/model/CallManager.cpp index 069162a..8c9c7bd 100644 --- a/src/model/CallManager.cpp +++ b/src/model/CallManager.cpp @@ -422,7 +422,8 @@ namespace callui { { if (m_incomingCall) { if (m_slot == SimSlot::UNDEFINED) { - m_slot = slot; + // TODO: need to modify when companion mode will be added + m_slot = SimSlot::GEAR; } if (const auto listener = m_listener.lock()) { listener->onCallEvent(CallEventType::INCOMING); diff --git a/src/model/RejectMsg.cpp b/src/model/RejectMsg.cpp index 6c3165b..c1f6d52 100644 --- a/src/model/RejectMsg.cpp +++ b/src/model/RejectMsg.cpp @@ -68,12 +68,6 @@ namespace callui { // Set message type to SMS reject msg_set_int_value(msgInfo, MSG_MESSAGE_TYPE_INT, MSG_TYPE_SMS_REJECT); - int slotId = convertEnumValueToInt(slot); - DLOG("msg_sms_send_message() Sim slot [%d]", slotId); - // TODO: need to investigate whether this is needed - slotId++; - msg_set_int_value(msgInfo, MSG_MESSAGE_SIM_INDEX_INT, slotId); - // No setting send option msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false); diff --git a/src/model/SoundManager.cpp b/src/model/SoundManager.cpp index 0c45120..85b4c6e 100644 --- a/src/model/SoundManager.cpp +++ b/src/model/SoundManager.cpp @@ -54,11 +54,25 @@ namespace callui { namespace { namespace impl { if (!device) { UCL_FAIL_BREAK(res, "device is NULL"); } + sound_manager_get_device_type(device, &type); if (searchType == type) { DLOG("Bluetooth voice device found"); count++; } + + // For debug only + int id; + char *name; + sound_device_io_direction_e direction; + sound_manager_get_device_id(device, &id); + sound_manager_get_device_name(device, &name); + sound_manager_get_device_io_direction(device, &direction); + DLOG("===================="); + DLOG("Device ID [%d]", id); + DLOG("Device name [%s]", name); + DLOG("Device IO direction [%d]", direction); + DLOG("Device type [%d]", type); } sound_manager_free_device_list(deviceList); deviceCount = count; @@ -96,6 +110,8 @@ namespace callui { void SoundManager::audioStateChangedCb(cm_audio_state_type_e state) { + DLOG(); + if (state == CM_AUDIO_STATE_NONE_E) { ILOG("Ignore. Unhandled state [%d]", state); return; @@ -105,6 +121,8 @@ namespace callui { void SoundManager::muteStateChangedCb(cm_mute_status_e status) { + DLOG(); + m_muteStateEvent.dispatch(status == CM_MUTE_STATUS_ON); } diff --git a/src/presenters/AcceptDialog.cpp b/src/presenters/AcceptDialog.cpp index 668b5c0..79df682 100644 --- a/src/presenters/AcceptDialog.cpp +++ b/src/presenters/AcceptDialog.cpp @@ -87,7 +87,7 @@ namespace callui { Result AcceptDialog::prepare(ElmWidget &parent) { - FAIL_RETURN(Presenter::prepare(parent), + FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), "Presenter::prepare() failed!"); FAIL_RETURN(createPopup(parent, impl::POPUP_STYLE), @@ -99,7 +99,7 @@ namespace callui { m_rc->ref(); addDeactivatorException(this); - broadcastDeactivateBy(this); + broadcastDeactivate(); return RES_OK; } @@ -282,7 +282,7 @@ namespace callui { CALLBACK_A(AcceptDialog::onPopupHWBackKey)); deactivateBy(m_popup.get()); - broadcastActivateBy(this); + broadcastActivate(); m_popup.reset(); diff --git a/src/presenters/AcceptRejectPresenter.cpp b/src/presenters/AcceptRejectPresenter.cpp index 5a23249..97d00ac 100644 --- a/src/presenters/AcceptRejectPresenter.cpp +++ b/src/presenters/AcceptRejectPresenter.cpp @@ -65,22 +65,38 @@ namespace callui { { } - AcceptRejectPresenter::Builder &AcceptRejectPresenter::Builder::setIncomingCall(const IIncomingCallSRef &call) + AcceptRejectPresenter::Builder & + AcceptRejectPresenter::Builder::setIncomingCall(const IIncomingCallSRef &call) { m_call = call; return *this; } - AcceptRejectPresenter::Builder &AcceptRejectPresenter::Builder::setAvailableCallsFlag(CallMask mask) + AcceptRejectPresenter::Builder & + AcceptRejectPresenter::Builder::setAvailableCallsFlag(CallMask mask) { m_callMask = mask; return *this; } - AcceptRejectPresenterSRef AcceptRejectPresenter::Builder::build(ElmWidget &parent) const + AcceptRejectPresenter::Builder & + AcceptRejectPresenter::Builder::setParentWidget( + const ElmWidgetSRef &parentWidget) { + m_parentWidget = parentWidget; + return *this; + } + + AcceptRejectPresenterSRef + AcceptRejectPresenter::Builder::build(Presenter &parent) const + { + if (!m_parentWidget) { + LOG_RETURN_VALUE(RES_FAIL, {}, "m_parentWidget is NULL"); + } + auto result = makeShared(m_call, m_callMask); - FAIL_RETURN_VALUE(result->prepare(parent), {}, "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), + {}, "result->prepare() failed!"); return result; } @@ -105,12 +121,13 @@ namespace callui { CALLBACK_A(AcceptRejectPresenter::onRotaryEvent), this); } - Result AcceptRejectPresenter::prepare(ElmWidget &parent) + Result AcceptRejectPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget) { FAIL_RETURN(Presenter::prepare(parent), "Presenter::prepare() failed!"); - FAIL_RETURN(createWidget(parent), + FAIL_RETURN(createWidget(parentWidget), "createWidget() failed!"); FAIL_RETURN(createAcceptBtn(), @@ -238,8 +255,8 @@ namespace callui { return EINA_TRUE; } - StyledWidgetSRef AcceptRejectPresenter::createBtn(const ucl::ElmStyle &style, - const ucl::EdjePart &part) + StyledWidgetSRef AcceptRejectPresenter::createBtn(const ElmStyle &style, + const EdjePart &part) { Evas_Object *const btnEo = elm_button_add(*m_widget); if (!btnEo) { diff --git a/src/presenters/AccessoryPresenter.cpp b/src/presenters/AccessoryPresenter.cpp index 0e33872..d4c667d 100644 --- a/src/presenters/AccessoryPresenter.cpp +++ b/src/presenters/AccessoryPresenter.cpp @@ -52,26 +52,37 @@ namespace callui { { } - AccessoryPresenter::Builder &AccessoryPresenter::Builder::setSoundManager(const ISoundManagerSRef &sm) + AccessoryPresenter::Builder & + AccessoryPresenter::Builder::setSoundManager(const ISoundManagerSRef &sm) { m_sm = sm; return *this; } - AccessoryPresenter::Builder &AccessoryPresenter::Builder::setMuteControlDisabled(bool isDisabled) + AccessoryPresenter::Builder & + AccessoryPresenter::Builder::setMuteControlDisabled(bool isDisabled) { m_isMuteControlDisabled = isDisabled; return *this; } - AccessoryPresenterSRef AccessoryPresenter::Builder::build(ElmWidget &parent) const + AccessoryPresenter::Builder & + AccessoryPresenter::Builder::setParentWidget( + const ElmWidgetSRef &parentWidget) { - if (!m_sm) { - LOG_RETURN_VALUE(RES_FAIL, {}, "Sound manager is NULL"); + m_parentWidget = parentWidget; + return *this; + } + + AccessoryPresenterSRef + AccessoryPresenter::Builder::build(Presenter &parent) const + { + if (!m_sm || !m_parentWidget) { + LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are not set"); } auto result = makeShared(m_sm); - FAIL_RETURN_VALUE(result->prepare(parent, m_isMuteControlDisabled), + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget, m_isMuteControlDisabled), {}, "result->prepare() failed!"); return result; } @@ -91,11 +102,13 @@ namespace callui { unregisterCallbacks(); } - Result AccessoryPresenter::prepare(ElmWidget &parent, bool isMuteControlDisabled) + Result AccessoryPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget, + bool isMuteControlDisabled) { FAIL_RETURN(Presenter::prepare(parent), "Presenter::prepare() failed"); - FAIL_RETURN(createWidget(parent), "createWidget() failed"); + FAIL_RETURN(createWidget(parentWidget), "createWidget() failed"); FAIL_RETURN(createSlider(), "createSlider() failed"); @@ -227,12 +240,22 @@ namespace callui { void AccessoryPresenter::onVolumeBtnClicked(Widget &widget, void *eventInfo) { + if (!isActive()) { + ILOG("Presenter is not active. Ignore"); + return; + } + show(*m_vc); startVCTimer(); } void AccessoryPresenter::onMuteBtnClicked(Widget &widget, void *eventInfo) { + if (!isActive()) { + ILOG("Presenter is not active. Ignore"); + return; + } + m_sm->setMuteState(!m_sm->getMuteState()); } @@ -322,6 +345,10 @@ namespace callui { void AccessoryPresenter::onVolumeControlEventCb(VolumeControlEvent event) { + if (!isActive()) { + LOG_RETURN_VOID(RES_OK, "Presenter is not active. Ignore"); + } + if (!m_vcTimer) { DLOG("Ignore as control is hidden"); return; diff --git a/src/presenters/CallInfoPresenter.cpp b/src/presenters/CallInfoPresenter.cpp index a4bbe98..cfccf52 100644 --- a/src/presenters/CallInfoPresenter.cpp +++ b/src/presenters/CallInfoPresenter.cpp @@ -14,12 +14,11 @@ * limitations under the License. */ +#include "presenters/CallStatusPresenter.h" #include "presenters/CallInfoPresenter.h" #include "ucl/gui/Window.h" -#include "presenters/CallStatus.h" - #include "model/ICallManager.h" #include "model/IIncomingCall.h" #include "model/IActiveCall.h" @@ -100,27 +99,39 @@ namespace callui { { } - CallInfoPresenter::Builder &CallInfoPresenter::Builder::setCallManager(const ICallManagerSRef &cm) + CallInfoPresenter::Builder & + CallInfoPresenter::Builder::setCallManager(const ICallManagerSRef &cm) { m_cm = cm; return *this; } - CallInfoPresenter::Builder &CallInfoPresenter::Builder::setMode(CallMode mode) + CallInfoPresenter::Builder & + CallInfoPresenter::Builder::setMode(CallMode mode) { m_mode = mode; return *this; } - CallInfoPresenterSRef CallInfoPresenter::Builder::build(ElmWidget &parent) const + CallInfoPresenter::Builder & + CallInfoPresenter::Builder::setParentWidget( + const ucl::ElmWidgetSRef &parentWidget) + { + m_parentWidget = parentWidget; + return *this; + } + + CallInfoPresenterSRef + CallInfoPresenter::Builder::build(Presenter &parent) const { - if (m_mode == CallMode::UNDEFINED || !m_cm) { - LOG_RETURN_VALUE(RES_FAIL, {}, "Not all params are set"); + if (m_mode == CallMode::UNDEFINED || !m_cm || !m_parentWidget) { + LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are are set"); } auto result = makeShared(m_cm, m_mode); - FAIL_RETURN_VALUE(result->prepare(parent), {}, + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), {}, "result->prepare() failed!"); + return result; } @@ -139,15 +150,18 @@ namespace callui { { } - Result CallInfoPresenter::prepare(ElmWidget &parent) + Result CallInfoPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget) { - FAIL_RETURN(Presenter::prepare(parent), + FAIL_RETURN(Presenter::prepare(parent, PF_PASSIVE), "Presenter::prepare() failed!"); - FAIL_RETURN(createWidget(parent), + m_parent = asWeak(parent); + + FAIL_RETURN(createWidget(parentWidget), "createWidget() failed!"); - FAIL_RETURN(createCallStatus(), + FAIL_RETURN(createCallStatus(parent), "createCallStatus() failed!"); FAIL_RETURN(update(), "update() failed!"); @@ -562,7 +576,7 @@ namespace callui { return RES_OK; } - Result CallInfoPresenter::createCallStatus() + Result CallInfoPresenter::createCallStatus(Presenter &parent) { ICallInfoWCRef callInfo; bool isOnHold = false; @@ -592,11 +606,12 @@ namespace callui { break; } - m_callStatus = CallStatus::Builder().setLayout(m_widget). + m_callStatus = CallStatusPresenter::Builder(). + setLayout(m_widget). setMode(m_mode). setCallInfo(callInfo). setCallHoldState(isOnHold). - build(); + build(parent); if (!m_callStatus) { LOG_RETURN(RES_FAIL, "CallStatus::build() failed!"); @@ -614,7 +629,8 @@ namespace callui { FAIL_RETURN(updateMainTxt(), "diplayMainTxt() failed!"); if (m_needModifyCallStatus) { - return createCallStatus(); + if (const auto parent = m_parent.lock()) + return createCallStatus(*parent); } return RES_OK; diff --git a/src/presenters/CallStatus.cpp b/src/presenters/CallStatus.cpp deleted file mode 100644 index 73d807b..0000000 --- a/src/presenters/CallStatus.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "presenters/CallStatus.h" - -#include "model/ICallInfo.h" - -#include "common.h" -#include "resources.h" - -namespace callui { namespace { namespace impl { - - using namespace ucl; - - constexpr double CALL_DURATION_TIMER_INTERVAL = 0.1; - constexpr double END_CALL_BLINKING_TIMER_INTERVAL = 0.5; - constexpr int END_CALL_BLINKING_MAX_COUNT = 5; - - constexpr EdjePart PART_TXT_TEXT_INFO {"text_info"}; - - constexpr EdjeSignal SIGN_DOT_RTL {"default:RTL"}; - constexpr EdjeSignal SIGN_DOT_LTR {"default:LTR"}; - constexpr EdjeSignal SIGN_RESET {"reset"}; - - constexpr EdjeSignalSrc SIGN_SRC_DOT {"dot"}; - -}}} - -namespace callui { - - using namespace ucl; - - CallStatus::Builder::Builder(): - m_mode(CallMode::UNDEFINED), - m_isOnHold(false) - { - } - - CallStatus::Builder::~Builder() - { - } - - CallStatus::Builder &CallStatus::Builder::setMode(CallMode mode) - { - m_mode = mode; - return *this; - } - - CallStatus::Builder &CallStatus::Builder::setCallInfo(const ICallInfoWCRef &info) - { - m_info = info; - return *this; - } - - CallStatus::Builder &CallStatus::Builder::setCallHoldState(bool isOnHold) - { - m_isOnHold = isOnHold; - return *this; - } - - CallStatus::Builder &CallStatus::Builder::setLayout(const LayoutSRef &layout) - { - m_ly = layout; - return *this; - } - - CallStatusSRef CallStatus::Builder::build() const - { - if (m_mode == CallMode::UNDEFINED || !m_ly) { - LOG_RETURN_VALUE(RES_FAIL, {}, "Not all params are set"); - } - - auto result = makeShared(m_ly, m_mode, - m_info, m_isOnHold); - - FAIL_RETURN_VALUE(result->prepare(), {}, - "result->prepare() failed!"); - return result; - } - - - CallStatus::CallStatus(IRefCountObj &rc, - const LayoutSRef &layout, - CallMode mode, - const ICallInfoWCRef &info, - bool isHeld): - Presenter(rc), - m_ly(layout), - m_mode(mode), - m_info(info), - m_isOnHold(isHeld), - m_timer(nullptr), - m_duration{0}, - m_blinkCount(0) - { - } - - CallStatus::~CallStatus() - { - m_ly.reset(); - if (m_timer) { - ecore_timer_del(m_timer); - m_timer = nullptr; - } - } - - Result CallStatus::prepare() - { - m_ly->emit(impl::SIGN_RESET, impl::SIGN_SRC_DOT); - m_ly->setText("", impl::PART_TXT_TEXT_INFO); - - switch (m_mode) { - case CallMode::INCOMING: return processIncomingMode(); - case CallMode::OUTGOING: return processOutgoingMode(); - case CallMode::DURING: return processDuringMode(); - case CallMode::END: return processEndMode(); - default: - LOG_RETURN(RES_FAIL, "Unknown mode"); - break; - } - - return RES_OK; - } - - Result CallStatus::processIncomingMode() - { - m_ly->setText(STR_INCOMING_CALL, impl::PART_TXT_TEXT_INFO); - - // TODO: need add logic for RTL mode in the future - m_ly->emit(impl::SIGN_DOT_LTR, impl::SIGN_SRC_DOT); - - return RES_OK; - } - - Result CallStatus::processOutgoingMode() - { - m_ly->setText(STR_DIALING_CALL, impl::PART_TXT_TEXT_INFO); - - // TODO: need add logic for RTL mode in the future - m_ly->emit(impl::SIGN_DOT_LTR, impl::SIGN_SRC_DOT); - - return RES_OK; - } - - Eina_Bool CallStatus::onCallDurationTimerCb() - { - const auto info = m_info.lock(); - if (!info) { - m_timer = nullptr; - LOG_RETURN_VALUE(RES_FAIL, ECORE_CALLBACK_CANCEL, "m_info is NULL"); - } - - struct tm tmp = info->getDuration(); - tryUpdateCallDurationTime( - m_duration, - tmp, - *m_ly, - impl::PART_TXT_TEXT_INFO); - - return ECORE_CALLBACK_RENEW; - } - - Result CallStatus::processDuringMode() - { - - if (m_isOnHold) { - m_ly->setText(STR_ON_HOLD, impl::PART_TXT_TEXT_INFO); - } else { - if (const auto info = m_info.lock()) { - m_duration = info->getDuration(); - } - setCallDuration(m_duration, *m_ly, impl::PART_TXT_TEXT_INFO); - - if (m_timer) { - ecore_timer_del(m_timer); - m_timer = nullptr; - } - - m_timer = ecore_timer_add(impl::CALL_DURATION_TIMER_INTERVAL, - CALLBACK_B(CallStatus::onCallDurationTimerCb), - this); - - if (!m_timer) { - LOG_RETURN(RES_FAIL, "m_timer is NULL"); - } - } - return RES_OK; - } - - Eina_Bool CallStatus::onBlinkingTimerCb() - { - if ((m_blinkCount % 2) == 0) { - setCallDuration(m_duration, *m_ly, impl::PART_TXT_TEXT_INFO); - } else if ((m_blinkCount % 2) == 1) { - m_ly->setText("", impl::PART_TXT_TEXT_INFO); - } - - m_blinkCount++; - - if (m_blinkCount == impl::END_CALL_BLINKING_MAX_COUNT) { - m_ly->setText(STR_CALL_ENDED, impl::PART_TXT_TEXT_INFO); - m_timer = nullptr; - return ECORE_CALLBACK_CANCEL; - } - return ECORE_CALLBACK_RENEW; - } - - Result CallStatus::processEndMode() - { - if (m_timer) { - ecore_timer_del(m_timer); - m_timer = nullptr; - } - - if (const auto info = m_info.lock()) { - m_duration = info->getDuration(); - } - - m_timer = ecore_timer_add(impl::END_CALL_BLINKING_TIMER_INTERVAL, - CALLBACK_B(CallStatus::onBlinkingTimerCb), this); - if (!m_timer) { - LOG_RETURN(RES_FAIL, "m_timer is NULL"); - } - - return RES_OK; - } - -} diff --git a/src/presenters/CallStatusPresenter.cpp b/src/presenters/CallStatusPresenter.cpp new file mode 100644 index 0000000..6274d89 --- /dev/null +++ b/src/presenters/CallStatusPresenter.cpp @@ -0,0 +1,249 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "presenters/CallStatusPresenter.h" + +#include "model/ICallInfo.h" + +#include "common.h" +#include "resources.h" + +namespace callui { namespace { namespace impl { + + using namespace ucl; + + constexpr double CALL_DURATION_TIMER_INTERVAL = 0.1; + constexpr double END_CALL_BLINKING_TIMER_INTERVAL = 0.5; + constexpr int END_CALL_BLINKING_MAX_COUNT = 5; + + constexpr EdjePart PART_TXT_TEXT_INFO {"text_info"}; + + constexpr EdjeSignal SIGN_DOT_RTL {"default:RTL"}; + constexpr EdjeSignal SIGN_DOT_LTR {"default:LTR"}; + constexpr EdjeSignal SIGN_RESET {"reset"}; + + constexpr EdjeSignalSrc SIGN_SRC_DOT {"dot"}; + +}}} + +namespace callui { + + using namespace ucl; + + CallStatusPresenter::Builder::Builder(): + m_mode(CallMode::UNDEFINED), + m_isOnHold(false) + { + } + + CallStatusPresenter::Builder::~Builder() + { + } + + CallStatusPresenter::Builder & + CallStatusPresenter::Builder::setMode(CallMode mode) + { + m_mode = mode; + return *this; + } + + CallStatusPresenter::Builder & + CallStatusPresenter::Builder::setCallInfo(const ICallInfoWCRef &info) + { + m_info = info; + return *this; + } + + CallStatusPresenter::Builder & + CallStatusPresenter::Builder::setCallHoldState(bool isOnHold) + { + m_isOnHold = isOnHold; + return *this; + } + + CallStatusPresenter::Builder & + CallStatusPresenter::Builder::setLayout(const LayoutSRef &layout) + { + m_ly = layout; + return *this; + } + + CallStatusPresenterSRef + CallStatusPresenter::Builder::build(Presenter &parent) const + { + if (m_mode == CallMode::UNDEFINED || !m_ly) { + LOG_RETURN_VALUE(RES_FAIL, {}, "Not all params are set"); + } + + auto result = makeShared(m_ly, m_mode, + m_info, m_isOnHold); + + FAIL_RETURN_VALUE(result->prepare(parent), {}, + "result->prepare() failed!"); + return result; + } + + + CallStatusPresenter::CallStatusPresenter(IRefCountObj &rc, + const LayoutSRef &layout, + CallMode mode, + const ICallInfoWCRef &info, + bool isHeld): + Presenter(rc), + m_ly(layout), + m_mode(mode), + m_info(info), + m_isOnHold(isHeld), + m_timer(nullptr), + m_duration{0}, + m_blinkCount(0) + { + } + + CallStatusPresenter::~CallStatusPresenter() + { + m_ly.reset(); + if (m_timer) { + ecore_timer_del(m_timer); + m_timer = nullptr; + } + } + + Result CallStatusPresenter::prepare(Presenter &parent) + { + FAIL_RETURN(Presenter::prepare(parent, PF_PASSIVE), + "Presenter::prepare() failed!"); + + m_ly->emit(impl::SIGN_RESET, impl::SIGN_SRC_DOT); + m_ly->setText("", impl::PART_TXT_TEXT_INFO); + + switch (m_mode) { + case CallMode::INCOMING: return processIncomingMode(); + case CallMode::OUTGOING: return processOutgoingMode(); + case CallMode::DURING: return processDuringMode(); + case CallMode::END: return processEndMode(); + default: + LOG_RETURN(RES_FAIL, "Unknown mode"); + break; + } + + return RES_OK; + } + + Result CallStatusPresenter::processIncomingMode() + { + m_ly->setText(STR_INCOMING_CALL, impl::PART_TXT_TEXT_INFO); + + // TODO: need add logic for RTL mode in the future + m_ly->emit(impl::SIGN_DOT_LTR, impl::SIGN_SRC_DOT); + + return RES_OK; + } + + Result CallStatusPresenter::processOutgoingMode() + { + m_ly->setText(STR_DIALING_CALL, impl::PART_TXT_TEXT_INFO); + + // TODO: need add logic for RTL mode in the future + m_ly->emit(impl::SIGN_DOT_LTR, impl::SIGN_SRC_DOT); + + return RES_OK; + } + + Eina_Bool CallStatusPresenter::onCallDurationTimerCb() + { + const auto info = m_info.lock(); + if (!info) { + m_timer = nullptr; + LOG_RETURN_VALUE(RES_FAIL, ECORE_CALLBACK_CANCEL, "m_info is NULL"); + } + + struct tm tmp = info->getDuration(); + tryUpdateCallDurationTime( + m_duration, + tmp, + *m_ly, + impl::PART_TXT_TEXT_INFO); + + return ECORE_CALLBACK_RENEW; + } + + Result CallStatusPresenter::processDuringMode() + { + + if (m_isOnHold) { + m_ly->setText(STR_ON_HOLD, impl::PART_TXT_TEXT_INFO); + } else { + if (const auto info = m_info.lock()) { + m_duration = info->getDuration(); + } + setCallDuration(m_duration, *m_ly, impl::PART_TXT_TEXT_INFO); + + if (m_timer) { + ecore_timer_del(m_timer); + m_timer = nullptr; + } + + m_timer = ecore_timer_add(impl::CALL_DURATION_TIMER_INTERVAL, + CALLBACK_B(CallStatusPresenter::onCallDurationTimerCb), + this); + + if (!m_timer) { + LOG_RETURN(RES_FAIL, "m_timer is NULL"); + } + } + return RES_OK; + } + + Eina_Bool CallStatusPresenter::onBlinkingTimerCb() + { + if ((m_blinkCount % 2) == 0) { + setCallDuration(m_duration, *m_ly, impl::PART_TXT_TEXT_INFO); + } else if ((m_blinkCount % 2) == 1) { + m_ly->setText("", impl::PART_TXT_TEXT_INFO); + } + + m_blinkCount++; + + if (m_blinkCount == impl::END_CALL_BLINKING_MAX_COUNT) { + m_ly->setText(STR_CALL_ENDED, impl::PART_TXT_TEXT_INFO); + m_timer = nullptr; + return ECORE_CALLBACK_CANCEL; + } + return ECORE_CALLBACK_RENEW; + } + + Result CallStatusPresenter::processEndMode() + { + if (m_timer) { + ecore_timer_del(m_timer); + m_timer = nullptr; + } + + if (const auto info = m_info.lock()) { + m_duration = info->getDuration(); + } + + m_timer = ecore_timer_add(impl::END_CALL_BLINKING_TIMER_INTERVAL, + CALLBACK_B(CallStatusPresenter::onBlinkingTimerCb), this); + if (!m_timer) { + LOG_RETURN(RES_FAIL, "m_timer is NULL"); + } + + return RES_OK; + } + +} diff --git a/src/presenters/Indicator.cpp b/src/presenters/Indicator.cpp deleted file mode 100644 index cda01fc..0000000 --- a/src/presenters/Indicator.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "presenters/Indicator.h" - -#include - -#include "model/IIndicatorStateProvider.h" - -#include "common.h" - -namespace callui { namespace { namespace impl { - using namespace ucl; - - constexpr int BATTERY_LOW_LIMIT = 5; - - constexpr LayoutTheme LAYOUT_INDICATOR_WIDGET - {"layout", "callui", "indicator"}; - - constexpr LayoutTheme LAYOUT_CONNECTION - {"layout", "callui", "connection"}; - - constexpr LayoutTheme LAYOUT_RSSI - {"layout", "callui", "rssi"}; - - constexpr LayoutTheme LAYOUT_BATTERY - {"layout", "callui", "battery"}; - - constexpr LayoutTheme LAYOUT_SIM - {"layout", "callui", "sim"}; - - constexpr LayoutTheme LAYOUT_HD_CALL - {"layout", "callui", "hd_voice"}; - - - constexpr EdjePart PART_CONNECTION {"swl.connection"}; - constexpr EdjePart PART_RSSI {"swl.rssi"}; - constexpr EdjePart PART_BATTERY {"swl.battery"}; - constexpr EdjePart PART_SIM {"swl.sim"}; - constexpr EdjePart PART_HD_VOICE {"swl.hd_voice"}; - - constexpr EdjeSignal SIGL_BATT_LVL_HIDE {"batt_lvl_hide"}; - - EdjeSignal getConnUpdateSignal(ConnectionType connection) - { - switch (connection) { - case ConnectionType::EDGE_E: return EdjeSignal{"conn_edge_connected"}; - case ConnectionType::GPRS_G: return EdjeSignal{"conn_gprs_connected"}; - case ConnectionType::SIMPLE_2G: return EdjeSignal{"conn_2g_connected"}; - case ConnectionType::HSDPA_H: return EdjeSignal{"conn_hsdpa_connected"}; - case ConnectionType::HSPA_H_PLUS: return EdjeSignal{"conn_hspa_connected"}; - case ConnectionType::LTE_4G: return EdjeSignal{"conn_lte_connected"}; - case ConnectionType::UMTS_3G: return EdjeSignal{"conn_umts_connected"}; - case ConnectionType::UMTS_3G_PLUS: return EdjeSignal{"conn_3g_plus_connected"}; - case ConnectionType::WIFI_00: return EdjeSignal{"conn_wifi_connected_00"}; - case ConnectionType::WIFI_01: return EdjeSignal{"conn_wifi_connected_01"}; - case ConnectionType::WIFI_02: return EdjeSignal{"conn_wifi_connected_02"}; - case ConnectionType::WIFI_03: return EdjeSignal{"conn_wifi_connected_03"}; - case ConnectionType::WIFI_04: return EdjeSignal{"conn_wifi_connected_04"}; - case ConnectionType::NO_SIGNAL: return EdjeSignal{"conn_no_signal"}; - default: return EdjeSignal{"conn_none"}; - } - } - - EdjeSignal getPacketUpdateSignal(PacketDirection direction) - { - switch (direction) { - case PacketDirection::NO_INPUT: return EdjeSignal{"packet_no_inout_connected"}; - case PacketDirection::IN: return EdjeSignal{"packet_in_connected"}; - case PacketDirection::OUT: return EdjeSignal{"packet_out_connected"}; - case PacketDirection::INOUT: return EdjeSignal{"packet_inout_connected"}; - default: return EdjeSignal{"packet_none"}; - } - } - - EdjeSignal getRssiUpdateSignal(RssiState state, bool isRoaming) - { - switch (state) { - case RssiState::LEVEL_0: return EdjeSignal{ isRoaming ? "rssi_roaming_00" : "rssi_00"}; - case RssiState::LEVEL_1: return EdjeSignal{ isRoaming ? "rssi_roaming_01" : "rssi_01"}; - case RssiState::LEVEL_2: return EdjeSignal{ isRoaming ? "rssi_roaming_02" : "rssi_02"}; - case RssiState::LEVEL_3: return EdjeSignal{ isRoaming ? "rssi_roaming_03" : "rssi_03"}; - case RssiState::LEVEL_4: return EdjeSignal{ isRoaming ? "rssi_roaming_04" : "rssi_04"}; - case RssiState::NO_SIGNAL: return EdjeSignal{"rssi_no_signal"}; - case RssiState::FLIGHT_MODE: return EdjeSignal{"rssi_flight_mode"}; - default: return EdjeSignal{"rssi_none"}; - } - } - - EdjeSignal getBatteryStateUpdateSignal(BatteryState state, int battLvl) - { - switch (state) { - case BatteryState::CHARGING: return EdjeSignal{"batt_state_charging"}; - case BatteryState::CHARGING_PROBLEM: return EdjeSignal{"batt_state_charging_problem"}; - case BatteryState::UNKNOWN: return EdjeSignal{"batt_state_unknown"}; - default: - if (battLvl > BATTERY_LOW_LIMIT) - return EdjeSignal{"batt_state_normal"}; - else - return EdjeSignal{"batt_state_low_battery"}; - } - } - - EdjeSignal getBatteryLevelUpdateSignal(int level, bool isLevelUnknown) - { - if (isLevelUnknown) { - return impl::SIGL_BATT_LVL_HIDE; - } - - auto battLvl = level; - if (battLvl <= BATTERY_LOW_LIMIT) { - battLvl /= BATTERY_LOW_LIMIT; - battLvl *= BATTERY_LOW_LIMIT; - } else { - battLvl += BATTERY_LOW_LIMIT - 1; - battLvl /= BATTERY_LOW_LIMIT; - battLvl *= BATTERY_LOW_LIMIT; - } - - if (battLvl <= BATTERY_LOW_LIMIT - 1) { - return impl::SIGL_BATT_LVL_HIDE; - } - return EdjeSignal{std::string("batt_lvl_"). - append(std::to_string(battLvl)). - c_str()}; - - } - - EdjeSignal getSimSlotUpdateSignal(SimSlot slot, bool isForwarded) - { - switch (slot) { - case SimSlot::GEAR: - if (isForwarded) { - return EdjeSignal{"sim_gear_forwarded"}; - } else { - return EdjeSignal{"sim_gear"}; - } - case SimSlot::MOBILE_DEFAULT: return EdjeSignal{"sim_mobile"}; - case SimSlot::MOBILE_FIRST: return EdjeSignal{"sim_mobile_01"}; - case SimSlot::MOBILE_SECOND: return EdjeSignal{"sim_mobile_02"}; - default: return EdjeSignal{"sim_unknown"}; - } - } - -}}} - -namespace callui { - - using namespace ucl; - - Indicator::Builder::Builder() - { - } - - Indicator::Builder::~Builder() - { - } - - Indicator::Builder &Indicator::Builder::setIndicatorStateProvider( - const IIndicatorStateProviderSRef &provider) - { - m_provider = provider; - return *this; - } - - IndicatorSRef Indicator::Builder::build(ElmWidget &parent) const - { - if (!m_provider) { - LOG_RETURN_VALUE(RES_FAIL, {}, "Not all params are set"); - } - - auto result = makeShared(m_provider); - FAIL_RETURN_VALUE(result->prepare(parent), {}, - "result->prepare() failed!"); - return result; - } - - Indicator::Indicator(IRefCountObj &rc, - const IIndicatorStateProviderSRef &provider): - Presenter(rc), - m_provider(provider) - { - } - - Indicator::~Indicator() - { - } - - Result Indicator::prepare(ElmWidget &parent) - { - FAIL_RETURN(Presenter::prepare(parent), - "Presenter::prepare() failed!"); - - FAIL_RETURN(createWidget(parent), - "createWidget() failed!"); - - FAIL_RETURN(createConnectionLayout(), - "createConnectionLayout() failed!"); - - FAIL_RETURN(createRssiLayout(), - "createRssiLayout() failed!"); - - FAIL_RETURN(createBatteryLayout(), - "createBatteryLayout() failed!"); - - FAIL_RETURN(createSimLayout(), - "createSimLayout() failed!"); - - FAIL_RETURN(createHdVoiceLayout(), - "createHdCallLayout() failed!"); - - m_provider->setListener(asWeak(*this)); - - return RES_OK; - } - - Result Indicator::createWidget(ElmWidget &parent) - { - m_widget = Layout::Builder(). - setTheme(impl::LAYOUT_INDICATOR_WIDGET). - setIsOwner(true). - build(parent); - if (!m_widget) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - - return RES_OK; - } - - Result Indicator::createConnectionLayout() - { - m_connLayout = Layout::Builder(). - setTheme(impl::LAYOUT_CONNECTION). - build(*m_widget); - if (!m_connLayout) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - m_widget->setContent(*m_connLayout, impl::PART_CONNECTION); - - updateConnectionState(); - - return RES_OK; - } - - Result Indicator::createRssiLayout() - { - m_rssiLayout = Layout::Builder(). - setTheme(impl::LAYOUT_RSSI). - build(*m_widget); - if (!m_rssiLayout) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - m_widget->setContent(*m_rssiLayout, impl::PART_RSSI); - - updateRssiState(); - - return RES_OK; - } - - Result Indicator::createBatteryLayout() - { - m_batteryLayout = Layout::Builder(). - setTheme(impl::LAYOUT_BATTERY). - build(*m_widget); - if (!m_batteryLayout) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - m_widget->setContent(*m_batteryLayout, impl::PART_BATTERY); - - updateBatteryState(); - - return RES_OK; - } - - Result Indicator::createSimLayout() - { - m_simLayout = Layout::Builder(). - setTheme(impl::LAYOUT_SIM). - build(*m_widget); - if (!m_simLayout) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - m_widget->setContent(*m_simLayout, impl::PART_SIM); - - updateSimState(); - - return RES_OK; - } - - Result Indicator::createHdVoiceLayout() - { - m_hdCallLayout = Layout::Builder(). - setTheme(impl::LAYOUT_HD_CALL). - build(*m_widget); - if (!m_hdCallLayout) { - LOG_RETURN(RES_FAIL, "Layout::build() failed!"); - } - m_widget->setContent(*m_hdCallLayout, impl::PART_HD_VOICE); - - updateHdVoiceState(); - - return RES_OK; - } - - void Indicator::updateConnectionState() - { - auto state = m_provider->getState(IndicatorProperty::NW_CONNECTION); - - m_connLayout->emit(impl::getConnUpdateSignal( - getConnectionState(state))); - - m_connLayout->emit(impl::getPacketUpdateSignal( - getPacketDirection(state))); - } - - void Indicator::updateRssiState() - { - auto state = m_provider->getState(IndicatorProperty::RSSI); - - m_rssiLayout->emit(impl::getRssiUpdateSignal( - getRssiState(state), - getRoamingState(state))); - } - - void Indicator::updateBatteryState() - { - auto state = m_provider->getState(IndicatorProperty::BATTERY); - auto battState = getBatteryState(state); - auto battLvl = getBatteryLevel(state); - - m_batteryLayout->emit( - impl::getBatteryStateUpdateSignal(battState, battLvl)); - m_batteryLayout->emit( - impl::getBatteryLevelUpdateSignal(battLvl, - (battState == BatteryState::UNKNOWN))); - } - - void Indicator::updateSimState() - { - auto state = m_provider->getState(IndicatorProperty::SIM_SLOT); - - m_simLayout->emit(impl::getSimSlotUpdateSignal( - getSimSlotType(state), - getSimForwardState(state))); - } - - void Indicator::updateHdVoiceState() - { - auto state = m_provider->getState(IndicatorProperty::HD_VOICE); - m_hdCallLayout->emit(EdjeSignal{ - (getHDVoiceState(state) ? "hd_voice_show" : "hd_voice_hide")}); - } - - Widget &Indicator::getWidget() - { - return *m_widget; - } - - void Indicator::onStateChanged(IndicatorProperty property) - { - switch (property) { - case IndicatorProperty::NW_CONNECTION: - updateConnectionState(); - break; - case IndicatorProperty::RSSI: - updateRssiState(); - break; - case IndicatorProperty::BATTERY: - updateBatteryState(); - break; - case IndicatorProperty::SIM_SLOT: - updateSimState(); - break; - case IndicatorProperty::HD_VOICE: - updateHdVoiceState(); - break; - default: - ELOG("Unhandled state"); - return; - } - } - -} diff --git a/src/presenters/IndicatorPresenter.cpp b/src/presenters/IndicatorPresenter.cpp new file mode 100644 index 0000000..7ec1d57 --- /dev/null +++ b/src/presenters/IndicatorPresenter.cpp @@ -0,0 +1,406 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "presenters/IndicatorPresenter.h" + +#include + +#include "model/IIndicatorStateProvider.h" + +#include "common.h" + +namespace callui { namespace { namespace impl { + using namespace ucl; + + constexpr int BATTERY_LOW_LIMIT = 5; + + constexpr LayoutTheme LAYOUT_INDICATOR_WIDGET + {"layout", "callui", "indicator"}; + + constexpr LayoutTheme LAYOUT_CONNECTION + {"layout", "callui", "connection"}; + + constexpr LayoutTheme LAYOUT_RSSI + {"layout", "callui", "rssi"}; + + constexpr LayoutTheme LAYOUT_BATTERY + {"layout", "callui", "battery"}; + + constexpr LayoutTheme LAYOUT_SIM + {"layout", "callui", "sim"}; + + constexpr LayoutTheme LAYOUT_HD_CALL + {"layout", "callui", "hd_voice"}; + + + constexpr EdjePart PART_CONNECTION {"swl.connection"}; + constexpr EdjePart PART_RSSI {"swl.rssi"}; + constexpr EdjePart PART_BATTERY {"swl.battery"}; + constexpr EdjePart PART_SIM {"swl.sim"}; + constexpr EdjePart PART_HD_VOICE {"swl.hd_voice"}; + + constexpr EdjeSignal SIGL_BATT_LVL_HIDE {"batt_lvl_hide"}; + + EdjeSignal getConnUpdateSignal(ConnectionType connection) + { + switch (connection) { + case ConnectionType::EDGE_E: return EdjeSignal{"conn_edge_connected"}; + case ConnectionType::GPRS_G: return EdjeSignal{"conn_gprs_connected"}; + case ConnectionType::SIMPLE_2G: return EdjeSignal{"conn_2g_connected"}; + case ConnectionType::HSDPA_H: return EdjeSignal{"conn_hsdpa_connected"}; + case ConnectionType::HSPA_H_PLUS: return EdjeSignal{"conn_hspa_connected"}; + case ConnectionType::LTE_4G: return EdjeSignal{"conn_lte_connected"}; + case ConnectionType::UMTS_3G: return EdjeSignal{"conn_umts_connected"}; + case ConnectionType::UMTS_3G_PLUS: return EdjeSignal{"conn_3g_plus_connected"}; + case ConnectionType::WIFI_00: return EdjeSignal{"conn_wifi_connected_00"}; + case ConnectionType::WIFI_01: return EdjeSignal{"conn_wifi_connected_01"}; + case ConnectionType::WIFI_02: return EdjeSignal{"conn_wifi_connected_02"}; + case ConnectionType::WIFI_03: return EdjeSignal{"conn_wifi_connected_03"}; + case ConnectionType::WIFI_04: return EdjeSignal{"conn_wifi_connected_04"}; + case ConnectionType::NO_SIGNAL: return EdjeSignal{"conn_no_signal"}; + default: return EdjeSignal{"conn_none"}; + } + } + + EdjeSignal getPacketUpdateSignal(PacketDirection direction) + { + switch (direction) { + case PacketDirection::NO_INPUT: return EdjeSignal{"packet_no_inout_connected"}; + case PacketDirection::IN: return EdjeSignal{"packet_in_connected"}; + case PacketDirection::OUT: return EdjeSignal{"packet_out_connected"}; + case PacketDirection::INOUT: return EdjeSignal{"packet_inout_connected"}; + default: return EdjeSignal{"packet_none"}; + } + } + + EdjeSignal getRssiUpdateSignal(RssiState state, bool isRoaming) + { + switch (state) { + case RssiState::LEVEL_0: return EdjeSignal{ isRoaming ? "rssi_roaming_00" : "rssi_00"}; + case RssiState::LEVEL_1: return EdjeSignal{ isRoaming ? "rssi_roaming_01" : "rssi_01"}; + case RssiState::LEVEL_2: return EdjeSignal{ isRoaming ? "rssi_roaming_02" : "rssi_02"}; + case RssiState::LEVEL_3: return EdjeSignal{ isRoaming ? "rssi_roaming_03" : "rssi_03"}; + case RssiState::LEVEL_4: return EdjeSignal{ isRoaming ? "rssi_roaming_04" : "rssi_04"}; + case RssiState::NO_SIGNAL: return EdjeSignal{"rssi_no_signal"}; + case RssiState::FLIGHT_MODE: return EdjeSignal{"rssi_flight_mode"}; + default: return EdjeSignal{"rssi_none"}; + } + } + + EdjeSignal getBatteryStateUpdateSignal(BatteryState state, int battLvl) + { + switch (state) { + case BatteryState::CHARGING: return EdjeSignal{"batt_state_charging"}; + case BatteryState::CHARGING_PROBLEM: return EdjeSignal{"batt_state_charging_problem"}; + case BatteryState::UNKNOWN: return EdjeSignal{"batt_state_unknown"}; + default: + if (battLvl > BATTERY_LOW_LIMIT) + return EdjeSignal{"batt_state_normal"}; + else + return EdjeSignal{"batt_state_low_battery"}; + } + } + + EdjeSignal getBatteryLevelUpdateSignal(int level, bool isLevelUnknown) + { + if (isLevelUnknown) { + return impl::SIGL_BATT_LVL_HIDE; + } + + auto battLvl = level; + if (battLvl <= BATTERY_LOW_LIMIT) { + battLvl /= BATTERY_LOW_LIMIT; + battLvl *= BATTERY_LOW_LIMIT; + } else { + battLvl += BATTERY_LOW_LIMIT - 1; + battLvl /= BATTERY_LOW_LIMIT; + battLvl *= BATTERY_LOW_LIMIT; + } + + if (battLvl <= BATTERY_LOW_LIMIT - 1) { + return impl::SIGL_BATT_LVL_HIDE; + } + return EdjeSignal{std::string("batt_lvl_"). + append(std::to_string(battLvl)). + c_str()}; + + } + + EdjeSignal getSimSlotUpdateSignal(SimSlot slot, bool isForwarded) + { + switch (slot) { + case SimSlot::GEAR: + if (isForwarded) { + return EdjeSignal{"sim_gear_forwarded"}; + } else { + return EdjeSignal{"sim_gear"}; + } + case SimSlot::MOBILE_DEFAULT: return EdjeSignal{"sim_mobile"}; + case SimSlot::MOBILE_FIRST: return EdjeSignal{"sim_mobile_01"}; + case SimSlot::MOBILE_SECOND: return EdjeSignal{"sim_mobile_02"}; + default: return EdjeSignal{"sim_unknown"}; + } + } + +}}} + +namespace callui { + + using namespace ucl; + + IndicatorPresenter::Builder::Builder() + { + } + + IndicatorPresenter::Builder::~Builder() + { + } + + IndicatorPresenter::Builder & + IndicatorPresenter::Builder::setIndicatorStateProvider( + const IIndicatorStateProviderSRef &provider) + { + m_provider = provider; + return *this; + } + + IndicatorPresenter::Builder & + IndicatorPresenter::Builder::setParentWidget(const ucl::ElmWidgetSRef &parentWidget) + { + m_parentWidget = parentWidget; + return *this; + } + + IndicatorPresenterSRef + IndicatorPresenter::Builder::build(Presenter &parent) const + { + if (!m_provider || !m_parentWidget) { + LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are not set"); + } + + auto result = makeShared(m_provider); + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), {}, + "result->prepare() failed!"); + return result; + } + + IndicatorPresenter::IndicatorPresenter(IRefCountObj &rc, + const IIndicatorStateProviderSRef &provider): + Presenter(rc), + m_provider(provider) + { + } + + IndicatorPresenter::~IndicatorPresenter() + { + } + + Result IndicatorPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget) + { + FAIL_RETURN(Presenter::prepare(parent, PF_PASSIVE), + "Presenter::prepare() failed!"); + + FAIL_RETURN(createWidget(parentWidget), + "createWidget() failed!"); + + FAIL_RETURN(createConnectionLayout(), + "createConnectionLayout() failed!"); + + FAIL_RETURN(createRssiLayout(), + "createRssiLayout() failed!"); + + FAIL_RETURN(createBatteryLayout(), + "createBatteryLayout() failed!"); + + FAIL_RETURN(createSimLayout(), + "createSimLayout() failed!"); + + FAIL_RETURN(createHdVoiceLayout(), + "createHdCallLayout() failed!"); + + m_provider->setListener(asWeak(*this)); + + return RES_OK; + } + + Result IndicatorPresenter::createWidget(ElmWidget &parent) + { + m_widget = Layout::Builder(). + setTheme(impl::LAYOUT_INDICATOR_WIDGET). + setIsOwner(true). + build(parent); + if (!m_widget) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + + return RES_OK; + } + + Result IndicatorPresenter::createConnectionLayout() + { + m_connLayout = Layout::Builder(). + setTheme(impl::LAYOUT_CONNECTION). + build(*m_widget); + if (!m_connLayout) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + m_widget->setContent(*m_connLayout, impl::PART_CONNECTION); + + updateConnectionState(); + + return RES_OK; + } + + Result IndicatorPresenter::createRssiLayout() + { + m_rssiLayout = Layout::Builder(). + setTheme(impl::LAYOUT_RSSI). + build(*m_widget); + if (!m_rssiLayout) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + m_widget->setContent(*m_rssiLayout, impl::PART_RSSI); + + updateRssiState(); + + return RES_OK; + } + + Result IndicatorPresenter::createBatteryLayout() + { + m_batteryLayout = Layout::Builder(). + setTheme(impl::LAYOUT_BATTERY). + build(*m_widget); + if (!m_batteryLayout) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + m_widget->setContent(*m_batteryLayout, impl::PART_BATTERY); + + updateBatteryState(); + + return RES_OK; + } + + Result IndicatorPresenter::createSimLayout() + { + m_simLayout = Layout::Builder(). + setTheme(impl::LAYOUT_SIM). + build(*m_widget); + if (!m_simLayout) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + m_widget->setContent(*m_simLayout, impl::PART_SIM); + + updateSimState(); + + return RES_OK; + } + + Result IndicatorPresenter::createHdVoiceLayout() + { + m_hdCallLayout = Layout::Builder(). + setTheme(impl::LAYOUT_HD_CALL). + build(*m_widget); + if (!m_hdCallLayout) { + LOG_RETURN(RES_FAIL, "Layout::build() failed!"); + } + m_widget->setContent(*m_hdCallLayout, impl::PART_HD_VOICE); + + updateHdVoiceState(); + + return RES_OK; + } + + void IndicatorPresenter::updateConnectionState() + { + auto state = m_provider->getState(IndicatorProperty::NW_CONNECTION); + + m_connLayout->emit(impl::getConnUpdateSignal( + getConnectionState(state))); + + m_connLayout->emit(impl::getPacketUpdateSignal( + getPacketDirection(state))); + } + + void IndicatorPresenter::updateRssiState() + { + auto state = m_provider->getState(IndicatorProperty::RSSI); + + m_rssiLayout->emit(impl::getRssiUpdateSignal( + getRssiState(state), + getRoamingState(state))); + } + + void IndicatorPresenter::updateBatteryState() + { + auto state = m_provider->getState(IndicatorProperty::BATTERY); + auto battState = getBatteryState(state); + auto battLvl = getBatteryLevel(state); + + m_batteryLayout->emit( + impl::getBatteryStateUpdateSignal(battState, battLvl)); + m_batteryLayout->emit( + impl::getBatteryLevelUpdateSignal(battLvl, + (battState == BatteryState::UNKNOWN))); + } + + void IndicatorPresenter::updateSimState() + { + auto state = m_provider->getState(IndicatorProperty::SIM_SLOT); + + m_simLayout->emit(impl::getSimSlotUpdateSignal( + getSimSlotType(state), + getSimForwardState(state))); + } + + void IndicatorPresenter::updateHdVoiceState() + { + auto state = m_provider->getState(IndicatorProperty::HD_VOICE); + m_hdCallLayout->emit(EdjeSignal{ + (getHDVoiceState(state) ? "hd_voice_show" : "hd_voice_hide")}); + } + + Widget &IndicatorPresenter::getWidget() + { + return *m_widget; + } + + void IndicatorPresenter::onStateChanged(IndicatorProperty property) + { + switch (property) { + case IndicatorProperty::NW_CONNECTION: + updateConnectionState(); + break; + case IndicatorProperty::RSSI: + updateRssiState(); + break; + case IndicatorProperty::BATTERY: + updateBatteryState(); + break; + case IndicatorProperty::SIM_SLOT: + updateSimState(); + break; + case IndicatorProperty::HD_VOICE: + updateHdVoiceState(); + break; + default: + ELOG("Unhandled state"); + return; + } + } + +} diff --git a/src/presenters/Instance.cpp b/src/presenters/Instance.cpp index b3f815a..8da8645 100644 --- a/src/presenters/Instance.cpp +++ b/src/presenters/Instance.cpp @@ -119,7 +119,8 @@ namespace callui { auto page = MainPage::Builder(). setNaviframe(m_navi). setCall(m_call). - build(DELEGATE(Instance::onPageExitRequest, this)); + build(WEAK_DELEGATE(Instance::onPageExitRequest, + asWeak(this))); if (!page) { ELOG("Create page failed! Exit application"); m_context->exitApp(); diff --git a/src/presenters/KeypadPage.cpp b/src/presenters/KeypadPage.cpp index 791efd4..e1460b3 100644 --- a/src/presenters/KeypadPage.cpp +++ b/src/presenters/KeypadPage.cpp @@ -62,8 +62,11 @@ namespace callui { auto result = makeShared(m_navi, onExitRequest); - FAIL_RETURN_VALUE(result->prepare(), {}, - "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare([&result](NaviItem &item) + { + return result->doPrepare(item); + }), + {}, "result->prepare() failed!"); return result; } @@ -81,7 +84,7 @@ namespace callui { { } - Result KeypadPage::prepare() + Result KeypadPage::doPrepare(NaviItem &item) { m_widget = Layout::Builder(). setTheme(impl::LAYOUT_KEYPAD_WIDGET). @@ -91,9 +94,11 @@ namespace callui { LOG_RETURN(RES_FAIL, "Layout::build() failed!"); } - return Page::prepare([this]() { - return getNaviframe().push(*m_widget); - }); + item = getNaviframe().push(*m_widget); + if (!item) { + LOG_RETURN(RES_FAIL, "Naviframe::push() failed!"); + } + return RES_OK; } } diff --git a/src/presenters/MainPage.cpp b/src/presenters/MainPage.cpp index d63715e..ea7683b 100644 --- a/src/presenters/MainPage.cpp +++ b/src/presenters/MainPage.cpp @@ -29,7 +29,7 @@ #include "model/ICallInfo.h" #include "model/IRejectMsgProvider.h" -#include "presenters/Indicator.h" +#include "presenters/IndicatorPresenter.h" #include "presenters/AcceptRejectPresenter.h" #include "presenters/CallInfoPresenter.h" #include "presenters/RejectMsgPresenter.h" @@ -114,8 +114,11 @@ namespace callui { auto result = makeShared( m_navi, handler, m_call); - FAIL_RETURN_VALUE(result->prepare(), {}, - "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare([&result](NaviItem &item) + { + return result->doPrepare(item); + }), + {}, "result->prepare() failed!"); return result; } @@ -138,7 +141,7 @@ namespace callui { { } - Result MainPage::prepare() + Result MainPage::doPrepare(NaviItem &item) { m_cm = m_call->getCallManager(); if (!m_cm) { @@ -156,47 +159,12 @@ namespace callui { win->addEventHandler(WIN_POWER_KEY_UP_EVENT, WEAK_DELEGATE( MainPage::onPowerKeyUp, asWeak(*this))); - return Page::prepare([this]() { - return getNaviframe().push(*m_widget); - }); - } - - void MainPage::onActivateBy(const DeactivatorInfo &info) - { - if (info.isBroadcast) { - return; - } - - if (m_rmPrs) { - m_rmPrs->activateBy(info.deactivator); - } - - if (m_acceptRejectPrs) { - m_acceptRejectPrs->activateBy(info.deactivator); - } - - if (m_accessoryPrs) { - m_accessoryPrs->activateBy(info.deactivator); - } - } - - void MainPage::onDeactivateBy(const DeactivatorInfo &info) - { - if (info.isBroadcast) { - return; + item = getNaviframe().push(*m_widget); + if (!item) { + LOG_RETURN(RES_FAIL, "Naviframe::push() failed!"); } - if (m_rmPrs) { - m_rmPrs->deactivateBy(info.deactivator); - } - - if (m_acceptRejectPrs) { - m_acceptRejectPrs->deactivateBy(info.deactivator); - } - - if (m_accessoryPrs) { - m_accessoryPrs->deactivateBy(info.deactivator); - } + return RES_OK; } void MainPage::processKeyPress() @@ -476,15 +444,18 @@ namespace callui { LOG_RETURN(RES_FAIL, "Layout::build() failed!"); } + setDeactivatorSink(m_widget); + return RES_OK; } Result MainPage::createIndicatorPresenter() { - m_indicator = Indicator::Builder(). + m_indicator = IndicatorPresenter::Builder(). setIndicatorStateProvider( m_call->getIndicatorStateProvider()). - build(*m_widget); + setParentWidget(m_widget). + build(*this); if (!m_indicator) { LOG_RETURN(RES_FAIL, "Indicator::build() failed!"); @@ -525,7 +496,8 @@ namespace callui { m_accessoryPrs = AccessoryPresenter::Builder(). setMuteControlDisabled(detectMuteControlDisableState()). setSoundManager(m_call->getSoundManager()). - build(*m_widget); + setParentWidget(m_widget). + build(*this); if (!m_accessoryPrs) { LOG_RETURN(RES_FAIL, @@ -550,7 +522,8 @@ namespace callui { setCallManager(m_cm). setSoundManager(m_call->getSoundManager()). setNaviframe(asShared(getNaviframe())). - build(*m_widget); + setParentWidget(m_widget). + build(*this); if (!m_moreOptionsPrs) { LOG_RETURN(RES_FAIL, @@ -559,7 +532,6 @@ namespace callui { m_widget->setContent(m_moreOptionsPrs->getWidget(), impl::PART_SWL_MORE_OPTION); - addDeactivatorSource(m_moreOptionsPrs->getWidget()); return RES_OK; } @@ -574,7 +546,8 @@ namespace callui { m_acceptRejectPrs = AcceptRejectPresenter::Builder(). setIncomingCall(m_cm->getIncomingCall()). setAvailableCallsFlag(m_cm->getAvailableCalls()). - build(*m_widget); + setParentWidget(m_widget). + build(*this); if (!m_acceptRejectPrs) { LOG_RETURN(RES_FAIL, @@ -605,13 +578,12 @@ namespace callui { { m_rmPrs = RejectMsgPresenter::Builder(). setProvider(provider). - setStateHandler( - WEAK_DELEGATE(MainPage::RejectMsgStateCb, - asWeak(*this))). - setSelectHandler( - WEAK_DELEGATE(MainPage::RejectMsgSelectCb, - asWeak(*this))). - build(*m_widget); + setStateHandler(WEAK_DELEGATE(MainPage::RejectMsgStateCb, + asWeak(*this))). + setSelectHandler(WEAK_DELEGATE(MainPage::RejectMsgSelectCb, + asWeak(*this))). + setParentWidget(m_widget). + build(*this); if (!m_rmPrs) { LOG_RETURN(RES_FAIL, @@ -620,7 +592,6 @@ namespace callui { m_widget->setContent(m_rmPrs->getWidget().getEo(), impl::PART_SWL_OVERLAY); - addDeactivatorSource(m_rmPrs->getWidget()); return RES_OK; } @@ -634,7 +605,8 @@ namespace callui { m_callInfoPrs = CallInfoPresenter::Builder(). setCallManager(m_cm). setMode(mode). - build(*m_widget); + setParentWidget(m_widget). + build(*this); if (!m_callInfoPrs) { LOG_RETURN(RES_FAIL, "CallerInfo::build() failed!"); diff --git a/src/presenters/MoreOptionsPresenter.cpp b/src/presenters/MoreOptionsPresenter.cpp index 75e7b39..91b3ee6 100644 --- a/src/presenters/MoreOptionsPresenter.cpp +++ b/src/presenters/MoreOptionsPresenter.cpp @@ -96,15 +96,23 @@ namespace callui { return *this; } + MoreOptionsPresenter::Builder & + MoreOptionsPresenter::Builder::setParentWidget( + const ElmWidgetSRef &parentWidget) + { + m_parentWidget = parentWidget; + return *this; + } + MoreOptionsPresenterSRef - MoreOptionsPresenter::Builder::build(ElmWidget &parent) const + MoreOptionsPresenter::Builder::build(Presenter &parent) const { - if (!m_cm || !m_sm || !m_navi) { + if (!m_cm || !m_sm || !m_navi || !m_parentWidget) { LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are not set"); } auto result = makeShared(m_cm, m_sm, m_navi); - FAIL_RETURN_VALUE(result->prepare(parent), {}, + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), {}, "result->prepare() failed!"); return result; @@ -132,7 +140,7 @@ namespace callui { eext_object_event_callback_del(*m_widget, EEXT_CALLBACK_BACK, CALLBACK_A(MoreOptionsPresenter::onBackKey)); - sendActivateBy(*m_widget, this); + sendActivate(*m_widget); } m_sm->removeAudioStateHandler(DELEGATE( @@ -143,11 +151,13 @@ namespace callui { } } - Result MoreOptionsPresenter::prepare(ElmWidget &parent) + Result MoreOptionsPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget) { - FAIL_RETURN(Presenter::prepare(parent), "Presenter::prepare() failed!"); + FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), + "Presenter::prepare() failed!"); - FAIL_RETURN(createWidget(parent), "createWidget() failed!"); + FAIL_RETURN(createWidget(parentWidget), "createWidget() failed!"); FAIL_RETURN(createPanel(), "createPanel() failed!"); @@ -160,7 +170,9 @@ namespace callui { update(); - addDeactivatorException(this); + deactivateBy(m_widget.get()); + + parent.addDeactivatorSource(*m_widget); return RES_OK; } @@ -374,8 +386,9 @@ namespace callui { } else { LOG_RETURN_VOID(RES_FAIL, "Naviframe is NULL"); } - m_keypad = builder.build(DELEGATE( - MoreOptionsPresenter::onPageExitRequest, this)); + m_keypad = builder.build( + WEAK_DELEGATE(MoreOptionsPresenter::onPageExitRequest, + asWeak(this))); } void MoreOptionsPresenter::onPageExitRequest(Page &page) @@ -428,7 +441,7 @@ namespace callui { CALLBACK_A(MoreOptionsPresenter::onBackKey), this); const auto keepAliver = asShared(*this); - sendDeactivateBy(*m_widget, this); + sendDeactivate(*m_widget); activateBy(m_widget.get()); } @@ -441,7 +454,7 @@ namespace callui { const auto keepAliver = asShared(*this); deactivateBy(m_widget.get()); - sendActivateBy(*m_widget, this); + sendActivate(*m_widget); } void MoreOptionsPresenter::onBackKey(Evas_Object *obj, void *eventInfo) diff --git a/src/presenters/Page.cpp b/src/presenters/Page.cpp index b36d41e..8695f63 100644 --- a/src/presenters/Page.cpp +++ b/src/presenters/Page.cpp @@ -20,8 +20,6 @@ namespace callui { namespace { namespace impl { - using namespace ucl; - constexpr SmartEvent TOP_PAGE_CHANGED {"ucl,top,page,changed"}; }}} @@ -30,7 +28,7 @@ namespace callui { using namespace ucl; Page::Page(IRefCountObj &rc, const NaviframeSRef &navi, - const ExitRequestHandler onExitRequest) : + const ExitRequestHandler &onExitRequest) : Presenter(rc), m_navi(navi), m_onExitRequest(onExitRequest) @@ -47,8 +45,9 @@ namespace callui { Result Page::preparePart2() { - FAIL_RETURN(Presenter::prepare(*m_navi), - "Presenter::prepare() failed!"); + if (!m_item) { + UCL_LOG_RETURN(ucl::RES_FAIL, "m_item is NULL"); + } Evas_Object *content = m_item.getContent(); if (!content) { @@ -97,7 +96,7 @@ namespace callui { void Page::exit() { - if (isAtTop() && !isAtBottom()) { + if (isAtTop() && !isAtBottom() && !m_navi->isInTransition()) { m_navi->pop(); m_item = nullptr; } else { @@ -146,7 +145,12 @@ namespace callui { void Page::requestExit() { - m_onExitRequest(*this); + if (m_onExitRequest) { + m_onExitRequest(*this); + } else { + WLOG("m_onExitRequest is NULL"); + exit(); + } } void Page::updateActiveState() diff --git a/src/presenters/Presenter.cpp b/src/presenters/Presenter.cpp index 6b9503c..b17f5cd 100644 --- a/src/presenters/Presenter.cpp +++ b/src/presenters/Presenter.cpp @@ -20,8 +20,6 @@ namespace callui { namespace { namespace impl { - using namespace ucl; - constexpr SmartEvent ACTIVATE_BY {"callui,activate,by"}; constexpr SmartEvent DEACTIVATE_BY {"callui,deactivate,by"}; }}} @@ -32,42 +30,88 @@ namespace callui { Presenter::Presenter(IRefCountObj &rc) : RefCountAware(&rc), + m_hasBuildInSources(false), + m_isChild(false), m_isPrepared(false) { } Presenter::~Presenter() { + if (m_hasBuildInSources) { + if (m_isChild) { + if (const auto parentSink = m_parentSink.lock()) { + delDeactivatorSource(*parentSink); + } + } else if (m_window) { + delDeactivatorSource(*m_window); + } + } } - Result Presenter::prepare(ElmWidget &widget) + Result Presenter::prepare(ElmWidget &widget, const int flags) { m_window = asShared(widget.getWindow()); if (!m_window) { LOG_RETURN(RES_FAIL, "m_window is NULL!"); } - addDeactivatorSource(*m_window); + if (flags & PF_ADD_DEACTIVATOR_SOURCES) { + addDeactivatorSource(*m_window); + m_hasBuildInSources = true; + } + + if (flags & PF_ADD_SELF_EXCEPT) { + addDeactivatorException(m_rc->getObjPtr()); + } m_isPrepared = true; return RES_OK; } + Result Presenter::prepare(Presenter &parent, const int flags) + { + if (!parent.m_sink) { + LOG_RETURN(RES_FAIL, "parent.m_sink is NULL!"); + } + + for (auto deactivator: parent.m_deactivators) { + if (m_deactivatorExceptions.find(deactivator) == + m_deactivatorExceptions.end()) { + m_deactivators.insert(deactivator); + } + } + + if (flags & PF_ADD_DEACTIVATOR_SOURCES) { + addDeactivatorSource(*parent.m_sink); + m_hasBuildInSources = true; + } + + if (flags & PF_ADD_SELF_EXCEPT) { + addDeactivatorException(m_rc->getObjPtr()); + } + + m_window = parent.m_window; + m_parentSink = parent.m_sink; + m_isChild = true; + m_isPrepared = true; + + return RES_OK; + } + Window &Presenter::getWindow() { + UCL_ASSERT(isWindowReady(), "m_window is NULL!"); return *m_window; } - void Presenter::addDeactivatorSource(Widget &source) + bool Presenter::isWindowReady() const { - source.addEventHandler(impl::ACTIVATE_BY, - WEAK_DELEGATE(Presenter::onActivateBySmart, asWeak(*this))); - source.addEventHandler(impl::DEACTIVATE_BY, - WEAK_DELEGATE(Presenter::onDeactivateBySmart, asWeak(*this))); + return !!m_window; } - void Presenter::addDeactivatorException(void *const deactivator) + void Presenter::addDeactivatorException(const void *const deactivator) { const auto pair = m_deactivatorExceptions.insert(deactivator); if (pair.second) { @@ -75,34 +119,39 @@ namespace callui { } } - void Presenter::sendActivateBy(Widget &sender, void *const deactivator) + void Presenter::setDeactivatorSink(const WidgetSRef &sink) { - sendDeactivator(sender, impl::ACTIVATE_BY, deactivator); + m_sink = sink; } - void Presenter::sendDeactivateBy(Widget &sender, void *const deactivator) + void Presenter::sendActivate(Widget &sender) { - sendDeactivator(sender, impl::DEACTIVATE_BY, deactivator); + sendDeactivator(sender, impl::ACTIVATE_BY, m_rc->getObjPtr()); } - void Presenter::broadcastActivateBy(void *const deactivator) + void Presenter::sendDeactivate(Widget &sender) { - broadcastDeactivator(impl::ACTIVATE_BY, deactivator); + sendDeactivator(sender, impl::DEACTIVATE_BY, m_rc->getObjPtr()); } - void Presenter::broadcastDeactivateBy(void *const deactivator) + void Presenter::broadcastActivate() { - broadcastDeactivator(impl::DEACTIVATE_BY, deactivator); + broadcastDeactivator(impl::ACTIVATE_BY, m_rc->getObjPtr()); + } + + void Presenter::broadcastDeactivate() + { + broadcastDeactivator(impl::DEACTIVATE_BY, m_rc->getObjPtr()); } void Presenter::sendDeactivator(Widget &sender, - SmartEvent event, void *deactivator) + SmartEvent event, const void *deactivator) { sendDeactivatorInfo(sender, event, {deactivator, false}); } void Presenter::broadcastDeactivator(const SmartEvent event, - void *const deactivator) + const void *const deactivator) { sendDeactivatorInfo(*m_window, event, {deactivator, true}); } @@ -118,25 +167,44 @@ namespace callui { return isEmpty(m_deactivators); } - bool Presenter::isDeactivatedBy(void *const deactivator) const + bool Presenter::isDeactivatedBy(const void *const deactivator) const { return (m_deactivators.find(deactivator) != m_deactivators.end()); } - void Presenter::activateBy(void *const deactivator) + void Presenter::activateBy(const void *const deactivator) { activateByImpl({deactivator, false}); } - void Presenter::deactivateBy(void *const deactivator) + void Presenter::deactivateBy(const void *const deactivator) { deactivateByImpl({deactivator, false}); } + void Presenter::addDeactivatorSource(Widget &source) + { + source.addEventHandler(impl::ACTIVATE_BY, + WEAK_DELEGATE(Presenter::onActivateBySmart, asWeak(*this))); + source.addEventHandler(impl::DEACTIVATE_BY, + WEAK_DELEGATE(Presenter::onDeactivateBySmart, asWeak(*this))); + } + + void Presenter::delDeactivatorSource(Widget &source) + { + source.delEventHandler(impl::ACTIVATE_BY, + WEAK_DELEGATE(Presenter::onActivateBySmart, asWeak(*this))); + source.delEventHandler(impl::DEACTIVATE_BY, + WEAK_DELEGATE(Presenter::onDeactivateBySmart, asWeak(*this))); + } + void Presenter::activateByImpl(const DeactivatorInfo &info) { const auto count = m_deactivators.erase(info.deactivator); if (m_isPrepared && (count > 0)) { + if (m_sink) { + sendDeactivatorInfo(*m_sink, impl::ACTIVATE_BY, info); + } onActivateBy(info); if (m_deactivators.size() == 0) { onActivate(); @@ -152,6 +220,9 @@ namespace callui { } const auto pair = m_deactivators.insert(info.deactivator); if (m_isPrepared && pair.second) { + if (m_sink) { + sendDeactivatorInfo(*m_sink, impl::DEACTIVATE_BY, info); + } onDeactivateBy(info); if (m_deactivators.size() == 1) { onDeactivate(); diff --git a/src/presenters/RejectMsgPresenter.cpp b/src/presenters/RejectMsgPresenter.cpp index 400e1be..ec041ff 100644 --- a/src/presenters/RejectMsgPresenter.cpp +++ b/src/presenters/RejectMsgPresenter.cpp @@ -112,17 +112,25 @@ namespace callui { return *this; } - RejectMsgPresenterSRef RejectMsgPresenter::Builder::build( - ElmWidget &parent) const + RejectMsgPresenter::Builder & + RejectMsgPresenter::Builder::setParentWidget( + const ElmWidgetSRef &parentWidget) + { + m_parentWidget = parentWidget; + return *this; + } + + RejectMsgPresenterSRef + RejectMsgPresenter::Builder::build(Presenter &parent) const { - if (!m_provider) { - LOG_RETURN_VALUE(RES_FAIL, {}, "m_provider is NULL"); + if (!m_provider || !m_parentWidget) { + LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are not set"); } auto result = makeShared(m_provider, m_stateHandler, m_selectHandler); - FAIL_RETURN_VALUE(result->prepare(parent), {}, + FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), {}, "result->prepare() failed!"); return result; @@ -144,16 +152,17 @@ namespace callui { RejectMsgPresenter::~RejectMsgPresenter() { if (m_widget) { - sendActivateBy(*m_widget, this); + sendActivate(*m_widget); } } - Result RejectMsgPresenter::prepare(ElmWidget &parent) + Result RejectMsgPresenter::prepare(Presenter &parent, + ElmWidget &parentWidget) { - FAIL_RETURN(Presenter::prepare(parent), + FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), "Presenter::prepare() failed!"); - FAIL_RETURN(createWidget(parent), + FAIL_RETURN(createWidget(parentWidget), "createWidget() failed!"); FAIL_RETURN(createPanel(), @@ -168,9 +177,10 @@ namespace callui { FAIL_RETURN(createGenlist(), "createGenlist() failed!"); - addDeactivatorException(this); deactivateBy(m_widget.get()); + parent.addDeactivatorSource(*m_widget); + return RES_OK; } @@ -207,7 +217,7 @@ namespace callui { m_state = RejectMsgState::SHOWN; // Prevent panel scrolling elm_object_scroll_freeze_push(m_panel->getEo()); - sendDeactivateBy(*m_widget, this); + sendDeactivate(*m_widget); activateBy(m_widget.get()); } else if (ev->rel_y == 0.0) { m_state = RejectMsgState::HIDDEN; @@ -220,7 +230,7 @@ namespace callui { m_panelBg->setColor(0, alphaValue); if (isActive()) { deactivateBy(m_widget.get()); - sendActivateBy(*m_widget, this); + sendActivate(*m_widget); } }