Commit 6751b6b3 authored by Camilo higuita's avatar Camilo higuita

now fetches andorid conatcts and can make phone clals via intents

parent 6868175d
#include "androidintents.h"
#include "./mauikit/src/android/mauiandroid.h"
#include <QDomDocument>
AndroidIntents::AndroidIntents(QObject *parent) : QObject(parent)
{
this->mauia = new MAUIAndroid(this);
}
void AndroidIntents::call(const QString &tel)
{
this->mauia->call(tel);
}
FMH::MODEL_LIST AndroidIntents::getContacts()
{
FMH::MODEL_LIST data;
const auto array = mauia->getContacts();
QString xmlData(array);
QDomDocument doc;
if (!doc.setContent(xmlData)) return data;
const QDomNodeList nodeList = doc.documentElement().childNodes();
for (int i = 0; i < nodeList.count(); i++)
{
QDomNode n = nodeList.item(i);
if(n.nodeName() == "item")
{
FMH::MODEL model;
auto contact = n.toElement().childNodes();
for(int i=0; i < contact.count(); i++)
{
const QDomNode m = contact.item(i);
if(m.nodeName() == "n")
{
const auto name = m.toElement().text();
model.insert(FMH::MODEL_KEY::N, name);
}else if(m.nodeName() == "tel")
{
const auto tel = m.toElement().text();
model.insert(FMH::MODEL_KEY::TEL, tel);
}else if(m.nodeName() == "email")
{
const auto email = m.toElement().text();
model.insert(FMH::MODEL_KEY::EMAIL, email);
}
}
data << model;
}
}
return data;
}
......@@ -2,16 +2,24 @@
#define ANDROIDINTENTS_H
#include <QObject>
#include "fmh.h"
class MAUIAndroid;
class AndroidIntents : public QObject
{
Q_OBJECT
public:
explicit AndroidIntents(QObject *parent = nullptr);
void call(const QString &tel);
FMH::MODEL_LIST getContacts();
private:
MAUIAndroid *mauia;
signals:
public slots:
};
#endif // ANDROIDINTENTS_H
\ No newline at end of file
#endif // ANDROIDINTENTS_H
#include "contactsmodel.h"
#include "./src/interfaces/synchroniser.h"
#ifdef Q_OS_ANDROID
#include "./src/interfaces/androidintents.h"
#endif
ContactsModel::ContactsModel(QObject *parent) : BaseList(parent)
{
this->syncer = new Synchroniser(this);
......@@ -110,6 +114,12 @@ void ContactsModel::setList()
emit this->preListChanged();
this->list = this->syncer->getContacts(this->query);
#ifdef Q_OS_ANDROID
AndroidIntents android;
this->list << android.getContacts();
#endif
this->sortList();
emit this->postListChanged();
}
......@@ -185,6 +195,25 @@ bool ContactsModel::remove(const int &index)
return false;
}
void ContactsModel::filter(const QString &query)
{
FMH::MODEL_LIST res;
for(const auto item : this->list)
{
for(const auto data : item)
{
if(data.contains(query, Qt::CaseInsensitive))
res << item;
}
}
emit this->preListChanged();
this->list = res;
emit this->postListChanged();
}
void ContactsModel::append(const QVariantMap &item)
{
if(item.isEmpty())
......@@ -246,3 +275,8 @@ void ContactsModel::clear()
emit this->postListChanged();
}
void ContactsModel::reset()
{
this->setList();
}
......@@ -60,11 +60,13 @@ public slots:
bool insert(const QVariantMap &map) override;
bool update(const QVariantMap &map, const int &index) override;
bool remove(const int &index);
void filter(const QString &query);
void append(const QVariantMap &item, const int &at);
void append(const QVariantMap &item);
void appendQuery(const QString &query);
void clear();
void reset();
};
......
......@@ -18,6 +18,42 @@ Maui.Dialog
rejectButton.visible: false
onAccepted: _editContactDialog.open()
headBar.implicitHeight: toolBarHeight * 1.3
headBar.middleContent: [
Maui.ToolButton
{
iconName: "phone"
text: qsTr("Call...")
display: ToolButton.TextUnderIcon
onClicked:
{
if(isAndroid)
Maui.Android.call(contact.tel)
}
},
Maui.ToolButton
{
iconName: "draw-text"
text: qsTr("Message...")
display: ToolButton.TextUnderIcon
},
Maui.ToolButton
{
iconName: "draw-star"
text: qsTr("Fav...")
display: ToolButton.TextUnderIcon
},
Maui.ToolButton
{
iconName: "document-share"
text: qsTr("Share...")
display: ToolButton.TextUnderIcon
}
]
EditContactDialog
{
id: _editContactDialog
......@@ -137,42 +173,6 @@ Maui.Dialog
}
}
Maui.ToolBar
{
Layout.fillWidth: true
Layout.margins: space.big
Layout.preferredHeight: toolBarHeight
colorScheme.backgroundColor: " transparent"
middleContent: [
Maui.ToolButton
{
iconName: "phone"
text: qsTr("Call...")
display: ToolButton.TextUnderIcon
},
Maui.ToolButton
{
iconName: "draw-text"
text: qsTr("Message...")
display: ToolButton.TextUnderIcon
},
Maui.ToolButton
{
iconName: "draw-star"
text: qsTr("Fav...")
display: ToolButton.TextUnderIcon
},
Maui.ToolButton
{
iconName: "document-share"
text: qsTr("Share...")
display: ToolButton.TextUnderIcon
}
]
}
Item
{
......@@ -183,6 +183,7 @@ Maui.Dialog
{
anchors.fill: parent
contentHeight: _formLayout.implicitHeight
contentWidth: _formLayout.width
clip: true
ColumnLayout
{
......
......@@ -55,6 +55,8 @@ Maui.Page
width: footBar.middleLayout.width * 0.7
// height: rowHeight
placeholderText: qsTr("Search contacts... ")
onAccepted: list.filter(text)
onCleared: list.reset()
}
BaseModel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment