TizenRefApp-6633 Active notification displayed when Messages app launched (part I) 99/87799/5
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 9 Sep 2016 11:39:08 +0000 (14:39 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 9 Sep 2016 12:09:45 +0000 (15:09 +0300)
Change-Id: I7b71a253f6c1c90762f7b0e588f1f6bcea6c68be
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
12 files changed:
src/Common/Controller/inc/App.h
src/Common/Controller/src/App.cpp
src/Common/MsgEngine/inc/MsgSettings.h
src/Common/MsgEngine/src/private/MsgSettingsPrivate.cpp
src/Common/MsgEngine/src/private/MsgSettingsPrivate.h
src/Common/MsgEngine/src/private/MsgUtilsPrivate.cpp
src/Common/MsgEngine/src/private/MsgUtilsPrivate.h
src/Conversation/ConvList/Controller/inc/ConvList.h
src/Conversation/ConvList/Controller/src/ConvList.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp

index 15d4131..575a664 100644 (file)
@@ -61,6 +61,8 @@ namespace Msg
             void removeListener(IAppListener &l);
             bool isPause() const;
 
+            void updateActiveNotifPolicy();
+
         protected:
             bool init();
             void pause();
index 3f84581..f9bfcd2 100644 (file)
@@ -20,6 +20,8 @@
 #include "Logger.h"
 #include "ContactManager.h"
 #include "PathUtils.h"
+#include "MsgEngine.h"
+#include "MsgSettings.h"
 
 #include <algorithm>
 
@@ -160,11 +162,19 @@ void App::pause()
     m_IsPause = true;
     for(IAppListener *l : m_Listeners)
         l->onAppPause();
+    updateActiveNotifPolicy();
 }
 
 void App::resume()
 {
     m_IsPause = false;
+    updateActiveNotifPolicy();
     for(IAppListener *l : m_Listeners)
         l->onAppResume();
 }
+
+void App::updateActiveNotifPolicy()
+{
+    MsgSettings::ActiveNotifPolicy policy = isPause() ? MsgSettings::AppBackgroundPolicy :MsgSettings::AppForegroundPolicy;
+    getMsgEngine().getSettings().setActiveNotifPolicy(policy);
+}
index 5c5f3f9..47e22a4 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef __MsgSettings_h__
 #define __MsgSettings_h__
 
+#include "MsgTypes.h"
+
 #include <string>
 #include <vector>
 
@@ -28,6 +30,13 @@ namespace Msg
     class MsgSettings
     {
         public:
+            enum ActiveNotifPolicy
+            {
+                AppBackgroundPolicy, // App is not running or on background.
+                AppForegroundPolicy  // App is running and on foreground, but not in conversation.
+            };
+
+        public:
             MsgSettings();
             virtual ~MsgSettings();
 
@@ -70,6 +79,9 @@ namespace Msg
             virtual void setMmsAutoRetrRoaming(bool value) = 0;
             virtual bool getMmsAutoRetrRoaming() const = 0;
 
+            virtual void setActiveNotifPolicy(ActiveNotifPolicy type) = 0;
+            virtual void setActiveNotifPolicy(ThreadId id) = 0;
+
         protected:
             typedef std::vector<IMsgSettingsListener *> MsgSettingsListeners;
 
index 8302c8f..c3cc17d 100644 (file)
@@ -38,6 +38,8 @@ MsgSettingsPrivate::MsgSettingsPrivate(msg_handle_t serviceHandle)
     , m_SmsSendOpt()
     , m_MmsSendOpt()
     , m_MmsRecvOpt()
+    , m_pActiveNotifJob(nullptr)
+    , m_ActiveNotifValue(0)
 {
     init();
 }
@@ -64,6 +66,13 @@ void MsgSettingsPrivate::init()
 
 void MsgSettingsPrivate::finit()
 {
+    if(m_pActiveNotifJob)
+    {
+        ecore_job_del(m_pActiveNotifJob);
+        m_pActiveNotifJob= nullptr;
+        // TODO: apply m_ActiveNotifValue when API will be ready
+        MSG_LOG("ActiveNotifValue = ", m_ActiveNotifValue);
+    }
     msg_release_struct(&m_MmsRecvOpt);
     msg_release_struct(&m_MmsSendOpt);
     msg_release_struct(&m_SmsSendOpt);
@@ -269,3 +278,32 @@ bool MsgSettingsPrivate::getMmsAutoRetrRoaming() const
     return res;
 }
 
+void MsgSettingsPrivate::setActiveNotifPolicy(ActiveNotifPolicy type)
+{
+    int value = MsgUtilsPrivate::activeNotifPolicyToNative(type);
+    addJobSetActiveNotifPolicy(value);
+}
+
+void MsgSettingsPrivate::setActiveNotifPolicy(ThreadId id)
+{
+    addJobSetActiveNotifPolicy(id);
+}
+
+void MsgSettingsPrivate::addJobSetActiveNotifPolicy(int value)
+{
+    m_ActiveNotifValue = value;
+    if(!m_pActiveNotifJob)
+    {
+        m_pActiveNotifJob = ecore_job_add
+        (
+            [](void *data)
+            {
+                auto *self =(MsgSettingsPrivate*)data;
+                self->m_pActiveNotifJob = nullptr;
+                // TODO: apply m_ActiveNotifValue when API will be ready
+                MSG_LOG("ActiveNotifValue = ", self->m_ActiveNotifValue);
+            },
+            this
+        );
+    }
+}
index b4ab132..521099a 100644 (file)
@@ -18,6 +18,8 @@
 #define __MsgSettingsPrivate_h__
 
 #include "MsgSettings.h"
+
+#include <Ecore.h>
 #include <msg_types.h>
 
 namespace Msg
@@ -64,9 +66,13 @@ namespace Msg
             virtual void setMmsAutoRetrRoaming(bool value);
             virtual bool getMmsAutoRetrRoaming() const;
 
+            virtual void setActiveNotifPolicy(ActiveNotifPolicy type);
+            virtual void setActiveNotifPolicy(ThreadId id);
+
         private:
             void init();
             void finit();
+            void addJobSetActiveNotifPolicy(int value);
 
         private:
             msg_handle_t m_ServiceHandle;
@@ -74,6 +80,8 @@ namespace Msg
             msg_struct_t m_SmsSendOpt;
             msg_struct_t m_MmsSendOpt;
             msg_struct_t m_MmsRecvOpt;
+            Ecore_Job *m_pActiveNotifJob;
+            int m_ActiveNotifValue;
     };
 }
 
index 4b65c1c..0e2e310 100644 (file)
@@ -301,3 +301,17 @@ Message::NetworkStatus MsgUtilsPrivate::nativeToNetworkStatus(int status)
     };
     return Message::NS_Unknown;
 }
+
+int MsgUtilsPrivate::activeNotifPolicyToNative(MsgSettings::ActiveNotifPolicy policy)
+{
+    switch(policy)
+    {
+        case MsgSettings::AppBackgroundPolicy:
+            return -1;
+        case MsgSettings::AppForegroundPolicy:
+            return 0;
+        default:
+            assert(false);
+    }
+    return 0;
+}
index 23ad2d1..866a2b8 100644 (file)
@@ -21,6 +21,7 @@
 #include "MsgMedia.h"
 #include "MsgReport.h"
 #include "MsgUtils.h"
+#include "MsgSettings.h"
 
 #include <msg_storage.h>
 #include <msg_types.h>
@@ -47,6 +48,7 @@ namespace Msg
             static MsgMedia::Type nativeToSmilType(int type);
             static int smilTypeToNative(MsgMedia::Type type);
             static Message::NetworkStatus nativeToNetworkStatus(int status);
+            static int activeNotifPolicyToNative(MsgSettings::ActiveNotifPolicy policy);
 
             static std::string getStr(msg_struct_t msgStruct, int field, int maxStrLen);
             static int setStr(msg_struct_t msgStruct, int field, const std::string &text);
index 6cfc588..661d541 100644 (file)
@@ -80,12 +80,18 @@ namespace Msg
             Mode getMode() const;
 
             /**
-             * @brief Sets valid thread id
+             * @brief Sets thread id
              * @param[in] thread id
              */
             void setThreadId(ThreadId id,const std::string &searchWord = std::string());
 
             /**
+             * @brief Gets thread id
+             * @return thread id
+             */
+            ThreadId getThreadId() const;
+
+            /**
              * @brief Navigate to message
              * @param[in] msgId message id to navigate
              */
index 09b2f7e..d18e843 100644 (file)
@@ -134,13 +134,15 @@ void ConvList::fill()
 
 void ConvList::setThreadId(ThreadId id, const std::string &searchWord)
 {
-    if(m_ThreadId != id || m_SearchWord != searchWord)
-    {
-        m_ThreadId = id;
-        m_SearchWord = searchWord;
-        updateRecipThumbId();
-        fill();
-    }
+    m_ThreadId = id;
+    m_SearchWord = searchWord;
+    updateRecipThumbId();
+    fill();
+}
+
+ThreadId ConvList::getThreadId() const
+{
+    return m_ThreadId;
 }
 
 void ConvList::updateRecipThumbId()
index e7e7908..3c84ef8 100644 (file)
@@ -176,6 +176,7 @@ namespace Msg
             void setBodyFocus();
             void setRecipEntryFocus();
             void resetMsgThread();
+            void updateActiveNotifPolicy();
 
             void showMainPopup();
             void showNoRecipPopup();
index ea84c93..3b378ba 100644 (file)
@@ -258,8 +258,18 @@ void Conversation::navigateToBottom()
     m_pConvList->navigateToBottom();
 }
 
+void Conversation::updateActiveNotifPolicy()
+{
+    ThreadId threadId = m_pConvList ? m_pConvList->getThreadId() : ThreadId();
+    if(isPause() || !threadId.isValid())
+        getApp().updateActiveNotifPolicy();
+    else
+        getMsgEngine().getSettings().setActiveNotifPolicy(threadId);
+}
+
 void Conversation::setThreadId(ThreadId id, const std::string &searchWord)
 {
+    MSG_LOG("Thread id = ", id);
     m_ThreadId = id;
     if(id.isValid())
         m_AddressList = getMsgEngine().getStorage().getAddressList(id);
@@ -275,9 +285,10 @@ void Conversation::setThreadId(ThreadId id, const std::string &searchWord)
         m_pRecipPanel->update(m_ThreadId);
 
     if(m_pConvList)
-        m_pConvList->setThreadId(m_ThreadId, searchWord);
+        m_pConvList->setThreadId(id, searchWord);
 
     markAsRead();
+    updateActiveNotifPolicy();
     checkAndSetMsgType(true);
 }
 
@@ -818,6 +829,7 @@ void Conversation::onMbeChanged(ConvRecipientsPanel &panel)
             id = getMsgEngine().getStorage().getThreadId(recips);
 
         m_pConvList->setThreadId(id);
+        updateActiveNotifPolicy();
         m_pConvList->navigateToBottom();
     }
 }
@@ -957,11 +969,13 @@ void Conversation::onTransitionFinished(NaviFrameItem &item)
 void Conversation::onPause()
 {
     MSG_LOG("");
+    updateActiveNotifPolicy();
 }
 
 void Conversation::onResume()
 {
     MSG_LOG("");
+    updateActiveNotifPolicy();
 }
 
 void Conversation::onHwBackButtonClicked()
index 182b270..307a288 100644 (file)
@@ -140,12 +140,9 @@ void ConvRecipientsPanel::update(const MsgAddressList &addressList)
 
 void ConvRecipientsPanel::update(const ThreadId &threadId)
 {
-    if(m_ThreadId != threadId)
-    {
-        clear();
-        m_ThreadId = threadId;
-        m_pMbe->update(threadId);
-    }
+    clear();
+    m_ThreadId = threadId;
+    m_pMbe->update(threadId);
 }
 
 MbeRecipients::AppendItemStatus ConvRecipientsPanel::appendItem(const std::string &address,