From 10f27b9d506550654317790f10f2754b7075ca5a Mon Sep 17 00:00:00 2001 From: Dusko Angirevic Date: Fri, 27 Oct 2017 16:44:35 +0200 Subject: [PATCH] Added User search support --- harbour-tooter.pro | 1 + harbour-tooter.pro.user | 28 +++---- qml/cover/CoverPage.qml | 6 +- qml/pages/Conversation.qml | 126 ++++++++++++------------------ qml/pages/MainPage.qml | 17 +++- qml/pages/components/ItemUser.qml | 48 ++++++++++++ qml/pages/components/MyList.qml | 4 + rpm/harbour-tooter.changes.in | 7 ++ rpm/harbour-tooter.spec | 2 +- rpm/harbour-tooter.yaml | 2 +- 10 files changed, 144 insertions(+), 97 deletions(-) create mode 100644 qml/pages/components/ItemUser.qml diff --git a/harbour-tooter.pro b/harbour-tooter.pro index d740eda..7ef5a3f 100644 --- a/harbour-tooter.pro +++ b/harbour-tooter.pro @@ -62,6 +62,7 @@ OTHER_FILES += qml/harbour-tooter.qml \ qml/pages/components/VisualContainer.qml \ qml/pages/components/MiniStatus.qml \ qml/pages/components/MiniHeader.qml \ + qml/pages/components/ItemUser.qml \ harbour-tooter.desktop SAILFISHAPP_ICONS = 86x86 108x108 128x128 256x256 diff --git a/harbour-tooter.pro.user b/harbour-tooter.pro.user index f3e58ca..4f3fb07 100644 --- a/harbour-tooter.pro.user +++ b/harbour-tooter.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {41ec03ca-9430-48f3-b421-990d428b2838} + {25497605-1bff-4134-a878-76c1475dd8e3} ProjectExplorer.Project.ActiveTarget @@ -61,12 +61,12 @@ SailfishOS-i486 (in Sailfish OS Build Engine) SailfishOS-i486 (in Sailfish OS Build Engine) - {2b6dd414-d640-472a-9475-472ab2c5e22e} + {c5294635-b154-4f12-9c01-f8fe0f997f49} 0 - 0 + 2 0 - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Debug + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Debug true @@ -138,7 +138,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Release + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Release true @@ -210,7 +210,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Profile + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_i486_in_Sailfish_OS_Build_Engine-Profile true @@ -396,7 +396,7 @@ 13 14 - /Users/dysko/GIT/harbour-tooter + C:/Users/dysko/SF/harbour-tooter false 10234 3 @@ -414,7 +414,7 @@ 3768 false true - false + true false true @@ -426,12 +426,12 @@ SailfishOS-armv7hl (in Sailfish OS Build Engine) SailfishOS-armv7hl (in Sailfish OS Build Engine) - {e475a8ea-d9f2-4d35-b4f0-1f1076cd8d23} + {c33e8913-ac83-4c44-be39-b4748ccc7738} 0 2 0 - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Debug + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Debug true @@ -503,7 +503,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Release + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Release true @@ -575,7 +575,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Profile + C:/Users/dysko/SF/build-harbour-tooter-SailfishOS_armv7hl_in_Sailfish_OS_Build_Engine-Profile true @@ -761,7 +761,7 @@ 13 14 - /Users/dysko/GIT/harbour-tooter + C:/Users/dysko/SF/harbour-tooter false 10234 3 diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index 8a07f10..751c57b 100644 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -99,20 +99,20 @@ CoverBackground { color: Theme.primaryColor } - /*CoverActionList { + CoverActionList { id: coverAction CoverAction { iconSource: "image://theme/icon-cover-next" onTriggered: { - label.text = Logic.modelTLhome.count + Logic.conf.notificationLastID = 0; } } CoverAction { iconSource: "image://theme/icon-cover-pause" } - }*/ + } function checkNotifications(){ console.log("checkNotifications") var notificationsNum = 0 diff --git a/qml/pages/Conversation.qml b/qml/pages/Conversation.qml index 78ecd2f..31b1d30 100644 --- a/qml/pages/Conversation.qml +++ b/qml/pages/Conversation.qml @@ -10,22 +10,36 @@ Page { property alias title: header.title property alias description: header.description property alias avatar: header.image + property string suggestedUser: "" + property ListModel suggestedModel; property int toot_id property ListModel mdl; allowedOrientations: Orientation.All + onSuggestedUserChanged: { + console.log(suggestedUser) + suggestedModel = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject'); + predictionList.visible = false; + if (suggestedUser.length > 0) { + var msg = { + 'action' : 'accounts/search', + 'method' : 'GET', + 'model' : suggestedModel, + 'mode' : "append", + 'params' : [ {name: "q", data: suggestedUser} ], + + 'conf' : Logic.conf + }; + worker.sendMessage(msg); + predictionList.visible = true; + } + } + ListModel { id: mediaModel onCountChanged: { btnAddImage.enabled = mediaModel.count < 4 } } - ListModel { - id: suggestedModel - onCountChanged: { - console.log("aaaa " + count) - } - } - WorkerScript { id: worker @@ -77,44 +91,26 @@ Page { anchors.bottom: panel.top anchors.left: parent.left anchors.right: panel.right - height: Theme.itemSizeMedium * 6 + height: suggestedModel.count > 6 ? Theme.itemSizeMedium * 6 : Theme.itemSizeMedium * suggestedModel.count color: Theme.highlightDimmerColor - ListView { + SilicaListView { anchors.fill: parent model: suggestedModel clip: true - delegate: BackgroundItem { - height: Theme.itemSizeMedium - width: parent.width - - Image { - id: avatar - width: Theme.itemSizeSmall - height: width - source: model.account_avatar - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.leftMargin: Theme.horizontalPageMargin - } - Column { - anchors.left: avatar.right - anchors.leftMargin: Theme.paddingLarge - anchors.verticalCenter: parent.verticalCenter - height: account_acct.height + display_name.height - Label { - id: display_name - text: model.account_display_name+" " - font.pixelSize: Theme.fontSizeMedium - } - Label { - id: account_acct - text: "@"+model.account_acct - color: Theme.secondaryColor - anchors.leftMargin: Theme.paddingMedium - font.pixelSize: Theme.fontSizeExtraSmall + delegate: ItemUser { + onClicked: { + var start = toot.cursorPosition; + while(toot.text[start] !== "@" && start > 0){ + start--; } + textOperations.text = toot.text + textOperations.cursorPosition = toot.cursorPosition + textOperations.moveCursorSelection(start-1,TextInput.SelectWords) + toot.text = textOperations.text.substring(0, textOperations.selectionStart) + ' @'+model.account_acct + ' ' + textOperations.text.substring(textOperations.selectionEnd).trim() + textOperations.text = "" + toot.cursorPosition = toot.text.indexOf('@'+model.account_acct) } } onCountChanged: { @@ -153,6 +149,11 @@ Page { //tweet() } } + TextInput { + id: textOperations + visible: false + } + TextArea { id: toot anchors { @@ -164,7 +165,7 @@ Page { } autoScrollEnabled: true labelVisible: false - // focus: true + //focus: true text: description !== "" && (description.charAt(0) == '@' || description.charAt(0) == '#') ? description+' ' : '' height: implicitHeight horizontalAlignment: Text.AlignLeft @@ -172,41 +173,14 @@ Page { //tweet() } onTextChanged: { - var pattern = /\B@[a-z0-9_-]+/gi; - var mentions = text.match(pattern); - if (mentions && mentions.length){ - var index = text.indexOf(cursorPosition); - var preText = text.substring(0, cursorPosition); - var current; - if (preText.indexOf(" ") > 0) { - var words = preText.split(" "); - current = words[words.length - 1]; //return last word - } - else { - current = preText; - } - if (current[0] === "@") { - predictionList.visible = true; - var matches = mentions.filter(function(value){ - if(value) { - return (value.substring(0, current.length) === current); - } - }); - console.log(matches) - var msg = { - 'action' : 'accounts/search', - 'method' : 'GET', - 'model' : suggestedModel, - 'mode' : "append", - 'params' : [ {name: "q", data: matches[0].substring(1)} ], - - 'conf' : Logic.conf - }; - - worker.sendMessage(msg); - } else { - predictionList.visible = false; - } + textOperations.text = toot.text + textOperations.cursorPosition = toot.cursorPosition + textOperations.selectWord() + textOperations.select(textOperations.selectionStart ? textOperations.selectionStart-1 : 0, textOperations.selectionEnd) + console.log(textOperations.text.substr(textOperations.selectionStart, textOperations.selectionEnd)) + suggestedUser = "" + if (textOperations.selectedText.charAt(0) === "@") { + suggestedUser = textOperations.selectedText.trim().substring(1); } } } @@ -577,7 +551,9 @@ Page { text: glyph } onClicked: { - toot.text = toot.text + model.glyph + var cursorPosition = toot.cursorPosition + toot.text = toot.text.substring(0, cursorPosition) + model.glyph + toot.text.substring(cursorPosition) + toot.cursorPosition = cursorPosition+model.glyph.length emoticonsDialog.canAccept = true; emoticonsDialog.accept() diff --git a/qml/pages/MainPage.qml b/qml/pages/MainPage.qml index c92d4d2..78ffa13 100644 --- a/qml/pages/MainPage.qml +++ b/qml/pages/MainPage.qml @@ -96,6 +96,12 @@ Page { tlSearch.type = "timelines/tag/"+search.substring(1) loadData("append") } + if (search[0] === "@") { + tlSearch.type = "accounts/search" + tlSearch.params = [] + tlSearch.params.push({name: 'q', data: search.substring(1)}); + loadData("append") + } } onTypeChanged: { console.log("type changed") @@ -119,9 +125,14 @@ Page { } } ViewPlaceholder { - enabled: tlSearch.mdl === 0 - text: "Only #hastag search works" - } + enabled: tlSearch.mdl === 0 + text: "Only #hastag search works" + } + delegate: Loader { + width: parent.width + source: tlSearch.search[0] === "@" ? "components/ItemUser.qml" : "components/VisualContainer.qml" + + } } } diff --git a/qml/pages/components/ItemUser.qml b/qml/pages/components/ItemUser.qml new file mode 100644 index 0000000..e6ea0db --- /dev/null +++ b/qml/pages/components/ItemUser.qml @@ -0,0 +1,48 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import QtGraphicalEffects 1.0 + +BackgroundItem { + id: delegate + //property string text: "0" + height: Theme.itemSizeMedium + width: parent.width + + Image { + id: avatar + width: Theme.itemSizeExtraSmall + height: width + source: model.account_avatar + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: Theme.horizontalPageMargin + MouseArea { + anchors.fill: parent + onClicked: pageStack.push(Qt.resolvedUrl("./../Profile.qml"), { + "displayname": model.account_username, + "username": model.account_acct, + "user_id": model.account_id, + "profileImage": model.account_avatar + }) + } + } + Column { + anchors.left: avatar.right + anchors.leftMargin: Theme.paddingLarge + anchors.verticalCenter: parent.verticalCenter + height: account_acct.height + display_name.height + Label { + id: display_name + text: model.account_display_name+" " + color: !pressed ? Theme.primaryColor : Theme.highlightColor + font.pixelSize: Theme.fontSizeSmall + } + Label { + id: account_acct + text: "@"+model.account_acct + color: !pressed ? Theme.secondaryColor : Theme.secondaryHighlightColor + anchors.leftMargin: Theme.paddingMedium + font.pixelSize: Theme.fontSizeExtraSmall + } + } +} diff --git a/qml/pages/components/MyList.qml b/qml/pages/components/MyList.qml index d70e96a..702fe53 100644 --- a/qml/pages/components/MyList.qml +++ b/qml/pages/components/MyList.qml @@ -166,6 +166,10 @@ SilicaListView { } function loadData(mode){ var p = []; + if (params.length) + for(var i = 0; i 0.2.3-0 +- Added User autocomplete options +- Added video player options +- Smileys are inserted on the cursor position +- Pintch to zoom photos +- Support for downloading media to the device diff --git a/rpm/harbour-tooter.spec b/rpm/harbour-tooter.spec index 12a4f27..1904eab 100644 --- a/rpm/harbour-tooter.spec +++ b/rpm/harbour-tooter.spec @@ -13,7 +13,7 @@ Name: harbour-tooter %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Tooter -Version: 0.2.2 +Version: 0.2.3 Release: 0 Group: Qt/Qt License: LICENSE diff --git a/rpm/harbour-tooter.yaml b/rpm/harbour-tooter.yaml index 4354826..5b4b922 100644 --- a/rpm/harbour-tooter.yaml +++ b/rpm/harbour-tooter.yaml @@ -1,6 +1,6 @@ Name: harbour-tooter Summary: Tooter -Version: 0.2.2 +Version: 0.2.3 Release: 0 # The contents of the Group field should be one of the groups listed here: # http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS