TizenRefApp-5419 Implement controller-layer(search in thread) 92/56792/2
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 12 Jan 2016 15:28:28 +0000 (17:28 +0200)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 12 Jan 2016 16:46:52 +0000 (18:46 +0200)
Change-Id: Ibb5e09aed935654bc9b11b0090b46ca694f7a754
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
25 files changed:
src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp
src/Common/Utils/src/TextDecorator.cpp
src/Common/View/inc/DefaultLayout.h
src/Common/View/inc/ListItem.h
src/Common/View/inc/View.h
src/Common/View/src/DefaultLayout.cpp
src/Conversation/ConvList/Controller/inc/ConvList.h
src/Conversation/ConvList/Controller/inc/ConvListItem.h
src/Conversation/ConvList/Controller/src/ConvList.cpp
src/Conversation/ConvList/Controller/src/ConvListItem.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/Conversation/Recipients/Controller/inc/RecipientsPanel.h
src/MsgThread/Controller/inc/BaseThreadListItem.h [new file with mode: 0644]
src/MsgThread/Controller/inc/MsgSearchListItem.h [new file with mode: 0644]
src/MsgThread/Controller/inc/MsgThread.h
src/MsgThread/Controller/inc/ThreadListItem.h
src/MsgThread/Controller/inc/ThreadSearchList.h
src/MsgThread/Controller/inc/ThreadSearchListItem.h
src/MsgThread/Controller/src/BaseThreadListItem.cpp [new file with mode: 0644]
src/MsgThread/Controller/src/MsgSearchListItem.cpp [new file with mode: 0644]
src/MsgThread/Controller/src/MsgThread.cpp
src/MsgThread/Controller/src/ThreadListItem.cpp
src/MsgThread/Controller/src/ThreadSearchList.cpp
src/MsgThread/Controller/src/ThreadSearchListItem.cpp

index 877f67f..ab277c2 100644 (file)
@@ -229,10 +229,10 @@ MsgConversationListRef MsgStoragePrivate::getConversationList(ThreadId id)
 MessageRef MsgStoragePrivate::getMessage(MsgId id)
 {
     MessageRef msgRef;
-    msg_struct_t msg = nullptr;
-
+    msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
     msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
-    if(msg_get_message(m_ServiceHandle, (msg_message_id_t)id, msg, sendOpt) == 0)
+
+    if(msg_get_message(m_ServiceHandle, id, msg, sendOpt) == 0)
     {
         int msgType = MSG_TYPE_INVALID;
         msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &msgType);
@@ -252,6 +252,10 @@ MessageRef MsgStoragePrivate::getMessage(MsgId id)
                 MSG_ASSERT(false, "Unsupported message type");
         }
     }
+    else
+    {
+        msg_release_struct(&msg);
+    }
     msg_release_struct(&sendOpt);
     return msgRef;
 }
index ded0d22..a761309 100644 (file)
@@ -142,7 +142,7 @@ std::string TextDecorator::highlightKeyword(const std::string &str, const std::s
 
     res += firstPart;
     res += "<match>";
-    res += searchWord;
+    res += std::string(found, searchWord.length());
     res += "</match>";
     res += lastPart;
 
index 51543ec..ecf86b8 100644 (file)
@@ -32,6 +32,9 @@ namespace Msg
             void setContent(Evas_Object *obj);
             void setBg(Evas_Object *obj);
             void setFloatingButton(Evas_Object *obj);
+            void showFloatingButton(bool show);
+        private:
+            Evas_Object *m_pFloatingBtn;
     };
 
 }
index 028582b..634a0f6 100644 (file)
@@ -72,7 +72,7 @@ namespace Msg
             void setSelected(bool selected);
             bool getSelected() const;
             void setExpanded(bool expand);
-            virtual void update();
+            void update();
             void updateFields(const char *parts, Elm_Genlist_Item_Field_Type type);;
             ListView *getOwner() const;
             Elm_Genlist_Item_Type getType() const;
