Skip to content

Commit

Permalink
Merge pull request #79 from dscheinah/master
Browse files Browse the repository at this point in the history
App store fixes
  • Loading branch information
abranson authored Jul 25, 2019
2 parents ad124f5 + fb873e2 commit c23677f
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 126 deletions.
23 changes: 23 additions & 0 deletions rockwork/applicationsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void ApplicationsModel::clear()
m_groupIcons.clear();
m_links.clear();
m_linkNames.clear();
m_linkQueries.clear();
m_linkPages.clear();
emit linksChanged();
emit changed();
}
Expand Down Expand Up @@ -176,6 +178,16 @@ QString ApplicationsModel::linkName(const QString &link) const
return m_linkNames.value(link);
}

QString ApplicationsModel::linkQuery(const QString &link) const
{
return m_linkQueries.value(link);
}

int ApplicationsModel::linkPage(const QString &link) const
{
return m_linkPages.value(link);
}

QStringList ApplicationsModel::links() const
{
return m_links;
Expand All @@ -185,6 +197,17 @@ void ApplicationsModel::addLink(const QString &link, const QString &name)
{
m_links.append(link);
m_linkNames[link] = name;
m_linkQueries[link] = "";
m_linkPages[link] = 0;
emit linksChanged();
}

void ApplicationsModel::addLink(const QString &link, const QString &name, const QString &query, const int page)
{
m_links.append(link);
m_linkNames[link] = name;
m_linkQueries[link] = query;
m_linkPages[link] = page;
emit linksChanged();
}

Expand Down
7 changes: 7 additions & 0 deletions rockwork/applicationsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ class ApplicationsModel : public QAbstractListModel
Q_INVOKABLE QString linkName(const QString &link) const;
void addLink(const QString &link, const QString &name);

// Added to enable pagination in searches. The QML page decides the correct call by reading the search page.
Q_INVOKABLE QString linkQuery(const QString &link) const;
Q_INVOKABLE int linkPage(const QString &link) const;
void addLink(const QString &link, const QString &name, const QString &query, const int page);

Q_INVOKABLE void move(int from, int to);
Q_INVOKABLE void commitMove();

Expand All @@ -194,6 +199,8 @@ class ApplicationsModel : public QAbstractListModel
QHash<QString, QString> m_groupIcons;
QStringList m_links;
QHash<QString, QString> m_linkNames;
QHash<QString, QString> m_linkQueries;
QHash<QString, int> m_linkPages;
};

#endif // APPLICATIONSMODEL_H
31 changes: 26 additions & 5 deletions rockwork/appstoreclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ void AppStoreClient::fetchHome(Type type)
}
QString slug = entry.toMap().value("slug").toString();
collections[slug] = appIds;
m_model->insertGroup(slug, entry.toMap().value("name").toString(), entry.toMap().value("links").toMap().value("apps").toString());
m_model->insertGroup(slug,
entry.toMap().value("name").toString(),
// Only the home page links are relative, so prepend here.
"https://appstore-api.rebble.io" + entry.toMap().value("links").toMap().value("apps").toString());
}

QHash<QString, QString> categoryNames;
Expand All @@ -124,7 +127,8 @@ void AppStoreClient::fetchHome(Type type)
if(m_enableCategories) {
m_model->insertGroup(entry.toMap().value("id").toString(),
entry.toMap().value("name").toString(),
entry.toMap().value("links").toMap().value("apps").toString(),
// Only the home page links are relative, so prepend here.
"https://appstore-api.rebble.io" + entry.toMap().value("links").toMap().value("apps").toString(),
entry.toMap().value("icon").toMap().value("88x88").toString());
}
}
Expand Down Expand Up @@ -273,6 +277,11 @@ void AppStoreClient::fetchAppDetails(const QString &appId)
}

void AppStoreClient::search(const QString &searchString, Type type)
{
search(searchString, type, 0);
}

void AppStoreClient::search(const QString &searchString, Type type, int page)
{
m_model->clear();
setBusy(true);
Expand All @@ -289,8 +298,8 @@ void AppStoreClient::search(const QString &searchString, Type type)
}

