summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Dolzhenko <d.dolzhenko@samsung.com>2017-06-29 19:08:18 +0300
committerDenis Dolzhenko <d.dolzhenko@samsung.com>2017-06-29 19:08:18 +0300
commit8acdfcec81ca5dab26de6e3546adf2311d592fe4 (patch)
tree2b63f0128069c8f64519442940ba9957195ce43e
parent2d7f92cbfe7cd549c29aa082265b19fccfae6035 (diff)
downloadmessage-8acdfcec81ca5dab26de6e3546adf2311d592fe4.tar.gz
message-8acdfcec81ca5dab26de6e3546adf2311d592fe4.tar.bz2
message-8acdfcec81ca5dab26de6e3546adf2311d592fe4.zip
TizenRefApp-8780 Implement Send As Audio menu item in Settings
Change-Id: I91601a07bf8f0f70ae93bd78849844d82707810d Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
-rw-r--r--src/Common/MsgEngine/inc/MsgSettings.h7
-rw-r--r--src/Common/MsgEngine/src/MsgSettings.cpp40
-rw-r--r--src/Common/View/inc/ListItem.h2
-rw-r--r--src/Common/View/src/ListItem.cpp5
-rw-r--r--src/Settings/Controller/inc/SettingsFrame.h32
-rw-r--r--src/Settings/Controller/src/SettingsFrame.cpp104
-rw-r--r--src/Settings/View/inc/SettingsMenuListItem.h15
-rw-r--r--src/Settings/View/src/SettingsMenuListItem.cpp56
8 files changed, 252 insertions, 9 deletions
diff --git a/src/Common/MsgEngine/inc/MsgSettings.h b/src/Common/MsgEngine/inc/MsgSettings.h
index 32d9873..2f75e6a 100644
--- a/src/Common/MsgEngine/inc/MsgSettings.h
+++ b/src/Common/MsgEngine/inc/MsgSettings.h
@@ -86,6 +86,9 @@ namespace Msg {
virtual void setActiveNotifPolicy(ActiveNotifPolicy type) = 0;
virtual void setActiveNotifPolicy(ThreadId id) = 0;
+ void setSendAsAudio(bool value);
+ bool getSendAsAudio() const;
+
protected:
typedef std::vector<IMsgSettingsListener *> MsgSettingsListeners;
@@ -95,12 +98,16 @@ namespace Msg {
private:
MsgSettings(MsgSettings&) = delete;
MsgSettings& operator=(MsgSettings&) = delete;
+
+ void onSendAsAudioChanged(const char *key);
+ void prepareSendAsAudio();
};
class IMsgSettingsListener {
public:
virtual ~IMsgSettingsListener() {}
virtual void onRingtoneChanged(MsgSettings &msgSetting) {};
+ virtual void onSendAsAudioChanged(MsgSettings &msgSetting) {};
};
}
diff --git a/src/Common/MsgEngine/src/MsgSettings.cpp b/src/Common/MsgEngine/src/MsgSettings.cpp
index 47ea37d..f4a85fd 100644
--- a/src/Common/MsgEngine/src/MsgSettings.cpp
+++ b/src/Common/MsgEngine/src/MsgSettings.cpp
@@ -14,9 +14,11 @@
* limitations under the License.
*/
-#include "Config.h"
#include "MsgSettings.h"
+#include "Config.h"
+#include "Callback.h"
#include <algorithm>
+#include <app_preference.h>
using namespace Msg;
@@ -24,14 +26,26 @@ const int defaultSmsGsm7MaxLen = 160;
const int defaultSmsMaxPage = 3;
const int defaultMaxAttachmentsCount = 10;
+#define SEND_AS_AUDIO_KEY PREF_PREFX"/send_as_audio"
+
MsgSettings::MsgSettings()
{
+ prepareSendAsAudio();
}
MsgSettings::~MsgSettings()
{
}
+void MsgSettings::prepareSendAsAudio()
+{
+ bool existing = false;
+ preference_is_existing(SEND_AS_AUDIO_KEY, &existing);
+ if (!existing)
+ setSendAsAudio(false);
+ preference_set_changed_cb(SEND_AS_AUDIO_KEY, makeCbLast(&MsgSettings::onSendAsAudioChanged), this);
+}
+
int MsgSettings::getMessageTextMaxChar() const
{
return defaultSmsGsm7MaxLen;
@@ -50,8 +64,7 @@ int MsgSettings::getAttachmentsMaxCount() const
void MsgSettings::addListener(IMsgSettingsListener &listener)
{
auto itr = std::find(m_Listeners.begin(), m_Listeners.end(), &listener);
- if (itr == m_Listeners.end())
- {
+ if (itr == m_Listeners.end()) {
m_Listeners.push_back(&listener);
}
}
@@ -59,9 +72,26 @@ void MsgSettings::addListener(IMsgSettingsListener &listener)
void MsgSettings::removeListener(IMsgSettingsListener &listener)
{
auto itr = std::find(m_Listeners.begin(), m_Listeners.end(), &listener);
- if (itr != m_Listeners.end())
- {
+ if (itr != m_Listeners.end()) {
m_Listeners.erase(itr);
}
}
+void MsgSettings::setSendAsAudio(bool value)
+{
+ preference_set_boolean(SEND_AS_AUDIO_KEY, value);
+}
+
+bool MsgSettings::getSendAsAudio() const
+{
+ bool value = false;
+ preference_get_boolean(SEND_AS_AUDIO_KEY, &value);
+ return value;
+}
+
+void MsgSettings::onSendAsAudioChanged(const char *key)
+{
+ for (auto listener: m_Listeners)
+ listener->onSendAsAudioChanged(*this);
+}
+
diff --git a/src/Common/View/inc/ListItem.h b/src/Common/View/inc/ListItem.h
index 6252241..2c179e4 100644
--- a/src/Common/View/inc/ListItem.h
+++ b/src/Common/View/inc/ListItem.h
@@ -199,6 +199,8 @@ namespace Msg
virtual void onRealized(ListItem &item) {};
virtual void onUnrealized(ListItem &item) {};
+ OnSelectedCb &getOnSelectedCb();
+
private:
virtual void onViewDestroyed();
Evas_Object *addCheck();
diff --git a/src/Common/View/src/ListItem.cpp b/src/Common/View/src/ListItem.cpp
index 355f89e..9228470 100644
--- a/src/Common/View/src/ListItem.cpp
+++ b/src/Common/View/src/ListItem.cpp
@@ -204,6 +204,11 @@ void ListItem::setOnSelectedCb(OnSelectedCb cb)
m_OnSelectedCb = cb;
}
+ListItem::OnSelectedCb &ListItem::getOnSelectedCb()
+{
+ return m_OnSelectedCb;
+}
+
void ListItem::onCheckChanged(Evas_Object *obj, void *eventInfo)
{
m_Checked = elm_check_state_get(obj);
diff --git a/src/Settings/Controller/inc/SettingsFrame.h b/src/Settings/Controller/inc/SettingsFrame.h
index 48b3750..59fea87 100644
--- a/src/Settings/Controller/inc/SettingsFrame.h
+++ b/src/Settings/Controller/inc/SettingsFrame.h
@@ -18,15 +18,22 @@
#define SettingsFrame_h_
#include "FrameController.h"
-#include "SettingsMenuBlockListFrame.h"
+#include "ListView.h"
+#include "MsgSettings.h"
namespace Msg {
+
+ class SettingsMenuListItem;
+
/**
* @brief A core-class responsible for a whole lifecycle of settings-module and for managing
* sub-components of message settings.
*/
class SettingsFrame
- : public SettingsMenuBlockListFrame {
+ : public FrameController
+ , private IListViewListener
+ , private IMsgSettingsListener {
+
public:
/**
* @brief A constructor of Settings object based on outside parent object.
@@ -38,6 +45,27 @@ namespace Msg {
private:
// NaviFrameItem:
void onAttached(ViewItem &item) override;
+
+ // ListView:
+ void onSountItemSelected(ListItem &item);
+ void onSountItemChecked(SettingsMenuListItem &item);
+ void onBlockListSelected(ListItem &item);
+
+ // IMsgSettingsListener:
+ void onSendAsAudioChanged(MsgSettings &msgSetting) override;
+
+ private:
+ void preapareList();
+ void fillList();
+
+ void updateItems();
+ void updateAudioItem();
+ void updateBlockListItem();
+
+ private:
+ ListView *m_pList;
+ SettingsMenuListItem *m_pAudioItem;
+ SettingsMenuListItem *m_pBlockListItem;
};
}
diff --git a/src/Settings/Controller/src/SettingsFrame.cpp b/src/Settings/Controller/src/SettingsFrame.cpp
index 85eb462..45b7766 100644
--- a/src/Settings/Controller/src/SettingsFrame.cpp
+++ b/src/Settings/Controller/src/SettingsFrame.cpp
@@ -15,21 +15,121 @@
*/
#include "SettingsFrame.h"
+#include "PaddingListViewItem.h"
+#include "SettingsMenuListItem.h"
+#include "TitleListItem.h"
+#include "SettingsMenuBlockListFrame.h"
+#include "App.h"
+#include "MsgEngine.h"
+#include "Window.h"
#include "Logger.h"
+#include "LangUtils.h"
+#include <functional>
using namespace Msg;
SettingsFrame::SettingsFrame(NaviFrameController &parent)
- : SettingsMenuBlockListFrame(parent)
+ : FrameController(parent)
+ , m_pList(nullptr)
+ , m_pAudioItem(nullptr)
+ , m_pBlockListItem(nullptr)
{
+ preapareList();
+ App::getInst().getMsgEngine().getSettings().addListener(*this);
}
SettingsFrame::~SettingsFrame()
{
+ App::getInst().getMsgEngine().getSettings().removeListener(*this);
+}
+
+void SettingsFrame::preapareList()
+{
+ if (!m_pList) {
+ m_pList = new ListView(getParent(), App::getInst().getWindow().getCircleSurface());
+ m_pList->setHomogeneous(false);
+ m_pList->setMultiSelection(false);
+ fillList();
+ }
+}
+
+void SettingsFrame::fillList()
+{
+ using namespace std::placeholders;
+
+ // Title:
+ auto *titleItem = new TitleListItem;
+ titleItem->setTitle("WDS_MSG_HEADER_MESSAGES_ABB", true);
+ m_pList->appendItem(*titleItem);
+
+ // Send as audio:
+ m_pAudioItem = new SettingsMenuListItem(SettingsMenuListItem::twoTextIconStyle);
+ m_pAudioItem->setOnSelectedCb(std::bind(&SettingsFrame::onSountItemSelected, this, _1));
+ m_pAudioItem->setOnChangedCb(std::bind(&SettingsFrame::onSountItemChecked, this, _1));
+ updateAudioItem();
+ m_pList->appendItem(*m_pAudioItem);
+
+ // Block list:
+ m_pBlockListItem = new SettingsMenuListItem(SettingsMenuListItem::twoTextStyle);
+ m_pBlockListItem->setOnSelectedCb(std::bind(&SettingsFrame::onBlockListSelected, this, _1));
+ updateBlockListItem();
+ m_pList->appendItem(*m_pBlockListItem);
+
+ // Bottom padding:
+ m_pList->appendItem(*new PaddingListViewItem);
+}
+
+void SettingsFrame::updateItems()
+{
+ updateAudioItem();
+ updateBlockListItem();
+}
+
+void SettingsFrame::updateAudioItem()
+{
+ m_pAudioItem->setText(msg("WDS_MSG_MBODY_SEND_AS_AUDIO_ABB"));
+ m_pAudioItem->setSubText(msg("WDS_MSG_SBODY_USING_VOICE_INPUT_ABB"));
+ m_pAudioItem->setMenuCheckedState(App::getInst().getMsgEngine().getSettings().getSendAsAudio());
+}
+
+void SettingsFrame::updateBlockListItem()
+{
+ m_pBlockListItem->setText(msg("WDS_MSG_MBODY_BLOCK_LIST"));
}
void SettingsFrame::onAttached(ViewItem &item)
{
MSG_LOG("");
- SettingsMenuBlockListFrame::onAttached(item);
+ FrameController::onAttached(item);
+ preapareList();
+ setContent(*m_pList);
+}
+
+void SettingsFrame::onSountItemSelected(ListItem &item)
+{
+ MSG_LOG("");
+ auto &seetingsItem = static_cast<SettingsMenuListItem&>(item);
+ seetingsItem.changeMenuCheckedState();
+ bool newState = seetingsItem.getMenuCheckedState();
+ App::getInst().getMsgEngine().getSettings().setSendAsAudio(newState);
+}
+
+void SettingsFrame::onSountItemChecked(SettingsMenuListItem &item)
+{
+ MSG_LOG("");
+ bool newState = item.getMenuCheckedState();
+ App::getInst().getMsgEngine().getSettings().setSendAsAudio(newState);
+}
+
+void SettingsFrame::onBlockListSelected(ListItem &item)
+{
+ MSG_LOG("");
+ auto *frame = new SettingsMenuBlockListFrame(getParent());
+ getParent().push(*frame);
+}
+
+void SettingsFrame::onSendAsAudioChanged(MsgSettings &msgSetting)
+{
+ MSG_LOG("");
+ updateAudioItem();
}
diff --git a/src/Settings/View/inc/SettingsMenuListItem.h b/src/Settings/View/inc/SettingsMenuListItem.h
index 5e75bf1..2ceb0ce 100644
--- a/src/Settings/View/inc/SettingsMenuListItem.h
+++ b/src/Settings/View/inc/SettingsMenuListItem.h
@@ -18,14 +18,18 @@
#define SettingsMenuListItem_h_
#include "ListItem.h"
+#include "LangUtils.h"
namespace Msg {
class SettingsMenuListItem
: public ListItem {
public:
+ using OnChangedCb = std::function<void(SettingsMenuListItem &item)>;
+
static ListItemStyleRef oneTextStyle;
static ListItemStyleRef twoTextStyle;
+ static ListItemStyleRef twoTextIconStyle;
public:
SettingsMenuListItem(const ListItemStyleRef &itemStyle);
@@ -34,12 +38,23 @@ namespace Msg {
void setText(std::string text);
void setSubText(std::string text);
+ void setOnChangedCb(OnChangedCb cb);
+ void setMenuCheckedState(bool state);
+ void changeMenuCheckedState();
+ bool getMenuCheckedState() const;
+
private:
std::string getText(ListItem &item, const char *part) override;
+ Evas_Object *getContent(ListItem &item, const char *part) override;
+
+ Evas_Object *createCheck();
+ void onCheckChanged(Evas_Object *obj, void *event_info);
private:
std::string m_Text;
std::string m_SubText;
+ Eina_Bool m_CheckedState;
+ OnChangedCb m_OnChangedCb;
};
}
diff --git a/src/Settings/View/src/SettingsMenuListItem.cpp b/src/Settings/View/src/SettingsMenuListItem.cpp
index edf6d81..5260893 100644
--- a/src/Settings/View/src/SettingsMenuListItem.cpp
+++ b/src/Settings/View/src/SettingsMenuListItem.cpp
@@ -16,6 +16,9 @@
#include "SettingsMenuListItem.h"
#include "LangUtils.h"
+#include "ListView.h"
+#include "Logger.h"
+#include "Callback.h"
using namespace Msg;
@@ -26,9 +29,11 @@ namespace {
ListItemStyleRef SettingsMenuListItem::oneTextStyle = ListItemStyle::create("1text");
ListItemStyleRef SettingsMenuListItem::twoTextStyle = ListItemStyle::create("2text");
+ListItemStyleRef SettingsMenuListItem::twoTextIconStyle = ListItemStyle::create("2text.1icon.1");
SettingsMenuListItem::SettingsMenuListItem(const ListItemStyleRef &itemStyle)
: ListItem(itemStyle)
+ , m_CheckedState(false)
{
}
@@ -46,6 +51,29 @@ void SettingsMenuListItem::setSubText(std::string text)
m_SubText = std::move(text);
}
+void SettingsMenuListItem::setOnChangedCb(OnChangedCb cb)
+{
+ m_OnChangedCb = std::move(cb);
+}
+
+void SettingsMenuListItem::setMenuCheckedState(bool state)
+{
+ if (m_CheckedState != state) {
+ m_CheckedState = state;
+ update();
+ }
+}
+
+void SettingsMenuListItem::changeMenuCheckedState()
+{
+ setMenuCheckedState(!m_CheckedState);
+}
+
+bool SettingsMenuListItem::getMenuCheckedState() const
+{
+ return m_CheckedState;
+}
+
std::string SettingsMenuListItem::getText(ListItem &item, const char *part)
{
if (strcmp(part, mainTextPart) == 0)
@@ -57,3 +85,31 @@ std::string SettingsMenuListItem::getText(ListItem &item, const char *part)
return "";
}
+Evas_Object *SettingsMenuListItem::createCheck()
+{
+ Evas_Object *check = nullptr;
+ check = elm_check_add(*getOwner());
+ elm_object_focus_allow_set(check, false);
+ elm_object_style_set(check, "on&off");
+ elm_check_state_set(check, m_CheckedState);
+ elm_check_state_pointer_set(check, &m_CheckedState);
+ evas_object_propagate_events_set(check, false);
+ evas_object_smart_callback_add(check, "changed", makeCbFirst(&SettingsMenuListItem::onCheckChanged), this);
+ View::processSignal(check);
+ return check;
+}
+
+Evas_Object *SettingsMenuListItem::getContent(ListItem &item, const char *part)
+{
+ if (strcmp(part, "elm.icon") == 0)
+ return createCheck();
+ return nullptr;
+}
+
+void SettingsMenuListItem::onCheckChanged(Evas_Object *obj, void *event_info)
+{
+ MSG_LOG("");
+ if (m_OnChangedCb)
+ m_OnChangedCb(*this);
+}
+