TizenRefApp-8240 Implement ConvTitleListItem class 70/121270/4
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 27 Mar 2017 10:50:17 +0000 (13:50 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 27 Mar 2017 12:59:40 +0000 (15:59 +0300)
Update TextDecorator class.

Change-Id: I4d25fe0b7e0a101cab65582a960d249316a39667
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
res/edje/conv_genlist_theme.edc
src/Common/Utils/inc/TextDecorator.h
src/Common/Utils/src/TextDecorator.cpp
src/Common/View/inc/View.h
src/Conversation/Controller/inc/ConvList.h
src/Conversation/Controller/src/ConvList.cpp
src/Conversation/View/inc/ConvTitleListItem.h [new file with mode: 0644]
src/Conversation/View/src/ConvTitleListItem.cpp [new file with mode: 0644]

index 060ae19037a5fad09236218e69e6de98fb417e00..d72369c332a2ae8bd23b7f88086b339fb82d65d9 100644 (file)
@@ -572,7 +572,26 @@ collections {
       }
    }
 
-   group { name: "elm/genlist/item/1lineitem/default";
+   group {
+      name: "elm/genlist/item/conv_title/default";
+      data.item: "contents" "swl.content";
+      parts{
+         PADDING_TOP("pad.top", 37);
+         PADDING_BOTTOM("pad.bottom", 7);
+         swallow { "swl.content"; scale; nomouse;
+            desc { "default";
+               align: 0.5 1.0;
+               min: 0 39;
+               max: 240 39;
+               rel1 { relative : 0.0 1.0; to_y: "pad.top"; }
+               rel2 { relative : 1.0 0.0; to_y: "pad.bottom"; }
+            }
+         }
+      }
+   }
+
+   group {
+      name: "elm/genlist/item/1lineitem/default";
       inherit: "elm/genlist/item/dateline/default";
       parts {
          spacer { "pad.top"; scale; nomouse;
index 7f140ea080228b9ec14e80e666be86db6c98090d..7d60cebe6c621b3ec7590b9dcfd7c744653e8f6f 100644 (file)
 #include <string>
 
 namespace Msg {
-    enum class TextAlign {
-        None,
-        Left,
-        Center,
-        Right
-    };
-
     class TextStyle {
         public:
+            enum class Align {
+                None,
+                Left,
+                Center,
+                Right
+            };
+
+            enum class Weight {
+                None,
+                Bold
+            };
+
             static const char *defaultColor;
             static const char *whiteColor;
             static const int defaultFontSize;
 
         public:
             TextStyle();
-            TextStyle(int size, const std::string &color, TextAlign align = TextAlign::None);
+            TextStyle(int size, const std::string &color, Align align = Align::None);
             ~TextStyle();
 
-            void setColor(const std::string &color);
-            void setSize(int size);
-            void setAlign(TextAlign align);
+            TextStyle &setColor(const std::string &color);
+            TextStyle &setSize(int size);
+            TextStyle &setAlign(Align align);
+            TextStyle &setWeight(Weight weight);
 
             const std::string &getColor() const;
             int getSize() const;
-            TextAlign getAlign() const;
+            Align getAlign() const;
+            Weight getWeight() const;
 
         private:
+            Weight m_Weight;
             std::string m_Color;
-            TextAlign m_Align;
+            Align m_Align;
             int m_Size;
     };
 
@@ -61,7 +69,8 @@ namespace Msg {
         std::string make(const std::string &text,
                                 int size = TextStyle::defaultFontSize,
                                 const std::string &color = TextStyle::defaultColor,
-                                TextAlign align = TextAlign::None);
+                                TextStyle::Align align = TextStyle::Align::None,
+                                TextStyle::Weight weight = TextStyle::Weight::None);
         std::string makePlainText(const std::string &text);
 
         /**
index 02e103e2dc7c6c747b92afb5328feaeeb7886c32..83ef0e770d0a8981c7429bc9b52aa73b9d065b34 100644 (file)
@@ -32,17 +32,32 @@ const int TextStyle::defaultFontSize = 28;
 
 namespace
 {
-    const char *alignAsString(TextAlign align)
+    const char *alignAsString(TextStyle::Align align)
     {
         switch (align)
         {
-            case TextAlign::Center:
+            case TextStyle::Align::Center:
                 return "center";
-            case TextAlign::Left:
+            case TextStyle::Align::Left:
                 return "left";
-            case TextAlign::Right:
+            case TextStyle::Align::Right:
                 return "right";
-            case TextAlign::None:
+            case TextStyle::Align::None:
+            default:
+                break;
+        }
+
+        assert(false);
+        return "";
+    }
+
+    const char *weightAsString(TextStyle::Weight wight)
+    {
+        switch (wight)
+        {
+            case TextStyle::Weight::Bold:
+                return "bold";
+            case TextStyle::Weight::None:
             default:
                 break;
         }
@@ -53,14 +68,16 @@ namespace
 }
 
 TextStyle::TextStyle()
-    : m_Color(defaultColor)
-    , m_Align(TextAlign::None)
+    : m_Weight(Weight::None)
+    , m_Color(defaultColor)
+    , m_Align(Align::None)
     , m_Size(defaultFontSize)
 {
 }
 
-TextStyle::TextStyle(int size, const std::string &color, TextAlign align)
-    : m_Color(color)
+TextStyle::TextStyle(int size, const std::string &color, Align align)
+    : m_Weight(Weight::None)
+    , m_Color(color)
     , m_Align(align)
     , m_Size(size)
 {
@@ -70,19 +87,28 @@ TextStyle::~TextStyle()
 {
 }
 
-void TextStyle::setColor(const std::string &color)
+TextStyle &TextStyle::setColor(const std::string &color)
 {
     m_Color = color;
+    return *this;
 }
 
-void TextStyle::setSize(int size)
+TextStyle &TextStyle::setSize(int size)
 {
     m_Size = size;
+    return *this;
 }
 
-void TextStyle::setAlign(TextAlign align)
+TextStyle &TextStyle::setAlign(Align align)
 {
     m_Align = align;
+    return *this;
+}
+
+TextStyle &TextStyle::setWeight(Weight weight)
+{
+    m_Weight = weight;
+    return *this;
 }
 
 const std::string &TextStyle::getColor() const
@@ -95,17 +121,22 @@ int TextStyle::getSize() const
     return m_Size;
 }
 
-TextAlign TextStyle::getAlign() const
+TextStyle::Align TextStyle::getAlign() const
 {
     return m_Align;
 }
 
+TextStyle::Weight TextStyle::getWeight() const
+{
+    return m_Weight;
+}
+
 namespace Msg {
 namespace TextDecorator {
 
 std::string make(const std::string &text, const TextStyle &style)
 {
-    return make(text, style.getSize(), style.getColor(), style.getAlign());
+    return make(text, style.getSize(), style.getColor(), style.getAlign(), style.getWeight());
 }
 
 std::string make(const std::string &text, const std::string &color)
@@ -117,20 +148,30 @@ std::string make(const std::string &text, const std::string &color)
 std::string make(const std::string &text,
                                 int size,
                                 const std::string &color,
-                                TextAlign align)
+                                TextStyle::Align align,
+                                TextStyle::Weight weight)
 {
     std::ostringstream ss;
-    ss << OPEN_TAG("font_size", size) << OPEN_TAG("color", color);
-    if (align != TextAlign::None)
-    {
+    bool isAlign = align != TextStyle::Align::None;
+    bool isWeight = weight != TextStyle::Weight::None;
+
+    ss << OPEN_TAG("font_size", size);
+    ss << OPEN_TAG("color", color);
+
+    if (isAlign)
         ss << OPEN_TAG("align", alignAsString(align));
-    }
+
+    if (isWeight)
+        ss << OPEN_TAG("font_weight", weightAsString(weight));
+
     ss << text;
-    if (align != TextAlign::None)
-    {
+    if (isAlign)
         ss << CLOSE_TAG("align");
-    }
-    ss << CLOSE_TAG("color") << CLOSE_TAG("font_size");
+    if (isWeight)
+        ss << CLOSE_TAG("font_weight");
+
+    ss << CLOSE_TAG("color");
+    ss << CLOSE_TAG("font_size");
     return ss.str();
 }
 
index 86c7f11b5d806237ef171da292e86c7e1542989b..9d3ed31093af38dedf464fddef537cd7d9190d3f 100644 (file)
@@ -471,7 +471,7 @@ namespace Msg
 
     inline void View::setText(Evas_Object *obj, const std::string &text, const char *part)
     {
-        setText(obj, part, text.c_str());
+        setText(obj, text.c_str(), part);
     }
 
     inline void View::setText(Evas_Object *obj, const char *text, const char *part)
index bcfc30f004e49f9df5583a41b0e3b9b9a5fe41f5..1eeca364ae4d786e083e1e3cc5ddfd7e303c70c8 100644 (file)
@@ -31,6 +31,7 @@ namespace Msg {
     class PaddingListViewItem;
     class ConvReplyListItem;
     class IConvListListener;
+    class ConvTitleListItem;
 
     class ConvList
         : public ListView
@@ -53,6 +54,7 @@ namespace Msg {
             void onListItemChecked(ListItem &listItem) override;
 
             void fillList();
+            void updateTitle();
             MsgStorage &getMsgStorage();
             void insertItem(const MsgConversationItem &item);
 
@@ -62,6 +64,7 @@ namespace Msg {
             IConvListListener *m_pListener;
             PaddingListViewItem *m_pBottomPadItem;
             ConvReplyListItem *m_pReplyItem;
+            ConvTitleListItem *m_pConvTitleItem;
             WorkingDirRef m_WorkingDir;
             BubbleEntityFactory m_BubbleEntityFactory;
             ConvListItemMap m_ConvListItemMap;
index 6ac7da97147ff229df0ca3da601c61c82c68c566..7b1da351298bbb7b33f602b3ca9cefdc4a02a9e2 100644 (file)
@@ -21,6 +21,7 @@
 #include "Window.h"
 #include "ConvReplyListItem.h"
 #include "PaddingListViewItem.h"
+#include "ConvTitleListItem.h"
 
 using namespace Msg;
 
@@ -30,6 +31,7 @@ ConvList::ConvList(Evas_Object *parent, WorkingDirRef &workingDir)
     , m_pListener(nullptr)
     , m_pBottomPadItem(nullptr)
     , m_pReplyItem(nullptr)
+    , m_pConvTitleItem(nullptr)
     , m_WorkingDir(workingDir)
     , m_BubbleEntityFactory(m_WorkingDir)
 {
@@ -66,10 +68,23 @@ MsgStorage &ConvList::getMsgStorage()
     return App::getInst().getMsgEngine().getStorage();
 }
 
+void ConvList::updateTitle()
+{
+    MsgAddressListRef list = getMsgStorage().getAddressList(m_ThreadId);
+    if (list && !list->isEmpty() && m_pConvTitleItem) {
+        m_pConvTitleItem->setTitle(list->at(0).getAddress());
+        // TODO: Find address in contacts
+    }
+}
+
 void ConvList::fillList()
 {
     clear();
 
+    // Recipient name:
+    m_pConvTitleItem = new ConvTitleListItem;
+    ListView::appendItem(*m_pConvTitleItem);
+
     MsgConversationListRef convList = getMsgStorage().getConversationList(m_ThreadId);
     int convListLen = convList->getLength();
 
@@ -97,6 +112,7 @@ void ConvList::setThreadId(ThreadId id)
     if (m_ThreadId != id) {
         m_ThreadId = id;
         fillList();
+        updateTitle();
     }
 }
 
diff --git a/src/Conversation/View/inc/ConvTitleListItem.h b/src/Conversation/View/inc/ConvTitleListItem.h
new file mode 100644 (file)
index 0000000..adbba7e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2016 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 ConvTitleListItem_h_
+#define ConvTitleListItem_h_
+
+#include "ListItem.h"
+
+namespace Msg {
+    class ConvTitleListItem
+        : public ListItem {
+        public:
+            ConvTitleListItem();
+
+            void setTitle(const std::string &title);
+
+        private:
+            Evas_Object *getContent(ListItem &item, const char *part) override;
+            Evas_Object *createLabel() const;
+
+        private:
+            std::string m_Title;
+    };
+}
+
+#endif /* ConvTitleListItem_h_ */
diff --git a/src/Conversation/View/src/ConvTitleListItem.cpp b/src/Conversation/View/src/ConvTitleListItem.cpp
new file mode 100644 (file)
index 0000000..708a7f5
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 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 "ConvTitleListItem.h"
+#include "ListView.h"
+#include "TextDecorator.h"
+
+using namespace Msg;
+
+const TextStyle titleTextStyle = TextStyle().
+                                 setSize(30).
+                                 setAlign(TextStyle::Align::Center).
+                                 setWeight(TextStyle::Weight::Bold).
+                                 setColor("#ffae0d");
+
+ConvTitleListItem::ConvTitleListItem()
+    : ListItem(ListItemStyle::create("conv_title"))
+{
+}
+
+void ConvTitleListItem::setTitle(const std::string &title)
+{
+    m_Title = TextDecorator::make(title, titleTextStyle);
+}
+
+Evas_Object *ConvTitleListItem::createLabel() const
+{
+    static const double slideDuration = 3.0;
+
+    Evas_Object *label = elm_label_add(*getOwner());
+    elm_object_focus_allow_set(label, false);
+    elm_object_style_set(label, "slide_roll");
+    elm_label_ellipsis_set(label, true);
+    elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
+    elm_label_slide_duration_set(label, slideDuration);
+    elm_label_slide_go(label);
+    View::setText(label, m_Title);
+    return label;
+}
+
+Evas_Object *ConvTitleListItem::getContent(ListItem &item, const char *part)
+{
+    return createLabel();
+}