TizenRefApp-8865 Integrate SendingOptions to Composer 65/139365/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 18 Jul 2017 12:34:26 +0000 (15:34 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 18 Jul 2017 12:34:26 +0000 (15:34 +0300)
Change-Id: Ib98694197777846ccae4b0fde022852bc0bb6e6e
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
16 files changed:
inc/Resource.h
src/Common/AppControl/inc/InputSelector.h
src/Common/AppControl/src/AppControlUtils.cpp
src/Common/AppControl/src/InputSelector.cpp
src/Common/ContactManager/src/ContactManager.cpp
src/Common/Controller/src/App.cpp
src/Common/Controller/src/NaviFrameController.cpp
src/Common/MsgEngine/src/private/MsgComposerPrivate.cpp
src/Common/MsgEngine/src/private/MsgTransportPrivate.cpp
src/Common/View/inc/View.h
src/Composer/Controller/inc/Composer.h
src/Composer/Controller/inc/MsgInputSelector.h
src/Composer/Controller/inc/SendingOptionsFrame.h
src/Composer/Controller/src/Composer.cpp
src/Composer/Controller/src/MsgInputSelector.cpp
src/Composer/Controller/src/SendingOptionsFrame.cpp

index c5fda899acfb0235a92da5c42bb60f8887abb98e..fcbc2023989b4ca320ae5247784cec75f9c1bef0 100644 (file)
@@ -30,8 +30,6 @@
 
 #define NO_SPAM_MSG_ICON                "No_item/msg_no_spam_messages.png"
 
-#define TEST_IMAGE_PATH                 "images/cat.png"
-
 #define NEW_MSG_MORE_ICON                MORE_OPTION_DIR"/b_more_option_ic_compose.png"
 #define DELETEG_MORE_ICON                MORE_OPTION_DIR"/b_more_option_ic_delete.png"
 #define ADD_TO_SPAM_MORE_ICON            MORE_OPTION_DIR"/b_more_option_ic_add_to_spam.png"
index 672ae08f8feb777ee013c0f16e42cd3c44240edf..1e89292f87dd3c4496f10dd6105603190f66a861 100644 (file)
@@ -51,10 +51,11 @@ namespace Msg {
             virtual void onEmoticonReply(const std::string &emoticon) {};
             virtual void onTerminate() {};
 
-            void clear();
+            void terminateHandler();
 
         private:
             void onReply(app_control_h request, app_control_h reply, app_control_result_e result) override;
+            void clear();
 
         private:
             IInputSelectorListener *m_pListener;
index 303fa9c54d19954d6fd26945b39b60b2a6e3d22d..b903dd32ee2d8b63c697f55669a538f2d93c5755 100644 (file)
@@ -42,8 +42,10 @@ std::list<std::string> getExtraDataArray(app_control_h handle, const std::string
     char **pArrayVal = nullptr;
     if (APP_CONTROL_ERROR_NONE == app_control_get_extra_data_array(handle, key.c_str(), &pArrayVal, &arrayLength)) {
         for (int i = 0; i < arrayLength; ++i) {
-            res.push_back(pArrayVal[i]);
-            free(pArrayVal[i]);
+            if (pArrayVal[i]) {
+                res.push_back(pArrayVal[i]);
+                free(pArrayVal[i]);
+            }
         }
         free(pArrayVal);
     }
index 347af06c9d08540c2adf8c6460206460e0461685..b311fe60f457d47f6e4c7e9cc1ba43e5b140fce6 100644 (file)
@@ -23,6 +23,7 @@ InputSelector::InputSelector()
     : m_pListener(nullptr)
 {
     setOperation(APP_CONTROL_OPERATION_GET_INPUT);
+    addExtraData("return_key_type", "DONE");
 }
 
 InputSelector::~InputSelector()
@@ -45,6 +46,14 @@ void InputSelector::clear()
     removeExtraData(APP_CONTROL_DATA_INPUT_DEFAULT_TEXT);
 }
 
+void InputSelector::terminateHandler()
+{
+    onTerminate();
+    if (m_pListener)
+        m_pListener->onTerminate(*this);
+    clear();
+}
+
 bool InputSelector::launch(InputType type)
 {
     terminate();
@@ -93,12 +102,8 @@ void InputSelector::onReply(app_control_h request, app_control_h reply, app_cont
              onVoiceReply(text, fileList);
          } if (replyType == "template") {
              onTemplateReply(text);
-         } else {
-             onTerminate();
-             if (m_pListener)
-                 m_pListener->onTerminate(*this);
-             clear();
          }
     }
+    terminateHandler();
 }
 
index 4115bd7ebe835ce189a74559ce533d30b1c75d0d..c5c50830a3754ea0b4513bb5cf6ba0e323c28953 100644 (file)
     {
         contacts_filter_h filter = nullptr;
         contacts_filter_create(_contacts_person_phone_log._uri, &filter);
-        contacts_filter_add_str(filter, _contacts_person_email.email, CONTACTS_MATCH_FULLSTRING, address.c_str());
+        contacts_filter_add_str(filter, _contacts_person_phone_log.address, CONTACTS_MATCH_FULLSTRING, address.c_str());
         return filter ? getContactPersonPhoneLog(filter) : nullptr;
     }
 
index 43b3effe08a6ccb0dd36aac10b22fbf4c0779843..ee369e03557634049b72857e7570bb081e107382 100644 (file)
@@ -85,6 +85,8 @@ App &App::getInst()
 
 void App::exit()
 {
+    MSG_LOG("");
+
     if (m_IsTerminating)
         return;
 
index 13c32166ff2612a69a5fe326eb031c3ce346f054..5920660e624e5017599eb5c3b3c68e6486d7faeb 100644 (file)
@@ -49,6 +49,12 @@ NaviFrameController::~NaviFrameController()
 
 void NaviFrameController::pop(FrameController &frame)
 {
+    if (frame.isPopping())
+        return;
+
+    MSG_LOG("Is Last frame: ", isLastFrame());
+    MSG_LOG("PopupManager isEmpty: ", App::getInst().getPopupManager().isEmpty());
+
     if (isLastFrame() && App::getInst().getPopupManager().isEmpty())
         App::getInst().exit();
     else {
@@ -75,10 +81,11 @@ void NaviFrameController::popGroup(FrameController &frame)
 void NaviFrameController::popGroup(FrameController::GroupType type)
 {
     auto items = getItems();
-    for (NaviFrameItem * item: items) {
+    for (NaviFrameItem *item: items) {
         auto *frame = dynamic_cast<FrameController*>(item);
-        if (frame && frame->getGroupType() == type)
+        if (frame && frame->getGroupType() == type) {
             pop(*frame);
+        }
     }
 }
 
index 0b07c5e483e04990f4cf3c86da70cd32f7424a0e..48b60792e74ff5e5ed2d44106a98c22ee5898b57 100644 (file)
@@ -116,10 +116,10 @@ void MsgComposerPrivate::calculateTextMetric(const std::string &text, MsgTextMet
 {
     textMetric.reset();
 
-    static const int maxGsm7Len = 160;
-    static const int maxUnicodeLen = 70;
-    const int maxMmsLen = m_Engine.getSettings().getMaxMmsSize(); // In bytes
-    int maxSmsLen = maxGsm7Len; // In chars
+    static const unsigned maxGsm7Len = 160;
+    static const unsigned maxUnicodeLen = 70;
+    const unsigned maxMmsLen = m_Engine.getSettings().getMaxMmsSize(); // In bytes
+    unsigned maxSmsLen = maxGsm7Len; // In chars
 
     msg_encode_type_t encode = MSG_ENCODE_GSM7BIT;
     unsigned textLen = 0;
index ce06f780ed62888a8b7bf3f44ac3dc0fc700689a..d0dbb16456125e4cdaf06abd5a13865e37cd6025 100644 (file)
@@ -75,6 +75,7 @@ MsgTransport::SendResult MsgTransportPrivate::sendMessage(Message &msg, ThreadId
     msg_release_struct(&req);
 
     MsgTransport::SendResult sendRes = MsgUtilsPrivate::nativeToSendResult(err);
+    MSG_LOG("Send raw result: ", err);
     MSG_LOG("Send result: ", sendRes);
     return sendRes;
 }
index 5fc2c274ff9b78f96e61d0552acf89082abb5a40..e0723f8af48638fc1bc21ab8c2e2e6d56fbd47ec 100644 (file)
@@ -22,6 +22,7 @@
 #include "LangUtils.h"
 #include "Callback.h"
 #include <Elementary.h>
+#include <app.h>
 #include <efl_extension.h>
 
 namespace Msg
index 1904e3ee4de41e410c8f6210239df47226198e57..cf1af9af3f8ffa17f18cd8d8f4aff8e930cdf07b 100644 (file)
@@ -25,6 +25,7 @@
 #include "WorkingDir.h"
 #include "AppControlCompose.h"
 #include "ConnectivityChecker.h"
+#include "SendingOptionsFrame.h"
 #include "View.h"
 
 #include <set>
@@ -38,7 +39,8 @@ namespace Msg {
     class Popup;
 
     class Composer
-        : private IMsgTransportListener {
+        : private IMsgTransportListener
+        , private ISendingOptionsFrameListener {
 
         public:
             Composer();
@@ -49,7 +51,7 @@ namespace Msg {
             const Recipient &getRecip() const;
             void setText(std::string text);
             bool addFile(const std::string &file);
-            ThreadId send();
+            void send();
             ThreadId getThreadId() const;
             void reset();
             void clear();
@@ -68,16 +70,30 @@ namespace Msg {
             // IMsgTransportListener:
             void onMsgTransportSentStatus(const MsgSentStatus &status) override;
 
-            bool checkBeforeSend(Message::Type type);
+            // ISendingOptionsFrameListener:
+            void onSendAsText(SendingOptionsFrame &sender) override;
+            void onSendAsAudio(SendingOptionsFrame &sender) override;
+            void onDestroy(SendingOptionsFrame &sender) override;
+
+            bool checkConnectivity(Message::Type type);
+            bool checkSendingOptions();
             std::vector<MessageRef> createMessage();
             void requestSendMessage();
             void sendMessage();
-            bool readAddress(MessageRef msg);
+            bool readAddress(Message &msg);
             void handleSendResult(MsgTransport::SendResult result);
+            void destroySendingPopup(bool anim = true);
+            void navigateToSendingOptions();
 
             void setText(MessageRef msg, const std::string &text);
             void setText(MessageSMS &msg, const std::string &text);
             void setText(MessageMms &msg, const std::string &text);
+            void addFile(MessageMms &msg, const std::string &filePath);
+            void removeAudioFiles();
+
+            void notifyOnSendStart();
+            void notifyOnSendFinished();
+            void notifyOnCloseSendPopup();
 
             // Popup:
             void showMaxCharactersPopup();
@@ -105,7 +121,8 @@ namespace Msg {
     class IComposerListener {
         public:
             virtual ~IComposerListener() {}
-            virtual void onSendFinished(Composer &composer, Message::NetworkStatus status) {};
+            virtual void onSendStart(Composer &composer) {};
+            virtual void onSendFinished(Composer &composer) {};
             virtual void onCloseSendPopup(Composer &composer) {};
     };
 }
index 4e6aa8105f354b417e4529b5ba61bdc45a9069c4..bcb64034bf0314a8b723dd3b05f9516ad16a30e0 100644 (file)
@@ -45,7 +45,7 @@ namespace Msg {
         protected:
             void onTemplateReply(const std::string &text) override;
             void onKeyboardReply(const std::string &text) override;
-            void onVoiceReply(const std::string &text, const std::list<std::string> &filePath) override;
+            void onVoiceReply(const std::string &text, const std::list<std::string> &fileList) override;
             void onEmoticonReply(const std::string &emoticon) override;
 
         private:
@@ -53,9 +53,11 @@ namespace Msg {
             void showMsgBody(const std::string &text);
             void navigateToConv(ThreadId threadId);
             void send();
+            void addDummyAudio();
 
             // IComposerListener:
-            void onSendFinished(Composer &composer, Message::NetworkStatus status) override;
+            void onSendStart(Composer &composer) override;
+            void onSendFinished(Composer &composer) override;
             void onCloseSendPopup(Composer &composer) override;
 
             // IMsgBodyFrameListener:
index 52f2e48e7f5038601fd4500f391b6e695faa1233..b22ffbfdfc858f6faa7cd30d287c0d4bf2f56a60 100644 (file)
@@ -26,6 +26,7 @@ namespace Msg {
 
     class SendingOptionListViewItem;
     class AlwaysSendAsTextListViewItem;
+    class ISendingOptionsFrameListener;
 
     class SendingOptionsFrame
         : public FrameController
@@ -36,6 +37,8 @@ namespace Msg {
             SendingOptionsFrame(NaviFrameController &parent);
             virtual ~SendingOptionsFrame();
 
+            void setListener(ISendingOptionsFrameListener *l);
+
         private:
             // NaviFrameItem:
             void onAttached(ViewItem &item) override;
@@ -50,11 +53,21 @@ namespace Msg {
         private:
             void preapareList();
             void fillList();
+            void alwaysSendTextHandler(bool value);
 
         private:
             ListView *m_pList;
             SendingOptionListViewItem *m_pSendingOptionItem;
             AlwaysSendAsTextListViewItem *m_pSendAsTextItem;
+            ISendingOptionsFrameListener *m_pListener;
+    };
+
+    class ISendingOptionsFrameListener {
+        public:
+            virtual ~ISendingOptionsFrameListener() {}
+            virtual void onSendAsText(SendingOptionsFrame &sender) {};
+            virtual void onSendAsAudio(SendingOptionsFrame &sender) {};
+            virtual void onDestroy(SendingOptionsFrame &sender) {};
     };
 }
 
index 24c6bbe21fe98a10382aea395f62956da510e062..1ff3e72ca763197c05a7f88df2dd586fd947c822 100644 (file)
@@ -25,6 +25,9 @@
 #include "IconTextPopup.h"
 #include "ToastPopup.h"
 #include "NaviFrameController.h"
+#include "MediaType.h"
+#include "SendingOptionsFrame.h"
+#include "MediaUtils.h"
 
 using namespace Msg;
 
@@ -57,8 +60,7 @@ Composer::Composer()
 Composer::~Composer()
 {
     MSG_LOG("");
-    if (m_pSendingPopup)
-        m_pSendingPopup->destroy();
+    destroySendingPopup(false);
     App::getInst().getMsgEngine().getTransport().removeListener(*this);
 }
 
@@ -91,11 +93,40 @@ bool Composer::addFile(const std::string &file)
     return isValid;
 }
 
-ThreadId Composer::send()
+void Composer::addFile(MessageMms &msg, const std::string &filePath)
+{
+    constexpr int defaultPageDuration = 5000; // msec
+    if (!filePath.empty()) {
+        MsgPage &msgPage = msg.addPage();
+        MediaTypeData mediaData = getMsgMediaTypeByFileExt(filePath);
+        int pageDuration = 0;
+
+        if (mediaData.type == MsgMedia::VideoType || mediaData.type == MsgMedia::AudioType)
+            pageDuration = MediaUtils::getDuration(filePath);
+
+        if (pageDuration <= 0)
+            pageDuration = defaultPageDuration;
+
+        msgPage.setPageDuration(pageDuration);
+        MsgMedia &media = msgPage.addMedia();
+        media.setFilePath(filePath);
+    }
+}
+
+void Composer::removeAudioFiles()
+{
+    decltype(m_Files) newFileList;
+    for (std::string &file : m_Files) {
+       if (getMsgMediaTypeByFileExt(file).type != MsgMedia::AudioType)
+           newFileList.push_back(std::move(file));
+    }
+    m_Files = std::move(newFileList);
+}
+
+void Composer::send()
 {
     reset();
     requestSendMessage();
-    return getThreadId();
 }
 
 ThreadId Composer::getThreadId() const
@@ -116,10 +147,10 @@ void Composer::clear()
     m_Files.clear();
 }
 
-bool Composer::readAddress(MessageRef msg)
+bool Composer::readAddress(Message &msg)
 {
-    if(m_Recip.isValid() && msg) {
-        MsgAddress &msgAddr = msg->addAddress();
+    if(m_Recip.isValid()) {
+        MsgAddress &msgAddr = msg.addAddress();
         msgAddr.setAddress(m_Recip.getAddress());
         msgAddr.setRecipientType(MsgAddress::To);
         msgAddr.setAddressType(MsgAddress::Phone);
@@ -155,18 +186,45 @@ void Composer::setText(MessageMms &msg, const std::string &text)
     }
 }
 
-bool Composer::checkBeforeSend(Message::Type type)
+bool Composer::checkConnectivity(Message::Type type)
 {
     auto &checker = App::getInst().getNavigation().getConnectivityChecker();
     return MsgUtils::isMms(type) ? checker.isReadyToSendMms()
                                  : checker.isReadyToSendSms();
 }
 
-std::vector<MessageRef> Composer::createMessage()
+void Composer::navigateToSendingOptions()
 {
-    auto &msgEngine = App::getInst().getMsgEngine();
+    auto &navi = App::getInst().getNavigation();
+    auto *frame = new SendingOptionsFrame(navi);
+    frame->setListener(this);
+    navi.push(*frame);
+}
 
+bool Composer::checkSendingOptions()
+{
+    if (!App::getInst().getMsgEngine().getSettings().getSendAsAudio() ||
+        m_Files.empty())
+        return true;
+
+    bool onlyAudio = true;
+    for (const std::string &file : m_Files) {
+        onlyAudio &= getMsgMediaTypeByFileExt(file).type == MsgMedia::AudioType;
+        if (!onlyAudio)
+            break;
+    }
+
+    if (onlyAudio) {
+        navigateToSendingOptions();
+        return false;
+    }
+    return true;
+}
+
+std::vector<MessageRef> Composer::createMessage()
+{
     std::vector<MessageRef> msgList;
+    auto &msgEngine = App::getInst().getMsgEngine();
     const int maxMsgSize = msgEngine.getSettings().getMaxMmsSize();
 
     if (maxMsgSize <= 0) {
@@ -174,38 +232,59 @@ std::vector<MessageRef> Composer::createMessage()
         return {};
     }
 
-    auto textList = MsgUtils::splitUtf8String(m_Text, maxMsgSize);
-
-    for (auto &&text : textList) {
-        MsgTextMetric metric;
-        msgEngine.getComposer().calculateTextMetric(m_Text, metric);
-        Message::Type type = metric.isMms ? Message::MT_MMS : Message::MT_SMS;
-        auto msg = msgEngine.getComposer().createMessage(type);
-        if (readAddress(msg)) {
-            setText(msg, text);
-            msgList.push_back(msg);
+    if (m_Files.empty()) {
+        // Text messages:
+        auto textList = MsgUtils::splitUtf8String(m_Text, maxMsgSize);
+        for (auto &&text : textList) {
+            MsgTextMetric metric;
+            msgEngine.getComposer().calculateTextMetric(m_Text, metric);
+            Message::Type type = metric.isMms ? Message::MT_MMS : Message::MT_SMS;
+            auto msg = msgEngine.getComposer().createMessage(type);
+            if (msg && readAddress(*msg)) {
+                setText(msg, text);
+                msgList.push_back(msg);
+            }
+        }
+    } else {
+        // Create MMS:
+        auto mms = msgEngine.getComposer().createMms();
+        if (mms) {
+            if (readAddress(*mms)) {
+                for (const std::string &file : m_Files)
+                    addFile(*mms, file);
+                msgList.push_back(mms);
+            }
         }
     }
-
     return msgList;
 }
 
 void Composer::requestSendMessage()
 {
     m_SendInfo.reset();
+    destroySendingPopup(false);
 
-    m_SendInfo.msgs = createMessage();
-    if (m_SendInfo.msgs.empty())
-        return;
-
-    if (!checkBeforeSend(m_SendInfo.msgs [0]->getType()))
+    if (!checkSendingOptions())
         return;
 
+    removeAudioFiles();
     sendMessage();
 }
 
 void Composer::sendMessage()
 {
+    MSG_LOG("");
+    // Create message:
+    m_SendInfo.msgs = createMessage();
+    if (m_SendInfo.msgs.empty())
+        return;
+
+    MSG_LOG("");
+    // Check connectivity:
+    if (!checkConnectivity(m_SendInfo.msgs[0]->getType()))
+         return;
+
+    // Send process:
     MsgTransport::SendResult sendRes = MsgTransport::SendFail;
     MessageRef lastSentMsg;
 
@@ -215,6 +294,7 @@ void Composer::sendMessage()
         sendRes = App::getInst().getMsgEngine().getTransport().sendMessage(msg, &m_SendInfo.threadId, &reqId);
 
         MSG_LOG("Send result = ", sendRes);
+        MSG_LOG("Thread id = ", m_SendInfo.threadId);
         MSG_LOG("Request id = ", reqId);
 
         if (sendRes != MsgTransport::SendSuccess)
@@ -226,14 +306,42 @@ void Composer::sendMessage()
 
     if (sendRes == MsgTransport::SendSuccess && m_SendInfo.threadId.isValid()) {
         showSendingProgressPopup();
+        notifyOnSendStart();
     } else {
+        notifyOnSendStart();
         handleSendResult(sendRes);
     }
 }
 
-void Composer::handleSendResult( MsgTransport::SendResult result)
+void Composer::notifyOnSendStart()
+{
+    if (m_pListener)
+        m_pListener->onSendStart(*this);
+}
+
+void Composer::notifyOnSendFinished()
+{
+    if (m_pListener)
+        m_pListener->onSendFinished(*this);
+}
+
+void Composer::notifyOnCloseSendPopup()
+{
+    if (m_pListener)
+        m_pListener->onCloseSendPopup(*this);
+}
+
+void Composer::handleSendResult(MsgTransport::SendResult result)
+{
+    notifyOnSendFinished();
+}
+
+void Composer::destroySendingPopup(bool anim)
 {
-    // TODO: impl.
+    if (m_pSendingPopup) {
+        m_pSendingPopup->destroy(anim);
+        m_pSendingPopup = nullptr;
+    }
 }
 
 void Composer::showMaxCharactersPopup()
@@ -322,12 +430,11 @@ void Composer::onMsgTransportSentStatus(const MsgSentStatus &status)
             m_pSendingPopup->setText(msgt("WDS_MSG_TPOP_SENDING_FAILED_ABB"));
             m_pSendingPopup->setTimeOut();
         } else if (m_SendInfo.status != Message::NS_Send_Pending) {
-            m_pSendingPopup->destroy();
+            destroySendingPopup();
             showSentWhenServiceBecomesAvailablePopup();
         }
 
-        if (m_pListener)
-            m_pListener->onSendFinished(*this, m_SendInfo.status);
+        notifyOnSendFinished();
     }
 }
 
@@ -335,16 +442,13 @@ void Composer::onSendingPopupDestroy(Evas *e, Evas_Object *obj, void *event_info
 {
     MSG_LOG("");
     m_pSendingPopup = nullptr;
-    if (m_pListener)
-        m_pListener->onCloseSendPopup(*this);
+    notifyOnCloseSendPopup();
 }
 
 void Composer::onSendingPopupBackButtonPressed(Evas_Object *obj, void *event_info)
 {
     MSG_LOG("");
-    if (m_pSendingPopup)
-        m_pSendingPopup->destroy();
-
+    destroySendingPopup();
     if (m_SendInfo.inProgress)
         m_SendInfo.reset();
 }
@@ -354,3 +458,22 @@ void Composer::onAllowTransmissionTextClicked(Popup &popup)
     MSG_LOG("");
     popup.destroy();
 }
+
+void Composer::onSendAsText(SendingOptionsFrame &sender)
+{
+    MSG_LOG("");
+    removeAudioFiles();
+    sendMessage();
+}
+
+void Composer::onSendAsAudio(SendingOptionsFrame &sender)
+{
+    MSG_LOG("");
+    m_Text.clear();
+    sendMessage();
+}
+
+void Composer::onDestroy(SendingOptionsFrame &sender)
+{
+    MSG_LOG("");
+}
index 8c7a61ab67aff70455c964d259622a78b7170e38..ef8558c5edb095f657353cffa6fe4fe99948a0a5 100644 (file)
@@ -20,6 +20,7 @@
 #include "ConvFrame.h"
 #include "App.h"
 #include "Logger.h"
+#include "PathUtils.h"
 
 using namespace Msg;
 
@@ -115,16 +116,28 @@ void MsgInputSelector::navigateToConv(ThreadId threadId)
 
 void MsgInputSelector::send()
 {
-    ThreadId id = m_Composer.send();
-    if (id.isValid()) {
-        if (m_CloseAfterSent)
-            getNavigation().popGroup(FrameController::ComposerGroup);
-        else
-            navigateToConv(id);
+    m_Composer.send();
+}
+
+void MsgInputSelector::addDummyAudio()
+{
+    std::string file = PathUtils::getResourcePath("dummy_res/1.mp3");
+    m_Composer.addFile(file);
+}
+
+void MsgInputSelector::onSendStart(Composer &composer)
+{
+    MSG_LOG("");
+    ThreadId id = composer.getThreadId();
+
+    if (m_CloseAfterSent || !id.isValid()) {
+        getNavigation().popGroup(FrameController::ComposerGroup);
+    } else {
+        navigateToConv(id);
     }
 }
 
-void MsgInputSelector::onSendFinished(Composer &composer, Message::NetworkStatus status)
+void MsgInputSelector::onSendFinished(Composer &composer)
 {
     MSG_LOG("");
 }
@@ -171,12 +184,16 @@ void MsgInputSelector::onEmoticonReply(const std::string &emoticon)
 {
     MSG_LOG("");
     m_Composer.setText(emoticon);
+    // addDummyAudio(); // Only for test will be removed
     send();
 }
 
-void MsgInputSelector::onVoiceReply(const std::string &text, const std::list<std::string> &filePath)
+void MsgInputSelector::onVoiceReply(const std::string &text, const std::list<std::string> &fileList)
 {
     MSG_LOG("");
     m_Composer.setText(text);
+    for (const std::string &file : fileList) {
+        m_Composer.addFile(file);
+    }
     send();
 }
index db5d190ca5d0289a6b8aa94662ec2bae8734d43d..63947d5631dac2425abe72bff2f6225a7849771e 100644 (file)
@@ -21,6 +21,8 @@
 #include "LangUtils.h"
 #include "App.h"
 #include "NaviFrameController.h"
+#include "App.h"
+#include "MsgEngine.h"
 
 #include <functional>
 
@@ -31,12 +33,20 @@ SendingOptionsFrame::SendingOptionsFrame(NaviFrameController &parent)
     , m_pList(nullptr)
     , m_pSendingOptionItem(nullptr)
     , m_pSendAsTextItem(nullptr)
+    , m_pListener(nullptr)
 {
     preapareList();
 }
 
 SendingOptionsFrame::~SendingOptionsFrame()
 {
+    if (m_pListener)
+        m_pListener->onDestroy(*this);
+}
+
+void SendingOptionsFrame::setListener(ISendingOptionsFrameListener *l)
+{
+    m_pListener = l;
 }
 
 void SendingOptionsFrame::preapareList()
@@ -63,6 +73,7 @@ void SendingOptionsFrame::fillList()
     m_pList->appendItem(*m_pSendingOptionItem);
 
     m_pSendAsTextItem = new AlwaysSendAsTextListViewItem;
+    m_pSendAsTextItem->setCheckedState(!App::getInst().getMsgEngine().getSettings().getSendAsAudio());
     m_pSendAsTextItem->setOnSelectedCb(std::bind(&SendingOptionsFrame::onSendAsTextItemSelected, this, _1));
     m_pSendAsTextItem->setOnChangedCb(std::bind(&SendingOptionsFrame::onCheckItemClicked, this, _1));
     m_pList->appendItem(*m_pSendAsTextItem);
@@ -71,6 +82,17 @@ void SendingOptionsFrame::fillList()
     m_pList->appendItem(*new PaddingListViewItem);
 }
 
+void SendingOptionsFrame::alwaysSendTextHandler(bool value)
+{
+    App::getInst().getMsgEngine().getSettings().setSendAsAudio(!value);
+
+    if (m_pListener) {
+        bool sendAsAudio = App::getInst().getMsgEngine().getSettings().getSendAsAudio();
+        sendAsAudio ? m_pListener->onSendAsAudio(*this) : m_pListener->onSendAsText(*this);
+    }
+    pop();
+}
+
 void SendingOptionsFrame::onAttached(ViewItem &item)
 {
     MSG_LOG("");
@@ -82,11 +104,17 @@ void SendingOptionsFrame::onAttached(ViewItem &item)
 void SendingOptionsFrame::onTextButtonClicked()
 {
     MSG_LOG("");
+    if (m_pListener)
+        m_pListener->onSendAsText(*this);
+    pop();
 }
 
 void SendingOptionsFrame::onAudioButtonClicked()
 {
     MSG_LOG("");
+    if (m_pListener)
+        m_pListener->onSendAsAudio(*this);
+    pop();
 }
 
 void SendingOptionsFrame::onSendAsTextItemSelected(ListItem &item)
@@ -95,11 +123,13 @@ void SendingOptionsFrame::onSendAsTextItemSelected(ListItem &item)
     auto &textItem = static_cast<AlwaysSendAsTextListViewItem&>(item);
     textItem.changeCheckedState();
     bool newState = textItem.getCheckedState();
+    alwaysSendTextHandler(newState);
 }
 
 void SendingOptionsFrame::onCheckItemClicked(AlwaysSendAsTextListViewItem &item)
 {
     MSG_LOG("");
     bool newState = item.getCheckedState();
+    alwaysSendTextHandler(newState);
 }