Commit 098d6f10 authored by Camilo higuita's avatar Camilo higuita

ui fixes

parent 93e5d3f2
......@@ -18,6 +18,9 @@ void AndroidIntents::init()
this->mauia = new MAUIAndroid(this);
}
AndroidIntents *AndroidIntents::instance = nullptr;
AndroidIntents *AndroidIntents::getInstance()
......@@ -25,126 +28,142 @@ AndroidIntents *AndroidIntents::getInstance()
if(!instance)
{
instance = new AndroidIntents();
qDebug() << "getInstance(): First AndroidIntents instance\n";
qDebug() << "getInstance(AndroidIntents): First AndroidIntents instance\n";
instance->init();
return instance;
} else
{
qDebug()<< "getInstance(): previous AndroidIntents instance\n";
qDebug()<< "getInstance(AndroidIntents): previous AndroidIntents instance\n";
return instance;
}
}
void AndroidIntents::call(const QString &tel)
void AndroidIntents::call(const QString &tel) const
{
this->mauia->call(tel);
}
void AndroidIntents::contacts()
{
QFutureWatcher<FMH::MODEL_LIST> *watcher = new QFutureWatcher<FMH::MODEL_LIST>;
connect(watcher, &QFutureWatcher<FMH::MODEL_LIST>::finished, [this, watcher]()
void AndroidIntents::addContact(const FMH::MODEL &contact, const FMH::MODEL &account) const
{
qDebug() << "ADDING CONTACT TO ACCOUNT" << contact << account;
this->mauia->addContact(contact[FMH::MODEL_KEY::N],
contact[FMH::MODEL_KEY::TEL],
contact[FMH::MODEL_KEY::TEL_2],
contact[FMH::MODEL_KEY::TEL_3],
contact[FMH::MODEL_KEY::EMAIL],
contact[FMH::MODEL_KEY::TITLE],
contact[FMH::MODEL_KEY::ORG],
contact[FMH::MODEL_KEY::PHOTO],
account[FMH::MODEL_KEY::ACCOUNT],
account[FMH::MODEL_KEY::TYPE]);
}
FMH::MODEL_LIST AndroidIntents::getAccounts(const GET_TYPE &type)
{
if(type == GET_TYPE::CACHED)
{
auto contacts = watcher->future().result();
this->m_contacts = contacts;
emit this->contactsReady();
});
if(!m_accounts.isEmpty())
return this->m_accounts;
else
this->fetchAccounts();
QFuture<FMH::MODEL_LIST> t1 = QtConcurrent::run(AndroidIntents::fetchContacts);
watcher->setFuture(t1);
}else if(type == GET_TYPE::FETCH)
return this->fetchAccounts();
}
FMH::MODEL_LIST AndroidIntents::fetchContacts()
void AndroidIntents::getContacts(const GET_TYPE &type)
{
FMH::MODEL_LIST data;
auto list = MAUIAndroid::getContacts();
for(auto item : list)
data << FM::toModel(item.toMap());
if(type == GET_TYPE::CACHED)
{
if(!this->m_contacts.isEmpty())
emit this->contactsReady(this->m_contacts);
else
this->fetchContacts();
return data;
}else if(type == GET_TYPE::FETCH)
this->fetchContacts();
}
void AndroidIntents::addContact(const FMH::MODEL &contact, const FMH::MODEL &account)
QVariantMap AndroidIntents::getContact(const QString &id) const
{
qDebug() << "ADDING CONTACT TO ACCOUNT" << contact << account;
// this->mauia->addContact(contact[FMH::MODEL_KEY::N],
// contact[FMH::MODEL_KEY::TEL],
// contact[FMH::MODEL_KEY::TEL_2],
// contact[FMH::MODEL_KEY::TEL_3],
// contact[FMH::MODEL_KEY::EMAIL],
// contact[FMH::MODEL_KEY::TITLE],
// contact[FMH::MODEL_KEY::ORG],
// contact[FMH::MODEL_KEY::PHOTO],
// account[FMH::MODEL_KEY::ACCOUNT],
// account[FMH::MODEL_KEY::TYPE]);
return this->mauia->getContact(id);
}
FMH::MODEL_LIST AndroidIntents::getAccounts() const
void AndroidIntents::updateContact(const QString &id, const QString &field, const QString &value) const
{
return this->m_accounts;
this->mauia->updateContact(id, field, value);
}
FMH::MODEL_LIST AndroidIntents::getContacts() const
{
return this->m_contacts;
}
void AndroidIntents::updateContact(const QString &id, const QString &field, const QString &value)
{
// this->mauia->updateContact(id, field, value);
}
void AndroidIntents::fetch()
void AndroidIntents::fetchContacts()
{
// this->m_accounts = this->accounts();
this->contacts();
QFutureWatcher<FMH::MODEL_LIST> *watcher = new QFutureWatcher<FMH::MODEL_LIST>;
connect(watcher, &QFutureWatcher<FMH::MODEL_LIST>::finished, [=]()
{
this->m_contacts = watcher->future().result();
emit this->contactsReady(this->m_contacts);
watcher->deleteLater();
});
const auto func = []() -> FMH::MODEL_LIST
{
FMH::MODEL_LIST data;
auto list = MAUIAndroid::getContacts();
for(auto item : list)
data << FM::toModel(item.toMap());
return data;
};
QFuture<FMH::MODEL_LIST> t1 = QtConcurrent::run(func);
watcher->setFuture(t1);
}
FMH::MODEL_LIST AndroidIntents::accounts()
FMH::MODEL_LIST AndroidIntents::fetchAccounts()
{
FMH::MODEL_LIST data;
// const auto array = this->mauia->getAccounts();
// QString xmlData(array);
// QDomDocument doc;
// if (!doc.setContent(xmlData)) return data;
const auto array = this->mauia->getAccounts();
QString xmlData(array);
QDomDocument doc;
// const QDomNodeList nodeList = doc.documentElement().childNodes();
if (!doc.setContent(xmlData)) return data;
// for (int i = 0; i < nodeList.count(); i++)
// {
// QDomNode n = nodeList.item(i);
const QDomNodeList nodeList = doc.documentElement().childNodes();
// if(n.nodeName() == "account")
// {
// FMH::MODEL model;
// auto contact = n.toElement().childNodes();
for (int i = 0; i < nodeList.count(); i++)
{
QDomNode n = nodeList.item(i);
// for(int i=0; i < contact.count(); i++)
// {
// const QDomNode m = contact.item(i);
if(n.nodeName() == "account")
{
FMH::MODEL model;
auto contact = n.toElement().childNodes();
// if(m.nodeName() == "name")
// {
// const auto account = m.toElement().text();
// model.insert(FMH::MODEL_KEY::ACCOUNT, account);
for(int i=0; i < contact.count(); i++)
{
const QDomNode m = contact.item(i);
// }else if(m.nodeName() == "type")
// {
// const auto type = m.toElement().text();
// model.insert(FMH::MODEL_KEY::TYPE, type);
if(m.nodeName() == "name")
{
const auto account = m.toElement().text();
model.insert(FMH::MODEL_KEY::ACCOUNT, account);
// }
// }
}else if(m.nodeName() == "type")
{
const auto type = m.toElement().text();
model.insert(FMH::MODEL_KEY::TYPE, type);
// data << model;
// }
// }
}
}
data << model;
}
}
return data;
}
......@@ -9,53 +9,41 @@ class AndroidIntents : public QObject
{
Q_OBJECT
public:
enum GET_TYPE : uint_fast8_t
{
CACHED,
FETCH
};
static AndroidIntents *getInstance();
// explicit AndroidIntents(QObject *parent = nullptr);
void call(const QString &tel) const;
/**
* @brief call
* @param tel
*/
void call(const QString &tel);
/*!
* \brief init
*/
void init();
//!
//! \brief addContact
//! \param contact
//! \param account
//!
void addContact(const FMH::MODEL &contact, const FMH::MODEL &account);
FMH::MODEL_LIST getAccounts() const;
FMH::MODEL_LIST getContacts() const;
void updateContact(const QString &id, const QString &field, const QString &value);
void fetch();
void addContact(const FMH::MODEL &contact, const FMH::MODEL &account) const;
FMH::MODEL_LIST getAccounts(const GET_TYPE &type = GET_TYPE::CACHED);
void getContacts(const GET_TYPE &type = GET_TYPE::CACHED);
QVariantMap getContact(const QString &id) const;
void updateContact(const QString &id, const QString &field, const QString &value) const;
private:
explicit AndroidIntents(QObject *parent = nullptr);
void init();
static AndroidIntents *instance;
MAUIAndroid *mauia;
FMH::MODEL_LIST m_accounts;
FMH::MODEL_LIST m_contacts;
///
/// \brief accounts
/// \return
///
FMH::MODEL_LIST accounts();
void contacts();
FMH::MODEL_LIST m_contacts;
FMH::MODEL_LIST m_accounts;
///
/// \brief fetchContacts
/// \return
///
static FMH::MODEL_LIST fetchContacts();
void fetchContacts();
FMH::MODEL_LIST fetchAccounts();
signals:
void contactsReady();
void contactsReady(FMH::MODEL_LIST contacts) const;
public slots:
};
......
......@@ -38,7 +38,7 @@ kcontactsinterface::kcontactsinterface(QObject *parent) : QObject(parent)
// this->addContact("Daniel", "3298373843");
}
FMH::MODEL_LIST kcontactsinterface::getContacts(const QString &query)
FMH::MODEL_LIST kcontactsinterface::getContacts()
{
FMH::MODEL_LIST res;
......
......@@ -33,7 +33,7 @@ class kcontactsinterface : public QObject
Q_OBJECT
public:
explicit kcontactsinterface(QObject *parent = nullptr);
FMH::MODEL_LIST getContacts(const QString &query);
FMH::MODEL_LIST getContacts();
private:
const QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ ("/kpeoplevcard");
......
#include "synchroniser.h"
#include "./../db/dbactions.h"
#include <QtConcurrent>
#include <QtConcurrent/QtConcurrentRun>
#include <QFuture>
......@@ -19,20 +18,11 @@ extern void test()
Synchroniser::Synchroniser(QObject *parent) : QObject (parent)
{
this->dba = DBActions::getInstance();
#ifdef Q_OS_ANDROID
qDebug()<< "trying to insert contact to android api";
this->android = AndroidIntents::getInstance();
connect(android, &AndroidIntents::contactsReady, [this]()
connect(android, &AndroidIntents::contactsReady, [this](FMH::MODEL_LIST contacts)
{
const auto contacts = this->android->getContacts();
qDebug()<< "CONTACTS READY "<< contacts;
// this->dba->removeAll();
// for(auto contact : contacts)
// this->dba->insertContact(contact);
emit this->contactsReady(contacts);
});
......@@ -40,26 +30,32 @@ Synchroniser::Synchroniser(QObject *parent) : QObject (parent)
}
FMH::MODEL_LIST Synchroniser::getContacts(const QString &query)
void Synchroniser::getContacts(const bool &cached)
{
FMH::MODEL_LIST data /*=this->dba->getDBData(query)*/;
#ifdef Q_OS_ANDROID
// data << this->dba->getDBData(query);
this->android->fetch();
this->android->getContacts(cached ? AndroidIntents::GET_TYPE::CACHED : AndroidIntents::GET_TYPE::FETCH);
#else
kcontactsinterface kcontacts;
data << kcontacts.getContacts("");
emit this->contactsReady(kcontacts.getContacts());
#endif
return data;
}
FMH::MODEL_LIST Synchroniser::getAccounts()
FMH::MODEL_LIST Synchroniser::getAccounts(const bool &cached)
{
FMH::MODEL_LIST res;
#ifdef Q_OS_ANDROID
res = this->android->getAccounts();
res = this->android->getAccounts(cached ? AndroidIntents::GET_TYPE::CACHED : AndroidIntents::GET_TYPE::FETCH);
return res;
#endif
return res;
}
QVariantMap Synchroniser::getContact(const QString &id)
{
QVariantMap res;
#ifdef Q_OS_ANDROID
res = this->android->getContact(id);
return res;
#endif
......@@ -95,6 +91,7 @@ bool Synchroniser::updateContact(const FMH::MODEL &contact)
bool Synchroniser::removeContact(const FMH::MODEL &contact)
{
return this->dba->removeContact(contact[FMH::MODEL_KEY::ID]);
// return this->dba->removeContact(contact[FMH::MODEL_KEY::ID]);
return true;
}
......@@ -12,15 +12,16 @@
class AndroidIntents;
#endif
class DBActions;
class Synchroniser : public QObject
{
Q_OBJECT
public:
explicit Synchroniser(QObject *parent = nullptr);
FMH::MODEL_LIST getContacts(const QString &query);
FMH::MODEL_LIST getAccounts();
void getContacts(const bool &cached = false);
FMH::MODEL_LIST getAccounts(const bool &cached = false);
QVariantMap getContact(const QString &id);
bool insertContact(const FMH::MODEL &contact, const FMH::MODEL &account = {{}});
bool updateContact(const FMH::MODEL &contact);
bool removeContact(const FMH::MODEL &contact);
......@@ -29,8 +30,6 @@ public:
// FMH::MODEL_LIST getAccounts() const;
private:
DBActions *dba;
#ifdef Q_OS_ANDROID
AndroidIntents *android;
#endif
......
......@@ -17,44 +17,65 @@ Maui.ApplicationWindow
property int currentView : views.contacts
readonly property var views : ({
contacts : 0,
favs: 0,
dialer: 1,
favs: 2,
recent: 3,
contacts : 2
})
/** UI PROPS**/
bgColor: "#1f2532"
highlightColor: "#ff6a83"
backgroundColor: bgColor
textColor: "#fafafa"
viewBackgroundColor: "#1e2431"
accentColor: "#3c4862"
property color cardColor: darkTheme ? "#4f5160" : Qt.darker(Maui.Style.buttonBackgroundColor, 1.05)
bgColor: darkTheme ? "#1f2532" : Maui.Style.backgroundColor
highlightColor: darkTheme ? "#ff6a83" : Maui.Style.highlightColor
backgroundColor: darkTheme ? bgColor : Maui.Style.backgroundColor
textColor: darkTheme ? "#fafafa" : Maui.Style.textColor
viewBackgroundColor: darkTheme ? "#1e2431" : Maui.Style.viewBackgroundColor
accentColor: darkTheme ? "#3c4862" : Maui.Style.highlightColor
altToolBars: false
leftIcon.iconColor: footBar.visible ? highlightColor : textColor
// onSearchButtonClicked: footBar.visible = !footBar.visible
leftIcon.visible: false
leftIcon.visible: true
rightIcon.visible: false
headBar.implicitHeight: toolBarHeight * 1.2
headBar.drawBorder: false
headBarBGColor: backgroundColor
headBarFGColor: textColor
property bool darkTheme : Maui.FM.loadSettings("dark", "theme", true) == "true"
mainMenu: [
Maui.MenuItem
{
checkable: true
text: qsTr("Dark theme");
checked: darkTheme
onTriggered:
{
darkTheme = !darkTheme
Maui.FM.saveSettings("dark", darkTheme, "theme")
if(isAndroid)
Maui.Android.statusbarColor(backgroundColor, !darkTheme)
}
}
]
headBar.middleContent: [
Maui.ToolButton
{
id: _contactsButton
id: _favsButton
Layout.fillWidth: isMobile
Layout.alignment: Qt.AlignCenter
iconName: "draw-star"
Layout.fillHeight: true
iconName: "view-media-artist"
iconColor: currentView === views.contacts ? highlightColor : textColor
// text: qsTr("Contacts")
// height: parent.height
showIndicator: currentView === views.contacts
onClicked: currentView = views.contacts
iconColor: currentView === views.favs ? highlightColor : textColor
// text: qsTr("Favorites")
showIndicator: currentView === views.favs
onClicked: currentView = views.favs
},
......@@ -62,47 +83,35 @@ Maui.ApplicationWindow
{
id: _dialerButton
Layout.fillWidth: isMobile
Layout.alignment: Qt.AlignCenter
iconName: "view-list-icons"
Layout.fillHeight: true
iconColor: currentView === views.dialer ? highlightColor : textColor
// text: qsTr("Dialer")
// text: qsTr("Dialer")
// visible: isAndroid
showIndicator: currentView === views.dialer
onClicked: currentView = views.dialer
},
Maui.ToolButton
{
id: _favsButton
Layout.fillWidth: isMobile
id: _contactsButton
Layout.alignment: Qt.AlignCenter
iconName: "draw-star"
Layout.fillWidth: isMobile
Layout.fillHeight: true
iconColor: currentView === views.favs ? highlightColor : textColor
// text: qsTr("Favorites")
showIndicator: currentView === views.favs
onClicked: currentView = views.favs
iconName: "view-media-artist"
iconColor: currentView === views.contacts ? highlightColor : textColor
// text: qsTr("Contacts")
// height: parent.height
showIndicator: currentView === views.contacts
onClicked: currentView = views.contacts
}
// Maui.ToolButton
// {
// id: _recentButton
// Layout.fillWidth: isMobile && visible
// visible: (isAndroid && Maui.Handy.version() < 7)
// iconName: "view-media-recent"
// Layout.fillHeight: isMobile && visible
// iconColor: currentView === views.recent ? highlightColor : textColor
// // text: qsTr("Recent")
// // visible: isAndroid
// showIndicator: currentView === views.recent
// }
]
]
SwipeView
{
......@@ -117,30 +126,52 @@ Maui.ApplicationWindow
_contacsView.list.query = _dialerView.dialString
}
ContactsView
{
id: _favsView
list.query : "fav=1"
headBar.visible: false
}
DialerView
{
id: _dialerView
}
ContactsView
{
id: _contacsView
list.query: ""
altToolBars: isMobile
floatingBar: true
footBarMargins: space.huge
footBarAligment: Qt.AlignRight
footBar.middleContent: Maui.ToolButton
showAccountFilter: isAndroid
Rectangle
{
iconName: "list-add-user"
iconColor: "white"
onClicked: _newContactDialog.open()
anchors.right: parent.right
anchors.bottom: parent.bottom
height: toolBarHeight
width: height
color: highlightColor
radius: radiusV
Maui.ToolButton
{
anchors.centerIn: parent
iconName: "list-add-user"
iconColor: "white"
onClicked: _newContactDialog.open()
}
}
footBar.colorScheme.borderColor: "transparent"
headBarExit: false
headBar.drawBorder: false
footBar.drawBorder: false
footBar.floating: false
footBar.colorScheme.backgroundColor: highlightColor
headBar.implicitHeight: toolBarHeight * 1.4
headBar.plegable: false
headBarItem: Maui.TextField
{