index da1c3f6..7871ba2 100644 (file)
@@ -47,6 +47,7 @@ namespace Msg
             inline void setSizeHintMin(Evas_Coord w, Evas_Coord h);
             inline void setSizeHintMax(Evas_Coord w, Evas_Coord h);
             Evas_Object *setContent(Evas_Object *content, const char *part = nullptr, bool saveOldContent = false);
+            inline Evas_Object *unsetContent(const char *part = nullptr);
             inline Evas_Object* getContent(const char *part = nullptr) const;
             inline void setFocusAllow(bool enable);
             inline bool getFocusAllow() const;
@@ -280,6 +281,11 @@ namespace Msg
     {
         evas_object_event_callback_add(m_pEo, type, func, data);
     }
+
+    inline Evas_Object *View::unsetContent(const char *part)
+    {
+        return elm_object_part_content_unset(m_pEo, part);
+    }
 }
 
 #endif /* View_h_ */
index fbb6c9a..ec3810c 100644 (file)
 
 using namespace Msg;
 
+namespace
+{
+    const char *floatingPart = "elm.swallow.floatingbutton";
+}
+
 DefaultLayout::DefaultLayout(Evas_Object *parent)
+    : m_pFloatingBtn(nullptr)
 {
     setEo(elm_layout_add(parent));
     elm_layout_theme_set(getEo(), "layout", "application", "default");
@@ -42,6 +48,21 @@ void DefaultLayout::setBg(Evas_Object *obj)
 
 void DefaultLayout::setFloatingButton(Evas_Object *obj)
 {
-    elm_object_part_content_set(getEo(), "elm.swallow.floatingbutton", obj);
+    m_pFloatingBtn = obj;
+    elm_object_part_content_set(getEo(), floatingPart, obj);
+}
+
+void DefaultLayout::showFloatingButton(bool show)
+{
+    if(show)
+    {
+        View::setContent(m_pFloatingBtn, floatingPart, true);
+        evas_object_show(m_pFloatingBtn);
+    }
+    else
+    {
+        View::unsetContent(floatingPart);
+        evas_object_hide(m_pFloatingBtn);
+    }
 }
 
index cec42ca..7f1641b 100644 (file)
@@ -25,6 +25,8 @@
 
 namespace Msg
 {
+    class ConvListItem;
+
     class ConvList
         : public ConvListLayout
         , private IMsgStorageListener
@@ -66,6 +68,12 @@ namespace Msg
              */
             void setThreadId(ThreadId id);
 
+            /**
+             * @brief Navigate to mesage
+             * @param[in] msgId message id to navigate
+             */
+            void navigateTo(MsgId msgId);
+
         private:
             void create(Evas_Object *parent);
             Evas_Object *createSelectAll(Evas_Object *parent);
@@ -73,6 +81,7 @@ namespace Msg
             void fill();
             void selectListItems(bool state);
             bool isAllListItemSelected() const;
+            ConvListItem *getItem(MsgId msgId) const;
 
             // IListViewListener:
             virtual void onListItemSelected(ListItem &listItem, void *funcData);
index 8331c9b..2ec06ee 100644 (file)
@@ -37,6 +37,8 @@ namespace Msg
             ConvListItem(MsgConversationItem &item);
             virtual ~ConvListItem();
 
+            MsgId getMsgId() const;
+
         protected:
             virtual Evas_Object *getBubble();
             virtual std::string getText();
index 616b97f..9bd2014 100644 (file)
@@ -113,6 +113,24 @@ void ConvList::setThreadId(ThreadId id)
     fill();
 }
 
+void ConvList::navigateTo(MsgId msgId)
+{
+    ConvListItem *item = getItem(msgId);
+    if(item)
+        m_pList->showItem(*item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
+}
+
+ConvListItem *ConvList::getItem(MsgId msgId) const
+{
+    auto items = m_pList->getItems<ConvListItem>();
+    for(ConvListItem *item : items)
+    {
+        if(item->getMsgId() == msgId)
+            return item;
+    }
+    return nullptr;
+}
+
 bool ConvList::isAllListItemSelected() const
 {
     // Simple but not fast impl:
index c9b5d1a..3a50750 100644 (file)
@@ -51,3 +51,8 @@ std::string ConvListItem::getTime()
     //TODO: convert time_t to string
     return "10:23 PM";
 }
+
+MsgId ConvListItem::getMsgId() const
+{
+    return m_MsgId;
+}
index 7e4f967..f6e4245 100644 (file)
@@ -51,6 +51,8 @@ namespace Msg
             Conversation(NaviFrameController &parent, ThreadId threadId);
             virtual ~Conversation();
 
+            void navigateTo(MsgId msgId);
+
         private:
             enum Mode
             {
index a3510ec..5b3dffa 100644 (file)
@@ -93,6 +93,11 @@ void Conversation::create()
     setHwButtonListener(*m_pLayout, this);
 }
 
+void Conversation::navigateTo(MsgId msgId)
+{
+    m_pConvList->navigateTo(msgId);
+}
+
 void Conversation::setMode(Mode mode)
 {
     if(m_Mode == mode)
index 72353e9..405d4db 100644 (file)
@@ -33,7 +33,7 @@ namespace Msg
 
     class RecipientsPanel
         : public RecipientsPanelView,
-          public IContactPickerListener
+          private IContactPickerListener
     {
         public:
             RecipientsPanel(Evas_Object *parent, App &app);
diff --git a/src/MsgThread/Controller/inc/BaseThreadListItem.h b/src/MsgThread/Controller/inc/BaseThreadListItem.h
new file mode 100644 (file)
index 0000000..07b6e86
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 BaseThreadListItem_h_
+#define BaseThreadListItem_h_
+
+#include "ThreadListViewItem.h"
+#include "ThumbnailMaker.h"
+#include "MsgThreadItem.h"
+#include "MsgAddress.h"
+#include "App.h"
+
+#include <time.h>
+
+namespace Msg
+{
+    class BaseThreadListItem
+        : public ThreadListViewItem
+    {
+        public:
+            BaseThreadListItem(App &app);
+            virtual ~BaseThreadListItem();
+
+        protected:
+            void updateThumbnail(const MsgAddress &addr);
+            void updateThumbnail(const MsgAddressList &addressList);
+            void updateThumbnail(const MsgThreadItem &threadItem);
+            void updateTime(time_t time);
+
+            // ThreadListViewItem:
+            virtual std::string getName();
+            virtual std::string getMessage();
+            virtual std::string getTime();
+            virtual Evas_Object *getThumbnail();
+
+            App &m_App;
+            ThumbnailMaker::Type m_ThumbType;
+            std::string m_ThumbPath;
+            std::string m_Name;
+            std::string m_Message;
+            std::string m_Time;
+    };
+}
+
+#endif // BaseThreadListItem_h_
diff --git a/src/MsgThread/Controller/inc/MsgSearchListItem.h b/src/MsgThread/Controller/inc/MsgSearchListItem.h
new file mode 100644 (file)
index 0000000..1eb4b3d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 MsgSearchListItem_h_
+#define MsgSearchListItem_h_
+
+#include "BaseThreadListItem.h"
+#include "Message.h"
+
+namespace Msg
+{
+    class MsgSearchListItem
+        : public BaseThreadListItem
+    {
+        public:
+            MsgSearchListItem(App &app, const Message &msg, const std::string &searchWord);
+            virtual ~MsgSearchListItem();
+
+            MsgId getMsgId() const;
+
+        private:
+            void update(const Message &msg, const std::string &searchWord);
+            void updateThumbnail(const Message &msg);
+
+
+        private:
+            MsgId m_MsgId;
+    };
+}
+
+#endif // MsgSearchListItem_h_
index a20287c..8cb0cd4 100644 (file)
@@ -79,6 +79,8 @@ namespace Msg
 
             // ThreadSearchList:
             virtual void onSearchListChanged();
+            virtual void onSearchListItemSelected(ThreadId id);
+            virtual void onSearchListItemSelected(MsgId id);
 
         private:
             enum Mode
@@ -93,7 +95,7 @@ namespace Msg
             // MsgThread:
             void composeNewMessage();
             void navigateToSettings();
-            void navigateToConversation(ThreadId threadId);
+            void navigateToConversation(ThreadId threadId, MsgId msgId = MsgId());
             void showMainCtxPopup();
             void setMode(Mode mode);
             void setDeleteMode(bool value);
index 2099169..ef09102 100644 (file)
@@ -18,8 +18,7 @@
 #ifndef ThreadListItem_h_
 #define ThreadListItem_h_
 
-#include "ThreadListViewItem.h"
-#include "ViewItemController.h"
+#include "BaseThreadListItem.h"
 #include "MsgThreadItem.h"
 #include "ThumbnailMaker.h"
 #include "ContactPersonNumber.h"
@@ -29,7 +28,7 @@
 namespace Msg
 {
     class ThreadListItem
-        : public ThreadListViewItem
+        : public BaseThreadListItem
     {
         public:
             ThreadListItem(const MsgThreadItem &threadItem, App &app);
@@ -37,27 +36,16 @@ namespace Msg
 
             ThreadId getThreadId() const;
             void updateModel(const MsgThreadItem &threadItem);
-            void updateThumbnail(const MsgThreadItem &threadItem);
 
         private:
             // ThreadListViewItem:
-            virtual std::string getName();
-            virtual std::string getMessage();
-            virtual std::string getTime();
             virtual std::string getStatus();
-            virtual Evas_Object *getThumbnail();
             virtual Evas_Object *getIcon();
 
             Evas_Object *makeUnreadBadge(int unreadCount);
 
         private:
             ThreadId m_ThreadId;
-            App &m_App;
-            ThumbnailMaker::Type m_ThumbType;
-            std::string m_ThumbPath;
-            std::string m_Name;
-            std::string m_Message;
-            std::string m_Time;
             std::string m_Status;
     };
 }
index b53ee86..ebf0453 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "ListView.h"
 #include "App.h"
+#include "MsgTypes.h"
 
 #include <Ecore.h>
 
@@ -29,6 +30,7 @@ namespace Msg
 
     class ThreadSearchList
         : public ListView
+        , private IListViewListener
     {
         public:
             ThreadSearchList(Evas_Object *parent, App &app);
@@ -37,8 +39,12 @@ namespace Msg
             void setListener(IThreadSearchListListener *l);
             void requestSearch(const std::string &searchWord);
             void cancelSearch();
+            const std::string &getSearchWord() const;
 
         private:
+            // IListViewListener:
+            virtual void onListItemSelected(ListItem &listItem, void *funcData);
+
             void search();
 
         private:
@@ -53,6 +59,8 @@ namespace Msg
         public:
             virtual ~IThreadSearchListListener() {}
             virtual void onSearchListChanged() {};
+            virtual void onSearchListItemSelected(ThreadId id) {};
+            virtual void onSearchListItemSelected(MsgId id) {};
     };
 }
 
index c01a1d0..91dd050 100644 (file)
 #ifndef ThreadSearchListItem_h_
 #define ThreadSearchListItem_h_
 
-#include "ThreadListViewItem.h"
-#include "ThumbnailMaker.h"
-#include "App.h"
-#include "Message.h"
+#include "BaseThreadListItem.h"
+#include "MsgThreadItem.h"
 #include "MsgTypes.h"
 
 namespace Msg
 {
     class ThreadSearchListItem
-        : public ThreadListViewItem
+        : public BaseThreadListItem
     {
         public:
-            ThreadSearchListItem(const Message &msg, App &app, const std::string &searchWord);
+            ThreadSearchListItem(App &app, const MsgThreadItem &item, const std::string &searchWord);
             virtual ~ThreadSearchListItem();
 
-            MsgId getMsgId() const;
+            ThreadId getThreadId() const;
 
         private:
-            void updateModel(const Message &msg, const std::string &searchWord);
-            void updateThumbnail(const Message &msg);
-
-            // ThreadListViewItem:
-            virtual std::string getName();
-            virtual std::string getMessage();
-            virtual std::string getTime();
-            virtual Evas_Object *getThumbnail();
-
-            Evas_Object *makeUnreadBadge(int unreadCount);
+            void update(const MsgThreadItem &item, const std::string &searchWord);
 
         private:
-            MsgId m_MsgId;
-            App &m_App;
-            ThumbnailMaker::Type m_ThumbType;
-            std::string m_ThumbPath;
-            std::string m_Name;
-            std::string m_Message;
-            std::string m_Time;
+            ThreadId m_ThreadId;
     };
 }
 
diff --git a/src/MsgThread/Controller/src/BaseThreadListItem.cpp b/src/MsgThread/Controller/src/BaseThreadListItem.cpp
new file mode 100644 (file)
index 0000000..18fc56f
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "BaseThreadListItem.h"
+#include "ContactManager.h"
+#include "Resource.h"
+#include "ListView.h"
+
+using namespace Msg;
+
+BaseThreadListItem::BaseThreadListItem(App &app)
+    : m_App(app)
+    , m_ThumbType(ThumbnailMaker::UserType)
+{
+
+}
+
+BaseThreadListItem::~BaseThreadListItem()
+{
+
+}
+
+void BaseThreadListItem::updateThumbnail(const MsgThreadItem &threadItem)
+{
+    const MsgAddressListRef addressList = m_App.getMsgEngine().getStorage().getAddressList(threadItem.getId());
+    if(addressList)
+        updateThumbnail(*addressList);
+}
+
+void BaseThreadListItem::updateThumbnail(const MsgAddressList &addressList)
+{
+    int countContact = addressList.getLength();
+    m_ThumbType = ThumbnailMaker::MsgType;
+    if(countContact > 1)
+    {
+        m_ThumbPath = PathUtils::getResourcePath(THUMB_GROUP_IMG_PATH);
+    }
+    else if(countContact == 1)
+    {
+        const MsgAddress &addr = addressList[0];
+        updateThumbnail(addr);
+    }
+}
+
+void BaseThreadListItem::updateThumbnail(const MsgAddress &addr)
+{
+    ContactPersonNumber contactNumber = m_App.getContactManager().getContactPersonNumber(addr.getAddress());
+    const char *thumbPath = contactNumber.isValid() ? contactNumber.getThumbnailPath() : nullptr;
+    if(thumbPath)
+    {
+        m_ThumbPath.assign(thumbPath);
+        m_ThumbType = ThumbnailMaker::UserType;
+    }
+    else
+    {
+        m_ThumbPath = PathUtils::getResourcePath(THUMB_CONTACT_IMG_PATH);
+    }
+    contactNumber.release();
+}
+
+void BaseThreadListItem::updateTime(time_t time)
+{
+    m_Time = std::string("7:40"); // TODO: remove hardcode
+}
+
+std::string BaseThreadListItem::getName()
+{
+    return m_Name;
+}
+
+std::string BaseThreadListItem::getMessage()
+{
+    return m_Message;
+}
+
+std::string BaseThreadListItem::getTime()
+{
+    return m_Time;
+}
+
+Evas_Object *BaseThreadListItem::getThumbnail()
+{
+    return ThumbnailMaker::make(*getOwner(), m_ThumbType, m_ThumbPath);
+}
diff --git a/src/MsgThread/Controller/src/MsgSearchListItem.cpp b/src/MsgThread/Controller/src/MsgSearchListItem.cpp
new file mode 100644 (file)
index 0000000..af3b5f4
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "MsgSearchListItem.h"
+#include "MsgEngine.h"
+#include "TextDecorator.h"
+
+using namespace Msg;
+
+MsgSearchListItem::MsgSearchListItem(App &app, const Message &msg, const std::string &searchWord)
+    : BaseThreadListItem(app)
+    , m_MsgId(msg.getId())
+{
+    setState(NormalState, false);
+    update(msg, searchWord);
+}
+
+MsgSearchListItem::~MsgSearchListItem()
+{
+}
+
+MsgId MsgSearchListItem::getMsgId() const
+{
+    return m_MsgId;
+}
+
+void MsgSearchListItem::updateThumbnail(const Message &msg)
+{
+    const MsgAddressList &addressList = msg.getAddressList();
+    BaseThreadListItem::updateThumbnail(addressList);
+}
+
+void MsgSearchListItem::update(const Message &msg, const std::string &searchWord)
+{
+    m_MsgId = msg.getId();
+    m_Message = TextDecorator::highlightKeyword(msg.getText(), searchWord);
+
+    const MsgAddressList &addressList = msg.getAddressList();
+    int addrCount = addressList.getLength();
+    if(addrCount > 0)
+    {
+        m_Name = addressList.at(0).getAddress();
+        if(addrCount > 1)
+            m_Name += " + " + std::to_string(addrCount - 1);
+    }
+
+    updateThumbnail(msg);
+}
index 1f86b6e..9f2cdb0 100644 (file)
@@ -106,10 +106,12 @@ void MsgThread::navigateToSettings()
     getParent().push(*frame);
 }
 
-void MsgThread::navigateToConversation(ThreadId threadId)
+void MsgThread::navigateToConversation(ThreadId threadId, MsgId msgId)
 {
     Conversation *frame = new Conversation(getParent(), threadId);
     getParent().push(*frame);
+    if(msgId.isValid())
+        frame->navigateTo(msgId);
 }
 
 void MsgThread::setMode(Mode mode)
@@ -199,15 +201,19 @@ void MsgThread::setSearchMode(bool value)
 
 void MsgThread::update()
 {
-    if(m_Mode == SearchMode)
+    bool searchEnabled = m_Mode == SearchMode;
+
+    m_pLayout->showFloatingButton(!searchEnabled);
+    if(searchEnabled)
     {
         bool showSearch = !m_pSearchList->isEmpty();
-        bool showThread = !showSearch && !m_pThreadList->isEmpty();
-        bool showNoContent = !showThread;
+        bool showThread = !showSearch && !m_pThreadList->isEmpty() && m_pSearchList->getSearchWord().empty();
+        bool showNoContent = !showThread && !showSearch;
 
         m_pLayout->showSearchList(showSearch);
         m_pLayout->showThreadList(showThread);
         m_pLayout->showNoContent(showNoContent);
+
     }
     else
     {
@@ -285,6 +291,20 @@ void MsgThread::onSearchListChanged()
     update();
 }
 
+void MsgThread::onSearchListItemSelected(ThreadId id)
+{
+    MSG_LOG("");
+    navigateToConversation(id);
+}
+
+void MsgThread::onSearchListItemSelected(MsgId id)
+{
+    MSG_LOG("");
+    MessageRef msg = getMsgEngine().getStorage().getMessage(id);
+    if(msg)
+        navigateToConversation(msg->getThreadId(), id);
+}
+
 void MsgThread::onFloatingButtonPressed()
 {
     MSG_LOG("");
index 8790238..5bdb7fe 100644 (file)
 using namespace Msg;
 
 ThreadListItem::ThreadListItem(const MsgThreadItem &threadItem, App &app)
-    : ThreadListViewItem()
+    : BaseThreadListItem(app)
     , m_ThreadId()
-    , m_App(app)
-    , m_ThumbType(ThumbnailMaker::MsgType)
 {
     updateModel(threadItem);
 }
@@ -47,58 +45,6 @@ ThreadId ThreadListItem::getThreadId() const
     return m_ThreadId;
 }
 
-std::string ThreadListItem::getName()
-{
-    return m_Name;
-}
-
-std::string ThreadListItem::getMessage()
-{
-    return m_Message;
-}
-
-Evas_Object *ThreadListItem::getThumbnail()
-{
-    return ThumbnailMaker::make(*getOwner(), m_ThumbType, m_ThumbPath);
-}
-
-void ThreadListItem::updateThumbnail(const MsgThreadItem &threadItem)
-{
-    const MsgAddressListRef addressList = m_App.getMsgEngine().getStorage().getAddressList(threadItem.getId());
-
-    if(addressList)
-    {
-        int countContact = addressList->getLength();
-        m_ThumbType = ThumbnailMaker::MsgType;
-        if(countContact > 1)
-        {
-            m_ThumbPath = PathUtils::getResourcePath(THUMB_GROUP_IMG_PATH);
-        }
-        else if(countContact == 1)
-        {
-            const MsgAddress &addr = addressList->at(0);
-            ContactPersonNumber contactNumber = m_App.getContactManager().getContactPersonNumber(addr.getAddress());
-            const char *thumbPath = contactNumber.isValid() ? contactNumber.getThumbnailPath() : nullptr;
-            if(thumbPath)
-            {
-                m_ThumbPath.assign(thumbPath);
-                m_ThumbType = ThumbnailMaker::UserType;
-            }
-            else
-            {
-                m_ThumbPath = PathUtils::getResourcePath(THUMB_CONTACT_IMG_PATH);
-            }
-            contactNumber.release();
-        }
-    }
-}
-
-std::string ThreadListItem::getTime()
-{
-    //m_MsgThreadItem.getTime();
-    return std::string("7:40"); // TODO: remove hardcode
-}
-
 std::string ThreadListItem::getStatus()
 {
     return m_Status;
index dd558d8..16cef99 100644 (file)
  */
 
 #include "ThreadSearchList.h"
+#include "MsgSearchListItem.h"
 #include "ThreadSearchListItem.h"
-#include "MessageSMS.h"
 #include "MsgEngine.h"
+#include "Logger.h"
 
 using namespace Msg;
 
@@ -30,6 +31,7 @@ ThreadSearchList::ThreadSearchList(Evas_Object *parent, App &app)
 {
     setMultiSelection(false);
     setMode(ELM_LIST_COMPRESS);
+    ListView::setListener(this);
 }
 
 ThreadSearchList::~ThreadSearchList()
@@ -70,20 +72,56 @@ void ThreadSearchList::cancelSearch()
     }
 }
 
+const std::string &ThreadSearchList::getSearchWord() const
+{
+    return m_SearchWord;
+}
+
 void ThreadSearchList::search()
 {
+    MSG_LOG("Search word: ", m_SearchWord);
     ListView::clear();
-    // TODO: pull from model:
 
-    // TODO: only for demo will be removed
-    MessageSMSRef sms = m_App.getMsgEngine().getComposer().createSms();
-    sms->setText("Hello world!!!");
-    auto &addr = sms->addAddress();
-    addr.setAddress("5555512335555");
-    ThreadSearchListItem *item = new ThreadSearchListItem(*sms, m_App, m_SearchWord);
-    ListView::appendItem(*item);
+    if(!m_SearchWord.empty())
+    {
+        MsgStorage &msgSotrage = m_App.getMsgEngine().getStorage();
+
+        // Thread:
+        MsgThreadListRef threadList = msgSotrage.searchThread(m_SearchWord);
+        if(threadList)
+        {
+            int length = threadList->getLength();
+            for(int i = 0; i < length; ++i)
+            {
+                const MsgThreadItem &threadItem = threadList->at(i);
+                ListView::appendItem(*new ThreadSearchListItem(m_App, threadItem, m_SearchWord));
+            }
+        }
+
+        // Message:
+        MessageListRef msgList = msgSotrage.searchMessage(m_SearchWord);
+        if(msgList)
+        {
+            int length = msgList->getLength();
+            for(int i = 0; i < length; ++i)
+            {
+                const Message &msg = msgList->at(i);
+                ListView::appendItem(*new MsgSearchListItem(m_App, msg, m_SearchWord));
+            }
+        }
+    }
 
     if(m_pListener)
         m_pListener->onSearchListChanged();
 }
 
+void ThreadSearchList::onListItemSelected(ListItem &listItem, void *funcData)
+{
+    if(m_pListener)
+    {
+        if(auto it = dynamic_cast<MsgSearchListItem*>(&listItem))
+            m_pListener->onSearchListItemSelected(it->getMsgId());
+        else if(auto it = dynamic_cast<ThreadSearchListItem*>(&listItem))
+            m_pListener->onSearchListItemSelected(it->getThreadId());
+    }
+}
index 1cfdf60..4e0061e 100644 (file)
  */
 
 #include "ThreadSearchListItem.h"
-#include "ListView.h"
-#include "Logger.h"
-#include "PathUtils.h"
-#include "MsgEngine.h"
-#include "LangUtils.h"
-#include "ContactManager.h"
 #include "TextDecorator.h"
 
 using namespace Msg;
 
-ThreadSearchListItem::ThreadSearchListItem(const Message &msg, App &app, const std::string &searchWord)
-    : m_MsgId(msg.getId())
-    , m_App(app)
-    , m_ThumbType(ThumbnailMaker::MsgType)
+ThreadSearchListItem::ThreadSearchListItem(App &app, const MsgThreadItem &item, const std::string &searchWord)
+    : BaseThreadListItem(app)
 {
-    setState(NormalState, false);
-    updateModel(msg, searchWord);
+    update(item, searchWord);
 }
 
 ThreadSearchListItem::~ThreadSearchListItem()
 {
-}
-
-MsgId ThreadSearchListItem::getMsgId() const
-{
-    return m_MsgId;
-}
 
-std::string ThreadSearchListItem::getName()
-{
-    return m_Name;
 }
 
-std::string ThreadSearchListItem::getMessage()
+ThreadId ThreadSearchListItem::getThreadId() const
 {
-    return m_Message;
+    return m_ThreadId;
 }
 
-Evas_Object *ThreadSearchListItem::getThumbnail()
+void ThreadSearchListItem::update(const MsgThreadItem &item, const std::string &searchWord)
 {
-    return ThumbnailMaker::make(*getOwner(), m_ThumbType, m_ThumbPath);
+    m_ThreadId = item.getId();
+    m_Name = TextDecorator::highlightKeyword(item.getName(), searchWord);
+    m_Message = item.getLastMessage();
+    updateThumbnail(item);
 }
-
-void ThreadSearchListItem::updateThumbnail(const Message &msg)
-{
-    const MsgAddressList &addressList = msg.getAddressList();
-    int countContact = addressList.getLength();
-    m_ThumbType = ThumbnailMaker::MsgType;
-
-    if(countContact > 1)
-    {
-        m_ThumbPath = PathUtils::getResourcePath(THUMB_GROUP_IMG_PATH);
-    }
-    else if(countContact == 1)
-    {
-        const MsgAddress &addr = addressList.at(0);
-        ContactPersonNumber contactNumber = m_App.getContactManager().getContactPersonNumber(addr.getAddress());
-        const char *thumbPath = contactNumber.isValid() ? contactNumber.getThumbnailPath() : nullptr;
-        if(thumbPath)
-        {
-            m_ThumbPath.assign(thumbPath);
-            m_ThumbType = ThumbnailMaker::UserType;
-        }
-        else
-        {
-            m_ThumbPath = PathUtils::getResourcePath(THUMB_CONTACT_IMG_PATH);
-        }
-        contactNumber.release();
-    }
-}
-
-std::string ThreadSearchListItem::getTime()
-{
-    //m_MsgThreadItem.getTime();
-    return std::string("7:40"); // TODO: remove hardcode
-}
-
-Evas_Object *ThreadSearchListItem::makeUnreadBadge(int unreadCount)
-{
-    Evas_Object *label = makeUnreadIcon(*getOwner() ,std::to_string(unreadCount));
-    return label;
-}
-
-void ThreadSearchListItem::updateModel(const Message &msg, const std::string &searchWord)
-{
-    m_MsgId = msg.getId();
-    m_Message = TextDecorator::highlightKeyword(msg.getText(), searchWord);
-
-    const MsgAddressList &addressList = msg.getAddressList();
-    int addrCount = addressList.getLength();
-    if(addrCount > 0)
-    {
-        m_Name = TextDecorator::highlightKeyword(addressList.at(0).getAddress(), searchWord);
-        if(addrCount > 1)
-            m_Name += " + " + std::to_string(addrCount - 1);
-    }
-
-    updateThumbnail(msg);
-}
-