#define CONTACTS_LIST_MANAGE_FAVORITES_POPUP_H
#include "Ui/ListPopup.h"
+#include "Ux/SelectTypes.h"
namespace Ui
{
{
namespace List
{
+ class ListSection;
+
/**
- * @brief The popup provides ability to add/reorder favorites and
- * remove most frequent and favorites contacts
+ * @brief The popup provides ability to add/remove/reorder favorites and
+ * most frequent contacts.
*/
class ManageFavoritesPopup : public Ui::ListPopup
{
public:
/**
- * @brief Notifies that Mfc contacts were updated
- */
- typedef std::function<void()> MfcUpdateCallback;
-
- /**
- * @brief Notifies that Favorites contact was reordered
- * @param[in] Id of the favorite contact that was reordered
- * @param[in] Id of the previous contact
- */
- typedef std::function<void(int, int)> ReorderCallback;
-
- /**
- * @brief Creates new popup
+ * @brief Creates popup.
* @param[in] navigator Current navigator. Is needed to move to the next view.
+ * @param[in] favSection Favorites list section
+ * @param[in] mfcSection Most frequent contacts list section
*/
- ManageFavoritesPopup(Ui::Navigator *navigator);
-
- /**
- * @brief Set Mfc update callback
- * @param[in] callback Mfc update callback
- */
- void setMfcUpdateCallback(MfcUpdateCallback callback);
-
- /**
- * @brief Set favorites reorder callback
- * @param[in] callback Favorites reorder callback
- */
- void setReorderCallback(ReorderCallback callback);
+ ManageFavoritesPopup(Ui::Navigator *navigator,
+ ListSection *favSection, ListSection *mfcSection);
protected:
/**
virtual void onCreated() override;
private:
- ManageFavoritesPopup(const ManageFavoritesPopup &that) = delete;
- ManageFavoritesPopup & operator=(const ManageFavoritesPopup &that) = delete;
-
void onAddSelected();
void onReorderSelected();
void onRemoveSelected();
static void addFavorites(Ux::SelectResults results);
- static void removeFavorites(Ux::SelectResults results, MfcUpdateCallback callback);
+ static void removeFavorites(Ux::SelectResults results);
Ui::Navigator *m_Navigator;
- MfcUpdateCallback m_OnMfcUpdated;
- ReorderCallback m_OnFavoritesReordered;
+ ListSection *m_FavSection;
+ ListSection *m_MfcSection;
};
}
}
menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
if (!m_IsSearching) {
- menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB",
- std::bind(&ListView::onManageFavoritesSelected, this));
+ menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB", [this] {
+ auto popup = new ManageFavoritesPopup(getNavigator(),
+ static_cast<ListSection *>(m_Sections[SectionFavorites].m_Item),
+ static_cast<ListSection *>(m_Sections[SectionMfc].m_Item));
+ popup->create(getEvasObject());
+ });
}
}
return false;
}
-void ListView::onManageFavoritesSelected()
-{
- auto manageFavPopup = new ManageFavoritesPopup(getNavigator());
-
- manageFavPopup->setMfcUpdateCallback([this] {
- if (m_Sections[SectionMfc].m_Item) {
- static_cast<ListSection *>(m_Sections[SectionMfc].m_Item)->update();
- } else {
- createSection(SectionMfc);
- }
- });
- manageFavPopup->setReorderCallback( std::bind(&ListSection::reorderItem,
- static_cast<ListSection *>(m_Sections[SectionFavorites].m_Item), _1, _2));
- manageFavPopup->create(getEvasObject());
-}
-
void ListView::onSelectAllInsert(Ui::GenItem *item)
{
m_Genlist->insert(item, nullptr, m_SearchItem, Ui::Genlist::After);
*
*/
-#include "Common/Database/RecordIterator.h"
-#include "Common/Database/RecordUtils.h"
-#include "Contacts/List/ListView.h"
#include "Contacts/List/ManageFavoritesPopup.h"
+#include "Contacts/List/ListSection.h"
+#include "Contacts/List/ListView.h"
#include "Contacts/List/Model/FavoritesProvider.h"
#include "Contacts/List/RemoveFavView.h"
#include "Contacts/List/ReorderView.h"
+#include "Common/Database/RecordIterator.h"
+#include "Common/Database/RecordUtils.h"
+
#include "Ui/Navigator.h"
#include "Ui/ProcessPopup.h"
#include "Utils/Thread.h"
using namespace Common::Database;
using namespace Contacts::List;
using namespace Contacts::List::Model;
+using namespace std::placeholders;
-ManageFavoritesPopup::ManageFavoritesPopup(Ui::Navigator *navigator)
- : m_Navigator(navigator)
+ManageFavoritesPopup::ManageFavoritesPopup(Ui::Navigator *navigator,
+ ListSection *favSection, ListSection *mfcSection)
+ : m_Navigator(navigator), m_FavSection(favSection), m_MfcSection(mfcSection)
{
}
-void ManageFavoritesPopup::setMfcUpdateCallback(MfcUpdateCallback callback)
-{
- m_OnMfcUpdated = std::move(callback);
-}
-
-void ManageFavoritesPopup::setReorderCallback(ReorderCallback callback)
-{
- m_OnFavoritesReordered = std::move(callback);
-}
-
void ManageFavoritesPopup::onCreated()
{
ListPopup::onCreated();
-
setTitle("IDS_PB_HEADER_MANAGE_FAVOURITES_ABB");
-
- // todo Implement get list's size without retrieve of all fav persons from database
- FavoritesProvider provider;
- int count = provider.getDataList().size();
-
addItem("IDS_PB_OPT_ADD", std::bind(&ManageFavoritesPopup::onAddSelected, this));
- if (count > 0) {
+ size_t favCount = m_FavSection->getItemCount();
+ size_t mfcCount = m_MfcSection->getItemCount();
+ if (favCount > 0 || mfcCount > 0) {
addItem("IDS_PB_OPT_REMOVE", std::bind(&ManageFavoritesPopup::onRemoveSelected, this));
+ }
- if (count > 1) {
- addItem("IDS_PB_OPT_REORDER", std::bind(&ManageFavoritesPopup::onReorderSelected, this));
- }
+ if (favCount > 1) {
+ addItem("IDS_PB_OPT_REORDER", std::bind(&ManageFavoritesPopup::onReorderSelected, this));
}
}
void ManageFavoritesPopup::onReorderSelected()
{
ReorderView *view = new ReorderView();
- view->setItemReorderCallback(std::move(m_OnFavoritesReordered));
+ view->setItemReorderCallback(std::bind(&ListSection::reorderItem, m_FavSection, _1, _2));
m_Navigator->navigateTo(view);
}
void ManageFavoritesPopup::onRemoveSelected()
{
RemoveFavView *view = new RemoveFavView();
-
- //todo Implement separate controller to handle callback, because object is destroyed after popup close.
- auto &onMfcUpdated = m_OnMfcUpdated;
- view->setSelectCallback([view, onMfcUpdated](Ux::SelectResults results) {
+ ListSection *mfcSection = m_MfcSection;
+ view->setSelectCallback([view, mfcSection](Ux::SelectResults results) {
auto popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
- new Utils::Thread(std::bind(removeFavorites, std::move(results), std::move(onMfcUpdated)), [view, popup] {
+ new Utils::Thread(std::bind(removeFavorites, std::move(results)), [view, popup, mfcSection] {
+ mfcSection->update();
popup->close();
view->getPage()->close();
});
contacts_disconnect_on_thread();
}
-void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results, MfcUpdateCallback callback)
+void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results)
{
- bool isMfcUpdated = false;
contacts_list_h list = nullptr;
contacts_connect_on_thread();
contacts_list_create(&list);
contacts_record_set_bool(record, _contacts_person.is_favorite, false);
contacts_list_add(list, record);
} else {
- isMfcUpdated = true;
contacts_person_reset_usage(recordId, CONTACTS_USAGE_STAT_TYPE_OUTGOING_CALL);
contacts_person_reset_usage(recordId, CONTACTS_USAGE_STAT_TYPE_INCOMING_CALL);
contacts_record_destroy(record, true);
contacts_db_update_records(list);
contacts_list_destroy(list, true);
contacts_disconnect_on_thread();
-
- if (isMfcUpdated && callback) {
- callback();
- }
}