Commit daa0206d authored by kempe's avatar kempe

Refactored sleeptimer

parent fce53904
......@@ -42,7 +42,6 @@ DISTFILES += \
qml/components/NavigationMenu.qml \
qml/components/RadioAPI.qml \
qml/components/RecivedUpgrader.qml \
qml/components/SleepTimer.qml \
qml/components/StationDelegate.qml \
qml/cover/CoverPage.qml \
qml/pages/BrowsePageForm.ui.qml \
......@@ -63,7 +62,10 @@ DISTFILES += \
qml/components/listmodels/ApiLanguageListModel.qml \
qml/components/audioplayer/DockerAudioPlayerSmalForm.ui.qml \
qml/components/audioplayer/DockerAudioPlayerSmal.qml \
qml/components/audioplayer/SleepTimerSwitch.qml
qml/components/audioplayer/SleepTimerSwitch.qml \
qml/components/sleeptimer/SleepTimerDialogForm.ui.qml \
qml/components/sleeptimer/SleepTimerDialog.qml \
qml/components/sleeptimer/SleepTimer.qml
OTHER_FILES += \
rpm/harbour-received.changes.in \
......
import QtQuick 2.6
import Sailfish.Silica 1.0
import it.kempe.AudioPlayer 1.0
import "../js/Storage.js" as DB
import "../sleeptimer"
import "../js/Favorites.js" as FavoritesUtils
import "../js/Utils.js" as Utils
DockerAudioPlayerSmalForm {
id: player
......@@ -17,41 +16,47 @@ DockerAudioPlayerSmalForm {
// Property assignment
isPlaying: AudioPlayer.isPlaying
showProgressBar: AudioPlayer.isLoading || AudioPlayer.isBuffering
bufferProgress: AudioPlayer.bufferProgress
currentTrack: AudioPlayer.title
bufferProgress: AudioPlayer.bufferProgress
showProgressBar: AudioPlayer.isLoading || AudioPlayer.isBuffering
sleepTimerActive: sleepTimer.running
sleepTimerText: sleepTimer.clockText
// Triggers
opener.onClicked: console.debug("Show fullscreen player controls")
buttonPlay.onClicked: AudioPlayer.togglePlayback();
timerSwitch.onClicked: toggleSleepTimer()
favoriteSwitch.onClicked: player.isFavorite = FavoritesUtils.toogleFavorite(stationData)
sleepTimer.onSleepTriggered: AudioPlayer.stop()
timerSwitch.onClicked: {
// Components
SleepTimer {
id: sleepTimer
onSleepTriggered: {
timerSwitch.checked = false
AudioPlayer.stop()
}
}
Component {
id: sleepTimerDialog
SleepTimerDialog {
onAbort: timerSwitch.checked = false
onActivateTimer: sleepTimer.startTimer(sec)
}
}
// Helper functions
function toggleSleepTimer() {
playerMenu.close()
if (timerSwitch.checked) {
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);
})
pageStack.push(sleepTimerDialog)
} else {
sleepTimer.stopTimer()
}
}
// Helper functions
function play(station) {
if(!player.expanded)
player.open = true;
......
......@@ -5,32 +5,26 @@ import "../"
DockedPanel {
id: player
property alias opener: opener
property bool isPlaying
property bool isFavorite
property var stationData
property string currentTrack
property int bufferProgress
property bool showProgressBar
property bool sleepTimerActive
property string sleepTimerText
property alias opener: opener
property alias buttonPlay: buttonPlay
property alias playerMenu: playerMenu
property bool showProgressBar: false
property bool isPlaying: false
property bool isFavorite: false
property int bufferProgress: 0
property string currentTrack: ""
property alias sleepTimer: sleepTimer
property alias timerSwitch: timerSwitch
property alias favoriteSwitch: favoriteSwitch
property real hightPadding: Theme.paddingMedium
property var stationData
property real hightPadding: Theme.paddingMedium
height: Theme.itemSizeSmall + (hightPadding * 2)
contentHeight: height
flickableDirection: Flickable.VerticalFlick
SleepTimer {
id: sleepTimer
onRunningChanged: timerSwitch.checked = running // For some reason the binding on timerSwitch is not working
}
flickableDirection: Flickable.VerticalFlick
MouseArea {
id: opener
......@@ -96,10 +90,9 @@ DockedPanel {
SleepTimerSwitch {
id: timerSwitch
width: pushupMenuRow.itemWidth
clockText: sleepTimer.clockText
checked: sleepTimer.running
showText: sleepTimer.running
checked: sleepTimerActive
showText: sleepTimerActive
clockText: sleepTimerText
}
}
}
......
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../js/Storage.js" as DB
SleepTimerDialogForm {
id: root
signal abort
signal activateTimer(int sec)
onAccepted: {
DB.updateSleepTimer(hour, minute)
var sec = (minute + (hour * 60)) * 60;
activateTimer(sec)
}
onRejected: abort()
Component.onCompleted: {
var sTime = DB.loadSleepTimer()
hour = sTime.hour
minute = sTime.minute
hourMode = DateTime.TwentyFourHours
}
}
import QtQuick 2.6
import Sailfish.Silica 1.0
TimePickerDialog {
}
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