QString pluralFilter = filter + "s";
QString params = QString("query=%1&hitsPerPage=30&page=0&tagFilters=(%2)&analyticsTags=product-variant-time,%3,%4,appstore-search")
.arg(searchString).arg(filter).arg(m_hardwarePlatform).arg(pluralFilter);
QString params = QString("query=%1&hitsPerPage=30&page=%5&tagFilters=(%2)&analyticsTags=product-variant-time,%3,%4,appstore-search")
.arg(searchString).arg(filter).arg(m_hardwarePlatform).arg(pluralFilter).arg(page);
QJsonObject json;
json.insert("params", params);
QJsonDocument doc;
Expand All @@ -313,6 +322,13 @@ void AppStoreClient::search(const QString &searchString, Type type)
m_model->insert(item);
// qDebug() << "have item" << item->storeId() << item->name() << item->icon();
}
// Add pagination. The extra search parameters will be used as query and page. The link is just an identifier.
if (resultMap.value("page").toInt() > 0) {
m_model->addLink("previous", gettext("Previous"), resultMap.value("query").toString(), resultMap.value("page").toInt() - 1);
}
if (resultMap.value("page").toInt() < resultMap.value("nbPages").toInt() - 1) {
m_model->addLink("next", gettext("Next"), resultMap.value("query").toString(), resultMap.value("page").toInt() + 1);
}
qDebug() << "Found" << m_model->rowCount() << "items";
});
}
Expand All @@ -330,7 +346,12 @@ AppItem* AppStoreClient::parseAppItem(const QVariantMap &map)
item->setDescription(map.value("description").toString());
item->setHearts(map.value("hearts").toInt());
item->setCategory(map.value("category_name").toString());
item->setCompanion(!map.value("companions").toMap().value("android").isNull() || !map.value("companions").toMap().value("ios").isNull());
// The search returns the companions as 00 01 10 11 string instead of a map.
if (map.value("companions").type() == QVariant::Type::String) {
item->setCompanion(map.value("companions") != "00");
} else {
item->setCompanion(!map.value("companions").toMap().value("android").isNull() || !map.value("companions").toMap().value("ios").isNull());
}

QVariantList screenshotsList = map.value("screenshot_images").toList();
// try to get more hardware specific screenshots. The store search keeps them in a subgroup.
Expand Down
1 change: 1 addition & 0 deletions rockwork/appstoreclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public slots:

void fetchAppDetails(const QString &appId);

void search(const QString &searchString, Type type, int page);
void search(const QString &searchString, Type type);

