Evas_Object *getInnerButton() const;
void setText(const TText &text);
+ void disabled(bool value);
private:
Evas_Object *m_pButton;
*/
bool isCheckable() const;
+ /**
+ * @brief Compare two items
+ * @param[in] item for compare
+ * @return true if items is same, false otherwise
+ */
+ bool isSame(const ListItem &item) const;
+
protected:
virtual std::string getText(ListItem &item, const char *part);
virtual Evas_Object *getContent(ListItem &item, const char *part);
SelectButton(Evas_Object *parent);
Evas_Object *getInnerButton() const;
void showButton(bool show);
+ void setText(const std::string &text);
private:
Evas_Object *m_pButton;
inline SelectCtxPopup::SelectCtxPopup()
: CtxPopup()
+ , m_pTopItem(nullptr)
+ , m_pBottomItem(nullptr)
{
setStyle("select_mode");
}
View::setText(m_pButton, text);
}
+void BottomButton::disabled(bool value)
+{
+ elm_object_disabled_set(m_pButton, value);
+}
void CtxPopup::on_item_pressed_cb(void *data, Evas_Object *obj, void *event_info)
{
auto *item = static_cast<CtxPopupItem*>(data);
- if (item && item->m_pUserCb)
- item->m_pUserCb(*item, item->m_pUserData);
+ if (item) {
+ if (item->m_pUserCb)
+ item->m_pUserCb(*item, item->m_pUserData);
+ item->getParent().destroy();
+ }
}
void CtxPopup::align(Window &win)
Evas_Coord w = 0;
Evas_Coord h = 0;
evas_object_geometry_get(obj, &x, &y, &w, &h);
- evas_object_move(getEo(), x + (w / 2), y + (h /2));
+ evas_object_move(getEo(), x + (w / 2), y + (h / 2));
}
return self.getCheckPart(self) != nullptr;
}
+bool ListItem::isSame(const ListItem &item) const
+{
+ return item.getElmObjItem() == getElmObjItem();
+}
+
void ListItem::onCheckChanged(Evas_Object *obj, void *eventInfo)
{
m_Checked = elm_check_state_get(obj);
{
return obj ? static_cast<ListItem*>(elm_object_item_data_get(obj)) : nullptr;
}
+
+ inline int normalizeCmpValue(int value)
+ {
+ if (value > 0)
+ return 1;
+ if (value < 0)
+ return -1;
+ return 0;
+ }
}
// ListView:
ListItem *item1 = (ListItem*)elm_object_item_data_get((Elm_Object_Item*)data1);
ListItem *item2 = (ListItem*)elm_object_item_data_get((Elm_Object_Item*)data2);
if (item1->m_pOwner->m_CmpFunc)
- res = item1->m_pOwner->m_CmpFunc(*item1, *item2);
-
+ res = normalizeCmpValue(item1->m_pOwner->m_CmpFunc(*item1, *item2));
return res;
},
on_item_selected_cb,
const char *sig = show ? "select_mode,button,show" : "select_mode,button,hide";
emitSignal(sig);
}
+
+void SelectButton::setText(const std::string &text)
+{
+ View::setText(m_pButton, text);
+}
void prepareMainLayout();
void prepareMoreOption();
void prepareDeleteViews();
+ void updateDeleteViews();
void setMode(Mode mode);
void setDeleteMode(bool value);
#include "ContactManager.h"
#include "SystemSettingsManager.h"
#include "ThreadComposeListViewItem.h"
+#include "PaddingListViewItem.h"
#include "MsgTypes.h"
+
#include <set>
namespace Msg {
void setDeleteMode(bool value);
bool isDeleteModeEnabled() const;
void deleteSelectedItems();
- int getThreadsCheckedCount() const;
+ unsigned getThreadsCheckedCount() const;
+ unsigned getCheckableItemsCount() const;
private:
// IMsgStorageListener:
void navigateTo(ThreadListItem &item);
ThreadListItem *getItem(ThreadId id) const;
bool isAllThreadListItemChecked() const;
- void updateSelectAllItem();
std::set<ThreadId> getThreadIdSet(const MsgIdList &idList);
static int cmpFunc(const ListItem &item1, const ListItem &item2);
App &m_App;
bool m_DeleteMode;
ThreadComposeListViewItem *m_ComposeItem;
+ PaddingListViewItem *m_pTopPadItem;
+ PaddingListViewItem *m_pBottomPadItem;
};
class IThreadListListener {
MSG_LOG("");
prepareMainLayout();
prepareMoreOption();
- prepareDeleteViews();
prepareThreadList();
setMode(NormalMode);
}
m_Mode = NormalMode;
m_pLayout->showMoreOption(true);
m_pLayout->showBottomButton(false);
- m_pSelectButton->showButton(false);
+ if (m_pSelectButton)
+ m_pSelectButton->showButton(false);
m_pThreadList->setDeleteMode(false);
}
void MsgThreadFrame::setDeleteMode(bool value)
{
MSG_LOG("");
- m_Mode = DeleteMode;
- m_pLayout->showBottomButton(true);
- m_pLayout->showMoreOption(false);
- m_pSelectButton->showButton(true);
- m_pThreadList->setDeleteMode(true);
+ if (m_Mode != DeleteMode) {
+ prepareDeleteViews();
+ m_Mode = DeleteMode;
+ m_pSelectButton->setText("0");
+ m_pSelectButton->showButton(true);
+ m_pDeleteButton->disabled(true);
+ m_pLayout->showBottomButton(true);
+ m_pLayout->showMoreOption(false);
+ m_pThreadList->setDeleteMode(true);
+ }
}
void MsgThreadFrame::prepareThreadList()
}
}
+void MsgThreadFrame::updateDeleteViews()
+{
+ if (m_Mode == DeleteMode) {
+ int count = m_pThreadList->getThreadsCheckedCount();
+ m_pSelectButton->setText(std::to_string(count));
+ m_pDeleteButton->disabled(count <= 0);
+ }
+}
+
void MsgThreadFrame::showSelectPopup()
{
auto *ctx = new SelectCtxPopup;
- ctx->appendTopItem("Select all", makeCbLast(&MsgThreadFrame::onSelectAllButtonClicked), this);
- ctx->appendBottomItem("Deselect all", makeCbLast(&MsgThreadFrame::onDeselectAllButtonClicked), this);
+ int checkedCount = m_pThreadList->getThreadsCheckedCount();
+ int checkableCount = m_pThreadList->getCheckableItemsCount();
+
+ if (checkedCount < checkableCount)
+ ctx->appendTopItem("Select all", makeCbLast(&MsgThreadFrame::onSelectAllButtonClicked), this);
+ if (checkedCount > 0)
+ ctx->appendBottomItem("Deselect all", makeCbLast(&MsgThreadFrame::onDeselectAllButtonClicked), this);
+
if (m_pSelectButton)
ctx->align(m_pSelectButton->getInnerButton());
+
ctx->go();
}
{
MSG_LOG("");
ToastPopup::toast(msgt("IDS_MSG_BUTTON_DELETE_ABB4"), DELETEG_MORE_ICON);
+ m_pThreadList->deleteSelectedItems();
+ setNormalMode(true);
}
void MsgThreadFrame::onSelectButtonClicked(Evas_Object *obj, void *event)
void MsgThreadFrame::onSelectAllButtonClicked(CtxPopupItem &item)
{
MSG_LOG("");
+ m_pThreadList->checkAllItems(true);
+ updateDeleteViews();
}
void MsgThreadFrame::onDeselectAllButtonClicked(CtxPopupItem &item)
{
MSG_LOG("");
+ m_pThreadList->checkAllItems(false);
+ updateDeleteViews();
}
void MsgThreadFrame::onNewMessageClicked(MoreOption &obj)
void MsgThreadFrame::onThreadListChanged()
{
MSG_LOG("");
+ updateDeleteViews();
}
void MsgThreadFrame::onThreadListItemChecked()
{
MSG_LOG("");
+ updateDeleteViews();
}
void MsgThreadFrame::onComposeButtonClicked()
, m_App(App::getInst())
, m_DeleteMode(false)
, m_ComposeItem(nullptr)
+ , m_pTopPadItem(nullptr)
+ , m_pBottomPadItem(nullptr)
{
ListView::setListener(this);
ListView::setHomogeneous(false);
}
}
-int ThreadList::getThreadsCheckedCount() const
+unsigned ThreadList::getThreadsCheckedCount() const
{
auto items = getItems<ThreadListItem>();
- int count = 0;
+ unsigned count = 0;
for (ThreadListItem *item : items) {
if (item->isCheckable() && item->getCheckedState())
++count;
return count;
}
+unsigned ThreadList::getCheckableItemsCount() const
+{
+ auto items = getItems();
+ unsigned count = 0;
+ for (ListItem *item : items) {
+ if (item->isCheckable())
+ ++count;
+ }
+ return count;
+}
+
bool ThreadList::isAllThreadListItemChecked() const
{
// Simple impl. but not fast:
return true;
}
-void ThreadList::updateSelectAllItem()
-{
- if (!m_DeleteMode)
- return;
-
- // bool allChecked = isAllThreadListItemChecked();
-}
void ThreadList::checkHandler(ThreadListItem &item)
{
ThreadId threadId = item.getThreadId();
MSG_LOG("Checked (id : state) = ", threadId, ":", item.getCheckedState());
- updateSelectAllItem();
if (m_pListener)
m_pListener->onThreadListItemChecked();
}
if (!isTh1 && !isTh2)
return 0;
- if (!isTh1 || !isTh2)
- return !isTh1;
+ if (isTh2) {
+ auto *self = static_cast<ThreadList*>(item1.getOwner());
+ return self->m_pBottomPadItem->isSame(item1) ? 1 : -1;
+ }
auto &threadItem1 = static_cast<const ThreadListItem&>(item1);
auto &threadItem2 = static_cast<const ThreadListItem&>(item2);
void ThreadList::fillList()
{
// Top padding:
- ListView::appendItem(*new PaddingListViewItem);
+ m_pTopPadItem = new PaddingListViewItem;
+ ListView::appendItem(*m_pTopPadItem);
// Compose Item:
m_ComposeItem = new ThreadComposeListViewItem;
}
// Bottom padding:
- ListView::appendItem(*new PaddingListViewItem);
+ m_pBottomPadItem = new PaddingListViewItem;
+ ListView::appendItem(*m_pBottomPadItem);
}
void ThreadList::deleteItems()
if (threadIdSet.count(item->getThreadId()) == 0)
ListView::deleteItem(*item);
}
-
- updateSelectAllItem();
}
void ThreadList::navigateTo(ThreadListItem &item)
{
MSG_LOG("");
insertItem(threadId);
- updateSelectAllItem();
if (m_pListener)
m_pListener->onThreadListChanged();
}
{
MSG_LOG("");
auto* thread = getItem(threadId);
- if (thread) {
+ if (thread)
ListView::deleteItem(*thread);
- updateSelectAllItem();
- }
if (m_pListener)
m_pListener->onThreadListChanged();