summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander\ Kovalenko <al.kovalenko@samsung.com>2017-09-07 16:42:26 +0300
committerAlexander Kovalenko <al.kovalenko@samsung.com>2017-09-26 13:09:46 +0000
commitc8b1305b22627d84bc4b66f2904350841126cef9 (patch)
tree012e553cdb5aab682cd7cb1247ca95d5edaf982a
parenteb29dda8e3bbbb468c9ee291fa6f4d6929a306fc (diff)
downloadcall-setting-c8b1305b22627d84bc4b66f2904350841126cef9.tar.gz
call-setting-c8b1305b22627d84bc4b66f2904350841126cef9.tar.bz2
call-setting-c8b1305b22627d84bc4b66f2904350841126cef9.zip
TizenRefApp-8932 [Call Setting] Implement base ListOptionItem
Change-Id: I43c393e2797a35797c199580e64d13431d87f8f4
-rw-r--r--call-setting/presenters/items/base/ListOptionItem.cpp119
-rw-r--r--call-setting/presenters/items/base/ListOptionItem.h72
2 files changed, 191 insertions, 0 deletions
diff --git a/call-setting/presenters/items/base/ListOptionItem.cpp b/call-setting/presenters/items/base/ListOptionItem.cpp
new file mode 100644
index 0000000..6937539
--- /dev/null
+++ b/call-setting/presenters/items/base/ListOptionItem.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2017 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 "ListOptionItem.h"
+
+#include "call-setting/presenters/common.h"
+
+namespace call_setting { namespace { namespace impl {
+
+ constexpr ElmStyle ITEM_STYLE {"2text"};
+ constexpr EdjePart ITEM_PART_TITLE {"elm.text"};
+ constexpr EdjePart ITEM_PART_SUBTEXT {"elm.text.1"};
+}}}
+
+namespace call_setting {
+
+ using ucl::GenlistItem;
+
+ ListOptionItem::ListOptionItem(IRefCountObj &rc) :
+ ListItemPresenter::ListItemPresenter(rc)
+ {
+ }
+
+ ListOptionItem::~ListOptionItem()
+ {
+ }
+
+ ListOptionItem::ItemInsertionParams
+ ListOptionItem::getItemInsertionParams()
+ {
+ return impl::ITEM_STYLE;
+ }
+
+ CString ListOptionItem::getItemPartText(const EdjePart part)
+ {
+ if (part == impl::ITEM_PART_TITLE) {
+ return getOptionTitle();
+ }
+
+ if (part == impl::ITEM_PART_SUBTEXT) {
+ TString optionTextById = m_optionMap.get(getOptionValue());
+ return CString::dup(optionTextById.translate());
+ }
+
+ return nullptr;
+ }
+
+ void ListOptionItem::onItemSelected()
+ {
+ if (!isActive()) {
+ return;
+ }
+
+ if (m_dialogParent) {
+ m_dialog = m_dialogBuilder.
+ setInitialOptionId(getOptionValue()).
+ build(*m_dialogParent);
+ if (!m_dialog) {
+ LOG_RETURN_VOID(RES_FAIL,
+ "ListOptionDialog::Builder.build() failed");
+ }
+ }
+ }
+
+ bool ListOptionItem::onDialogEvent(ListOptionDialog &dialog,
+ ListOptionDialog::Event event)
+ {
+ if (event == ListOptionDialog::Event::OK) {
+ requestOptionValueChange(dialog.getSelectedOptionId());
+ }
+ return false;
+ }
+
+ void ListOptionItem::update()
+ {
+ tryDismissDialog();
+
+ if (const auto item = getItem()) {
+ item.update(impl::ITEM_PART_SUBTEXT, GenlistItem::FIELD_TEXT);
+ }
+ }
+
+ void ListOptionItem::tryDismissDialog()
+ {
+ if (const auto dialog = m_dialog.lock()) {
+ dialog->dismiss();
+ }
+ }
+ void ListOptionItem::prepare(Options options,
+ ElmWidgetSRef dialogParent)
+ {
+ if (!dialogParent) {
+ LOG_RETURN_VOID(RES_INVALID_ARGUMENTS, "dialogParent is null");
+ }
+ for (auto &option: options) {
+ m_dialogBuilder.addOption({option.id,
+ option.text});
+ m_optionMap.set(option.id, std::move(option.text));
+ }
+ m_dialogBuilder.setTitle(TString(getOptionTitle().get()));
+ m_dialogBuilder.setHandler(WEAK_DELEGATE(
+ ListOptionItem::onDialogEvent, asWeak(*this)));
+ m_dialogParent = std::move(dialogParent);
+ }
+
+}
diff --git a/call-setting/presenters/items/base/ListOptionItem.h b/call-setting/presenters/items/base/ListOptionItem.h
new file mode 100644
index 0000000..88ddc6f
--- /dev/null
+++ b/call-setting/presenters/items/base/ListOptionItem.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017 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 __CALL_SETTING_PRESENTERS_LIST_OPTION_ITEM_H__
+#define __CALL_SETTING_PRESENTERS_LIST_OPTION_ITEM_H__
+
+#include "ucl/mvp/ListItemPresenter.h"
+#include "ucl/misc/HashMap.h"
+
+#include "call-setting/presenters/dialogs/ListOptionDialog.h"
+
+namespace call_setting {
+
+ UCL_DECLARE_REF_ALIASES(ListOptionItem);
+
+ class ListOptionItem : public ucl::ListItemPresenter {
+ protected:
+ struct Option final {
+ int id;
+ ucl::TString text;
+ };
+
+ using Options = std::list<Option>;
+
+ protected:
+ ListOptionItem(ucl::IRefCountObj &rc);
+ virtual ~ListOptionItem();
+
+ virtual int getOptionValue() const = 0;
+ virtual ucl::CString getOptionTitle() const = 0;
+ virtual void requestOptionValueChange(int value) = 0;
+
+ void update();
+ void tryDismissDialog();
+
+ void prepare(std::list<Option> options,
+ ucl::ElmWidgetSRef dialogParent);
+
+ // ListItemPresenter //
+
+ virtual ItemInsertionParams getItemInsertionParams() final override;
+
+ virtual ucl::CString getItemPartText(ucl::EdjePart part) final override;
+
+ virtual void onItemSelected() final override;
+
+ private:
+ bool onDialogEvent(ListOptionDialog &dialog,
+ ListOptionDialog::Event event);
+
+ private:
+ ListOptionDialog::Builder m_dialogBuilder;
+ ListOptionDialogWRef m_dialog;
+ ucl::ElmWidgetSRef m_dialogParent;
+ ucl::HashMap<int, ucl::TString> m_optionMap;
+ };
+}
+
+#endif // __CALL_SETTING_PRESENTERS_LIST_OPTION_ITEM_H__