Commit 9cd6df95 authored by kempe's avatar kempe

Refactored Docked audio player to use form.ui.qml

parent 05d6a84b
......@@ -53,8 +53,6 @@ HEADERS +=
DISTFILES += \
qml/components/js/Rad.js \
qml/components/DockedAudioPlayer.qml
FORMS += \
qml/components/PlayerControls.qml.ui
qml/components/DockedAudioPlayer.qml \
qml/components/PlayerControlsForm.ui.qml \
qml/components/DockedAudioPlayerForm.ui.qml
......@@ -6,14 +6,8 @@ Audio {
autoLoad: false
autoPlay: false
function isPlaying() {
return playbackState == Audio.PlayingState
}
function isLoading() {
return isPlaying() && bufferProgress < 1
}
property bool isPlaying: false
property bool isLoading: false
function stopAndReset() {
audio.stop()
......@@ -56,15 +50,21 @@ Audio {
console.debug(errorMessage)
}
onStatusChanged: {
console.debug("AudioPlayer: Status changed: ", status)
onBufferProgressChanged: {
isLoading = isPlaying && bufferProgress < 1
}
onSourceChanged: {
console.debug("New source: ", source)
}
onStatusChanged: {
console.debug("AudioPlayer: Status changed: ", status)
}
onPlaybackStateChanged: {
console.debug("AudioPlayer PlaybackState changed: ", playbackState)
isPlaying = playbackState == Audio.PlayingState
isLoading = isPlaying && bufferProgress < 1
}
}
......@@ -4,11 +4,48 @@ import "./js/Storage.js" as DB
import "./js/Favorites.js" as FavoritesUtils
import "./js/Utils.js" as Utils
DockedPanel {
DockedAudioPlayerForm {
id: player
property var stationData: null;
property bool isFavorite: false
// Layout
width: parent.width
dock: Dock.Bottom
Behavior on opacity { FadeAnimation {duration: 300}}
// Property assignment
isLoading: audio.isLoading
isPlaying: audio.isPlaying
// Triggers
opener.onClicked: console.debug("Show fullscreen player controls")
buttonStar.onClicked: player.isFavorite = FavoritesUtils.toogleFavorite(stationData)
buttonPrevious.onClicked: playPrev()
buttonPlay.onClicked: isPlaying ? stop() : resume()
buttonNext.onClicked: playNext()
sleepTimer.onSleepTriggered: stop();
cancelSleepTimer.onClicked: sleepTimer.stopTimer()
setSleepTimer.onClicked: {
var sTime = DB.loadSleepTimer()
console.debug("DB HOUR: " + sTime.hour)
console.debug("DB MINUTE: " + sTime.minute)
var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hour: sTime.hour,
minute: sTime.minute,
hourMode: DateTime.TwentyFourHours
})
dialog.accepted.connect(function() {
DB.updateSleepTimer(dialog.hour, dialog.minute)
var sec = (dialog.minute + (dialog.hour * 60)) * 60;
sleepTimer.startTimer(sec);
})
}
// Helper functions
function play(station) {
if(!player.expanded)
player.open = true;
......@@ -43,141 +80,4 @@ DockedPanel {
audio.source = stationData.url;
audio.play();
}
function isPlaying() {
return audio.isPlaying();
}
function isLoading() {
audio.isLoading();
}
width: parent.width
height: Theme.itemSizeExtraLarge + Theme.paddingLarge
dock: Dock.Bottom
opacity: Qt.inputMethod.visible || !open ? 0.0 : 1.0
Behavior on opacity { FadeAnimation {duration: 300}}
SleepTimer {
id: sleepTimer
onSleepTriggered: player.stop();
}
PushUpMenu {
id: playerManu
MenuLabel {
text: qsTr("Sleep timer")
}
MenuLabelSmal {
id: sleepTimerLabel
visible: sleepTimer.running
text: Utils.secToTimeString(sleepTimer.progress);
}
MenuItem{
visible: sleepTimer.running
text: qsTr("Cancel")
onClicked: {
sleepTimer.stopTimer()
}
}
MenuItem {
visible: !sleepTimer.running
text: qsTr("Set")
onClicked: {
var sTime = DB.loadSleepTimer()
console.debug("DB HOUR: " + sTime.hour)
console.debug("DB MINUTE: " + sTime.minute)
var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hour: sTime.hour,
minute: sTime.minute,
hourMode: DateTime.TwentyFourHours
})
dialog.accepted.connect(function() {
DB.updateSleepTimer(dialog.hour, dialog.minute)
var sec = (dialog.minute + (dialog.hour * 60)) * 60;
sleepTimer.startTimer(sec);
})
}
}
}
Item {
anchors.fill: parent
MouseArea {
id: opener
anchors.fill: parent
onClicked: console.debug("Show fullscreen player controls")
}
Row {
id: quickControlsItem
anchors.fill: parent
spacing: Theme.paddingLarge
Image {
id: stationIcon
sourceSize.height: parent.height
sourceSize.width: player.height
source: window.stationIcon
smooth: true
fillMode: Image.PreserveAspectFit
cache: true
}
Column {
id: trackInfo
width: parent.width - stationIcon.width - Theme.paddingLarge
height: parent.height
spacing: -Theme.paddingSmall
Label {
width: parent.width
truncationMode: TruncationMode.Fade
text: stationData ? stationData.name : ""
}
Label {
width: parent.width
font.pixelSize: Theme.fontSizeSmall
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
text: stationData ? stationData.genre : "";
}
ProgressBar {
id: progressBar
value: audio.bufferProgress
width: parent.width
visible: audio.isLoading()
Behavior on value {
NumberAnimation {}
}
}
PlayerControls {
id: controls
visible: !player.isLoading()
isPlaying: player.isPlaying()
isStared: player.isFavorite
buttonStar.onClicked: player.isFavorite = FavoritesUtils.toogleFavorite(stationData)
buttonPrevious.onClicked: playPrev()
buttonPlay.onClicked: player.isPlaying() ? stop() : resume()
buttonNext.onClicked: playNext()
}
}
}
}
AudioPlayer {
id: audio
}
}
import QtQuick 2.0
import Sailfish.Silica 1.0
DockedPanel {
id: player
property alias opener: opener
property alias audio: audio
property alias buttonStar: controls.buttonStar
property alias buttonPrevious: controls.buttonPrevious
property alias buttonPlay: controls.buttonPlay
property alias buttonNext: controls.buttonNext
property alias sleepTimer: sleepTimer
property alias cancelSleepTimer: cancelSleepTimer
property alias setSleepTimer: setSleepTimer
property bool isLoading: false
property bool isPlaying: false
property bool isFavorite: false
property var stationData
opacity: Qt.inputMethod.visible || !open ? 0.0 : 1.0
height: Theme.itemSizeExtraLarge + Theme.paddingLarge
SleepTimer {
id: sleepTimer
}
AudioPlayer {
id: audio
}
Item {
anchors.fill: parent
PushUpMenu {
id: playerManu
MenuLabel {
text: qsTr("Sleep timer")
}
MenuLabelSmal {
id: sleepTimerLabel
visible: sleepTimer.running
text: sleepTimer.clockText
}
MenuItem{
id: cancelSleepTimer
visible: sleepTimer.running
text: qsTr("Cancel")
}
MenuItem {
id: setSleepTimer
visible: !sleepTimer.running
text: qsTr("Set")
}
}
MouseArea {
id: opener
anchors.fill: parent
}
Row {
id: quickControlsItem
anchors.fill: parent
spacing: Theme.paddingLarge
Image {
id: stationIcon
sourceSize.height: parent.height
sourceSize.width: player.height
source: window.stationIcon
smooth: true
fillMode: Image.PreserveAspectFit
cache: true
}
Column {
id: trackInfo
width: parent.width - stationIcon.width - Theme.paddingLarge
height: parent.height
spacing: -Theme.paddingSmall
Label {
width: parent.width
truncationMode: TruncationMode.Fade
text: stationData ? stationData.name : ""
}
Label {
width: parent.width
font.pixelSize: Theme.fontSizeSmall
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
text: stationData ? stationData.genre : "";
}
ProgressBar {
id: progressBar
value: audio.bufferProgress
width: parent.width
visible: isLoading
}
PlayerControlsForm {
id: controls
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
visible: !player.isLoading
isPlaying: player.isPlaying
isStared: player.isFavorite
}
}
}
}
}
import QtQuick 2.0
import QtQuick 2.5
import Sailfish.Silica 1.0
Row {
property bool isPlaying: false
......@@ -10,31 +11,29 @@ Row {
id: controls
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
property real itemWidth: width / 4
IconButton {
id: buttonStar
width: itemWidth
anchors.verticalCenter: parent.verticalCenter
icon.source: isStared ? "image://theme/icon-m-favorite-selected" : "image://theme/icon-m-favorite"
}
IconButton {
id: buttonPrevious
width: itemWidth
anchors.verticalCenter: parent.verticalCenter
icon.source: "image://theme/icon-m-previous-song"
}
IconButton {
id: buttonPlay
width: itemWidth
anchors.verticalCenter: parent.verticalCenter
icon.source: isPlaying ? "image://theme/icon-m-pause" : "image://theme/icon-m-play"
}
IconButton {
id: buttonNext
width: itemWidth
......@@ -42,3 +41,4 @@ Row {
icon.source: "image://theme/icon-m-next-song"
}
}
import QtQuick 2.0
Timer {
signal sleepTriggered()
property int count: 0
property int sleepSec: 0
property int progress: sleepSec - count
signal sleepTriggered()
property string clockText: secToTimeString(sleepTimer.progress)
id: sleepTimer
running: false
......@@ -29,4 +31,17 @@ Timer {
sleepSec = sec;
start();
}
function secToTimeString(sec) {
var hours = Math.floor(sec / 3600);
var minutes = Math.floor((sec - (hours * 3600)) / 60);
var seconds = sec - (hours * 3600) - (minutes * 60);
hours = hours < 10 ? "0"+hours : hours;
minutes = minutes < 10 ? "0"+minutes : minutes;
seconds = seconds < 10 ? "0"+seconds : seconds;
var time = hours+':'+minutes+':'+seconds;
return time;
}
}
......@@ -10,19 +10,6 @@ var Recommended = new ListType(qsTr("Recommended"));
var Local = new ListType(qsTr("Local"));
var Favorites = new ListType(qsTr("Favorites"));
function secToTimeString(sec) {
var hours = Math.floor(sec / 3600);
var minutes = Math.floor((sec - (hours * 3600)) / 60);
var seconds = sec - (hours * 3600) - (minutes * 60);
hours = hours < 10 ? "0"+hours : hours;
minutes = minutes < 10 ? "0"+minutes : minutes;
seconds = seconds < 10 ? "0"+seconds : seconds;
var time = hours+':'+minutes+':'+seconds;
return time;
}
/**
* This function may not work for all cases but its enough for my use case
*
......
......@@ -22,11 +22,11 @@ CoverBackground {
}
CoverAction {
iconSource: player.isPlaying() ? "image://theme/icon-cover-pause" : "image://theme/icon-cover-play"
iconSource: player.isPlaying ? "image://theme/icon-cover-pause" : "image://theme/icon-cover-play"
onTriggered: {
if(!player.stationData)
player.playNext()
if(!player.isPlaying())
else if(!player.isPlaying)
player.resume()
else
player.stop()
......
......@@ -24,7 +24,7 @@ Page {
}
}
MenuItem {
visible: player.isPlaying() && !player.open
visible: player.isPlaying && !player.open
text: qsTr("Show player")
onClicked: {
player.open = true
......
......@@ -64,7 +64,7 @@
</message>
</context>
<context>
<name>DockedAudioPlayer</name>
<name>DockedAudioPlayerForm.ui</name>
<message>
<source>Sleep timer</source>
<translation type="unfinished">insomningstimer</translation>
......
......@@ -64,7 +64,7 @@
</message>
</context>
<context>
<name>DockedAudioPlayer</name>
<name>DockedAudioPlayerForm.ui</name>
<message>
<source>Sleep timer</source>
<translation type="unfinished"></translation>
......
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