private:
Expand Down
43 changes: 31 additions & 12 deletions rockwork/qml/pages/AppStorePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Page {
property string grpName: ""

property string link: ""
// To open a new page from the search field, see Component.onCompleted.
property string search: ""

AppStoreClient {
id: client
Expand All @@ -31,6 +33,8 @@ Page {
Component.onCompleted: {
if (root.link) {
client.fetchLink(link)
} else if (root.search) {
client.search(root.search, root.showWatchApps ? AppStoreClient.TypeWatchapp : AppStoreClient.TypeWatchface);
} else {
root.fetchHome()
}
Expand All @@ -41,7 +45,7 @@ Page {
PullDownMenu {
MenuItem {
text: qsTr("Use")+" "+(showCategories ? qsTr("Collections") : qsTr("Categories"))
onClicked: showCategories=!showCategories;
onClicked: showCategories=!showCategories
enabled: client.enableCategories && showWatchApps
visible: enabled
}
Expand Down Expand Up @@ -104,16 +108,17 @@ Page {
id: seeAllBtn
anchors.verticalCenter: parent.verticalCenter
icon.source: "image://theme/icon-m-enter-accept"
onClicked: {
pageStack.push(Qt.resolvedUrl("AppStorePage.qml"), {
pebble: root.pebble,
link: client.model.groupLink(section),
grpName: client.model.groupName(section),
enableCategories: false
});
}
}
}
// Allow the complete header to be clicked instead of just the button.
onClicked: {
pageStack.push(Qt.resolvedUrl("AppStorePage.qml"), {
pebble: root.pebble,
link: client.model.groupLink(section),
grpName: client.model.groupName(section),
enableCategories: false
});
}
}

footer: Item {
Expand All @@ -130,7 +135,15 @@ Page {
Button {
width: root.width/client.model.links.length - Theme.paddingSmall
text: client.model.linkName(client.model.links[index])
onClicked: client.fetchLink(client.model.links[index]);
onClicked: {
// The page and query were set from the search to indicate an active search pagination.
var query = client.model.linkQuery(client.model.links[index]);
if (query) {
client.search(query, root.showWatchApps ? AppStoreClient.TypeWatchapp : AppStoreClient.TypeWatchface, client.model.linkPage(client.model.links[index]));
} else {
client.fetchLink(client.model.links[index]);
}
}
}
}
}
Expand Down Expand Up @@ -222,8 +235,14 @@ Page {
icon: "image://theme/icon-m-search"
hint: qsTr("Search app or watchface")
onSubmit: {
client.search(text, root.showWatchApps ? AppStoreClient.TypeWatchapp : AppStoreClient.TypeWatchface);
root.grpName = qsTr("Search Results")
// Open in a new page to be able to cancel the search.
pageStack.push(Qt.resolvedUrl("AppStorePage.qml"), {
pebble: root.pebble,
search: text,
showWatchApps: root.showWatchApps,
grpName: qsTr("Search Results"),
enableCategories: false
});
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions rockwork/qml/pages/DockedTextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@ DockedPanel {
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - parent.height*1.8
placeholderText: dockedField.hint
// Simulate the button with the keyboard.
EnterKey.enabled: text.length > 0
EnterKey.iconSource: dockedField.icon
EnterKey.onClicked: {
dockedField.open = false;
dockedTextField.focus = false;
dockedField.submit();
}
}
IconButton {
anchors { top: parent.top; right: parent.right }
height: parent.height
width: height
icon.source: dockedField.icon
// Submitting without text would break the app store search.
enabled: text.length > 0
onClicked: {
dockedField.open=false;
dockedField.submit()
dockedField.open = false;
// Hide the keyboard.
dockedTextField.focus = false;
dockedField.submit();
}
}
}
2 changes: 1 addition & 1 deletion rockwork/qml/pages/LanguagePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Page {
if(ret) {
ver = ret[1]+"."+ret[2]+"."+(ret[3]? ret[3] : "0");
}
var url = "https://lp.getpebble.com/v1/languages?mobileVersion=3.13.0-1055-06644a6&mobilePlatform=android&isoLocal="+locale+"&hardware="+pebble.platformString+"&firmware="+ver;
var url = "https://lp.rebble.io/v1/languages?mobileVersion=3.13.0-1055-06644a6&mobilePlatform=android&isoLocal="+locale+"&hardware="+pebble.platformString+"&firmware="+ver;
var xhr = new XMLHttpRequest();
xhr.open("GET",url);
xhr.onreadystatechange = function() {
Expand Down
2 changes: 1 addition & 1 deletion rockwork/qml/pages/ResponsesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Page {
onClicked: {
var cans = {};
cans[source] = list;
pebble.cannedResponses=cans;
pebble.setCannedResponses(cans);
pageStack.pop();
}
visible: changed
Expand Down
3 changes: 2 additions & 1 deletion rockwork/qml/pages/SendTextSettingsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ Dialog {
pebble: pebble,
source: msgKey,
title: qsTr("Send Text Messages"),
list: pebble.getCannedResponses([msgKey])[msgKey]})
list: pebble.getCannedResponses([msgKey])[msgKey] || []
});
}

}
Expand Down
26 changes: 13 additions & 13 deletions rockwork/translations/rockpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,59 +101,59 @@
<context>
<name>AppStorePage</name>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="43"/>
<location filename="../qml/pages/AppStorePage.qml" line="47"/>
<source>Use</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="43"/>
<location filename="../qml/pages/AppStorePage.qml" line="55"/>
<location filename="../qml/pages/AppStorePage.qml" line="47"/>
<location filename="../qml/pages/AppStorePage.qml" line="59"/>
<source>Collections</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="43"/>
<location filename="../qml/pages/AppStorePage.qml" line="55"/>
<location filename="../qml/pages/AppStorePage.qml" line="47"/>
<location filename="../qml/pages/AppStorePage.qml" line="59"/>
<source>Categories</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="49"/>
<location filename="../qml/pages/AppStorePage.qml" line="53"/>
<source>Search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="55"/>
<location filename="../qml/pages/AppStorePage.qml" line="59"/>
<source>Watchapps</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="55"/>
<location filename="../qml/pages/AppStorePage.qml" line="59"/>
<source>Watchfaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="101"/>
<location filename="../qml/pages/AppStorePage.qml" line="105"/>
<source>See all</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="163"/>
<location filename="../qml/pages/AppStorePage.qml" line="176"/>
<source>All Apps</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="196"/>
<location filename="../qml/pages/AppStorePage.qml" line="209"/>
<source>Needs companion</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="223"/>
<location filename="../qml/pages/AppStorePage.qml" line="236"/>
<source>Search app or watchface</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AppStorePage.qml" line="226"/>
<location filename="../qml/pages/AppStorePage.qml" line="243"/>
<source>Search Results</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Loading

0 comments on commit c23677f

Please sign in to comment.