Skip to content

Commit

Permalink
Add active connections and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Iktwo committed Sep 24, 2014
1 parent 086fafa commit fbf1200
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 59 deletions.
14 changes: 7 additions & 7 deletions qml/FakeSearchPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ Page {
id: busyFooter
Item {
id: busyFooterContainer
width: resultsList.width
height: musicStreamer.searching && resultsList.count > 0 ? 48 * ScreenValues.dp : 0
width: listResults.width
height: musicStreamer.searching && listResults.count > 0 ? 48 * ScreenValues.dp : 0

Connections {
target: musicStreamer
onSearchingChanged: {
if (musicStreamer.searching && resultsList.count > 0)
if (musicStreamer.searching && listResults.count > 0)
busyFooterContainer.height = 48 * ScreenValues.dp
else
busyFooterContainer.height = 0
}
}

Connections {
target: resultsList
target: listResults
onCountChanged: {
if (musicStreamer.searching && resultsList.count > 0)
if (musicStreamer.searching && listResults.count > 0)
busyFooterContainer.height = 48 * ScreenValues.dp
else
busyFooterContainer.height = 0
Expand Down Expand Up @@ -172,7 +172,7 @@ Page {
flickableItem.interactive: true; focus: true

ListView {
id: resultsList
id: listResults

anchors.fill: parent

Expand Down Expand Up @@ -202,7 +202,7 @@ Page {
BusyIndicator {
id: busyIndicatorComponent
anchors.centerIn: parent
running: musicStreamer.searching && resultsList.count == 0
running: musicStreamer.searching && listResults.count == 0
height: (applicationWindow.height > applicationWindow.width ? applicationWindow.width : applicationWindow.height) * 0.4
width: height

Expand Down
1 change: 0 additions & 1 deletion qml/ImageButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Item {
id: mouseArea

anchors.fill: parent

onClicked: root.clicked()
}
}
30 changes: 28 additions & 2 deletions qml/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ Page {

if (index < playlist.count - 1) {
/// Will copy next item data, no need to change index
playbackControls.song = playlist.get(index + 1).name + " - <i>" + playlist.get(index + 1).artist + "</i>"
playbackControls.song = playlist.get(index + 1).name + " - <i>" + playlist.get(index + 1).comment + "</i>"
audioElement.source = playlist.get(index + 1).url
audioElement.play()
} else if (index - 1 >= 0) {
/// Will copy previous item data, update index to -1
playbackControls.song = playlist.get(index - 1).name + " - <i>" + playlist.get(index - 1).artist + "</i>"
playbackControls.song = playlist.get(index - 1).name + " - <i>" + playlist.get(index - 1).comment + "</i>"
audioElement.source = playlist.get(index - 1).url
audioElement.index = audioElement.index - 1
audioElement.play()
Expand All @@ -116,6 +116,32 @@ Page {
}
}

Label {
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: parent.bottom
margins: 8 * ScreenValues.dp
}

text: qsTr("You have no music on the playlist")
visible: songList.count === 0

color: Theme.mainTextColor

font {
pixelSize: 28 * ScreenValues.dp
family: Theme.fontFamily
}

horizontalAlignment: "AlignHCenter"
verticalAlignment: "AlignVCenter"

wrapMode: "Wrap"
elide: "ElideRight"
}

//Component.onCompleted: playlist.append({"name" : "First Song",
//"artist" : "First Group", "length" : "3:31", "comment" : "this is a test",
//"code" : "XASDDASD", "url": "invalid", "picture": "crazytest"})
Expand Down
12 changes: 9 additions & 3 deletions qml/PlaylistDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ Item {
left: parent.left; leftMargin: 8 * ScreenValues.dp
}

font.pixelSize: 18 * ScreenValues.dp
font {
pixelSize: 18 * ScreenValues.dp
family: Theme.fontFamily
}

color: Style.TEXT_COLOR_DARK
elide: Text.ElideRight
text: model.name + " - <i>" + model.group + "</i>"
text: model.name
width: parent.width
renderType: Text.NativeRendering
// TODO: add a dialog to show full name in case it's too long ???
Expand All @@ -65,7 +68,10 @@ Item {
left: parent.left; leftMargin: 8 * ScreenValues.dp
}

font.pixelSize: 12 * ScreenValues.dp
font {
pixelSize: 12 * ScreenValues.dp
family: Theme.fontFamily
}

elide: Text.ElideRight
color: Style.TEXT_SECONDARY_COLOR_DARK
Expand Down
78 changes: 49 additions & 29 deletions qml/SearchPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ Page {
property var shareModel

function search() {
if (!musicStreamer.searching)
if (!musicStreamer.searching) {
if (textEdit.text.length > 0) {
labelNoResults.opacity = 0
musicStreamer.search(textEdit.text)
Qt.inputMethod.hide()
}
}
}

onActivated: {
if (!resultsList.count)
if (!listResults.count)
textEdit.focus = true
else
Qt.inputMethod.hide()
Expand All @@ -33,6 +35,7 @@ Page {
onClicked: stackView.pop()
}

/// TODO: add X button to clear this
TextField {
id: textEdit

Expand Down Expand Up @@ -122,28 +125,8 @@ Page {
id: busyFooter
Item {
id: busyFooterContainer
width: resultsList.width
height: musicStreamer.searching && resultsList.count > 0 ? 48 * ScreenValues.dp : 0

Connections {
target: musicStreamer
onSearchingChanged: {
if (musicStreamer.searching && resultsList.count > 0)
busyFooterContainer.height = 48 * ScreenValues.dp
else
busyFooterContainer.height = 0
}
}

Connections {
target: resultsList
onCountChanged: {
if (musicStreamer.searching && resultsList.count > 0)
busyFooterContainer.height = 48 * ScreenValues.dp
else
busyFooterContainer.height = 0
}
}
width: listResults.width
height: musicStreamer.activeConnections > 0 && listResults.count > 0 ? 48 * ScreenValues.dp : 0

BusyIndicator {
anchors.centerIn: parent
Expand Down Expand Up @@ -176,7 +159,7 @@ Page {
flickableItem.interactive: true; focus: true

ListView {
id: resultsList
id: listResults

anchors.fill: parent

Expand Down Expand Up @@ -216,13 +199,14 @@ Page {
}
}

/// TODO: consider adding a button on the bottom to fetch more if list doesn't cover whole page

onContentYChanged: {
Qt.inputMethod.hide()
if (contentHeight != 0) {
// if (!musicStreamer.searching && ((contentY + height) / contentHeight) > 0.85)
if (!musicStreamer.searching && atYEnd)
musicStreamer.fetchMore()

if (musicStreamer.activeConnections === 0 && atYEnd)
musicStreamer.fetchMoreResulst()
}
}
}
Expand All @@ -237,7 +221,7 @@ Page {
BusyIndicator {
id: busyIndicatorComponent
anchors.centerIn: parent
running: musicStreamer.searching && resultsList.count == 0
running: (musicStreamer.searching || musicStreamer.activeConnections > 0) && listResults.count == 0
height: (applicationWindow.height > applicationWindow.width ? applicationWindow.width : applicationWindow.height) * 0.4
width: height

Expand Down Expand Up @@ -327,6 +311,42 @@ Page {
progressLabel.progress = progress
progressLabel.name = name
}

onNoResults: {
if (listResults.count === 0)
labelNoResults.opacity = 1
}
}
}

Label {
id: labelNoResults

anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: parent.bottom
margins: 8 * ScreenValues.dp
}

color: Theme.mainTextColor

elide: "ElideRight"
wrapMode: "Wrap"

font {
pixelSize: 28 * ScreenValues.dp
family: Theme.fontFamily
}

horizontalAlignment: "AlignHCenter"
verticalAlignment: "AlignVCenter"

text: qsTr("No results")

opacity: 0

Behavior on opacity { NumberAnimation { } }
}
}
9 changes: 5 additions & 4 deletions qml/SongDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Item {
}

antialiasing: true
Layout.preferredHeight: 68 * ScreenValues.dp
Layout.preferredWidth: 68 * ScreenValues.dp
Layout.preferredHeight: 0
Layout.preferredWidth: 0
fillMode: Image.PreserveAspectCrop
source: "http://www.goear.com/band/picture/" + model.picture
source: ""
}

Item {
Expand All @@ -74,7 +74,7 @@ Item {
Layout.fillWidth: true
color: Style.TEXT_COLOR_DARK
elide: Text.ElideRight
text: model.name + " - <i>" + model.artist + "</i>"
text: model.name
renderType: Text.NativeRendering
maximumLineCount: 1
}
Expand All @@ -96,6 +96,7 @@ Item {
width: parent.width
renderType: Text.NativeRendering
maximumLineCount: 1
linkColor: Style.TEXT_SECONDARY_COLOR_DARK
}

Rectangle {
Expand Down
6 changes: 3 additions & 3 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ApplicationWindow {
else
audio.index = 0

playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).artist + "</i>"
playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).comment + "</i>"
audio.source = playlist.get(audio.index).url
audio.play()
}
Expand All @@ -40,7 +40,7 @@ ApplicationWindow {
else
audio.index = playlist.count - 1

playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).artist + "</i>"
playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).comment + "</i>"
audio.source = playlist.get(audio.index).url
audio.play()
}
Expand Down Expand Up @@ -120,7 +120,7 @@ ApplicationWindow {
onRowsInserted: {
// If new item is first on list, play it
if (count === 1) {
playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).artist + "</i>"
playbackControls.song = playlist.get(audio.index).name + " - <i>" + playlist.get(audio.index).comment + "</i>"
audio.source = playlist.get(audio.index).url
audio.play()
} else if (audio.status == Audio.EndOfMedia) {
Expand Down
Loading

0 comments on commit fbf1200

Please sign in to comment.