Commit fb46a71e authored by kempe's avatar kempe

Refactored Favorite page part of #6

* Extracted components
* Decided in .qml and .ui.qml
parent f832d5a0
......@@ -29,7 +29,6 @@ OTHER_FILES += qml/harbour-received.qml \
qml/components/js/Utils.js \
qml/components/python/api.py \
qml/components/js/Storage.js \
qml/pages/Favorites.qml \
qml/components/js/Favorites.js \
qml/pages/Browse.qml \
translations/harbour-received-sv.ts \
......@@ -58,4 +57,9 @@ DISTFILES += \
qml/components/DockedAudioPlayerForm.ui.qml \
qml/components/MenuLabelSmal.ui.qml \
qml/pages/NavigationMenuForm.ui.qml \
qml/pages/NavigationMenu.qml
qml/pages/NavigationMenu.qml \
qml/pages/FavoritesPageForm.ui.qml \
qml/pages/FavoritesPage.qml \
qml/components/FavoritesListContextMenu.qml \
qml/components/StationDelegate.qml
import QtQuick 2.6
import Sailfish.Silica 1.0
/**
* Context menu intended for use within FavoritePage list
*
* index is coming from that list and is the index in the list that the contextmenu was triggered for
*/
ContextMenu {
signal removeFavorite()
MenuItem {
text: qsTr("Remove from favorite")
onClicked: {
remorseAction("Deleteing", function() {
removeFavorite(index)
});
}
}
}
import QtQuick 2.6
import Sailfish.Silica 1.0
ListItem {
property string image
property string title
property string subtitle
width: 400
contentHeight: Theme.itemSizeLarge
Row {
anchors.fill: parent
spacing: Theme.paddingLarge
Image {
id: image
source: stationLogo
smooth: true
fillMode: Image.PreserveAspectFit
cache: true
sourceSize.height: parent.height - 20
visible: image !== ""
}
Column {
width: parent.width - image.width - Theme.paddingLarge
height: parent.height
spacing: -Theme.paddingSmall
Label {
text: title
visible: title !== ""
}
Label {
width: parent.width
font.pixelSize: Theme.fontSizeExtraSmall
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
text: subtitle
visible: subtitle !== ""
}
}
}
}
......@@ -16,7 +16,7 @@ ApplicationWindow
initialPage: favorites
cover: Qt.resolvedUrl("cover/CoverPage.qml")
Favorites {
FavoritesPage {
id: favorites
}
......
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components/js/Utils.js" as Utils
import "../components/js/Favorites.js" as FavoritesUtils
Page {
id: favoritePage
allowedOrientations: Orientation.All
property bool firstPage: true
property alias favoriteModel: favoriteModel
SilicaListView {
id: favoritesListView
VerticalScrollDecorator { flickable: favoritesListView }
anchors.fill: parent
NavigationMenu {
id: pulleyMeny
}
header: Column {
PageHeader {
title: qsTr("Favorites")
width: favoritePage.width
}
}
model: ListModel {
id: favoriteModel
}
delegate: ListItem {
id: favoritItem
menu: favoriteContextMenu
width: parent.width
contentHeight: Theme.itemSizeLarge
Row {
anchors.fill: parent
spacing: Theme.paddingLarge
Image {
id: stationIcon
source: stationLogo
smooth: true
fillMode: Image.PreserveAspectFit
cache: true
sourceSize.height: parent.height - 20
}
Column {
id: stationInfo
width: parent.width - stationIcon.width - Theme.paddingLarge
height: parent.height
spacing: -Theme.paddingSmall
Label {
id: stationName
text: name
}
Label {
width: parent.width
font.pixelSize: Theme.fontSizeExtraSmall
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
text: "From " + country + ": " + genre
}
}
}
onClicked: {
var station = getStation();
console.log("Playing", station)
player.play(getStation())
}
Component {
id: favoriteContextMenu
ContextMenu {
MenuItem {
text: qsTr("Remove from favorite")
onClicked: {
remove()
}
}
}
}
function remove() {
remorseAction("Deleteing", function() {
FavoritesUtils.removeFavorite(getStation());
});
}
function getStation() {
return favoriteModel.get(index);
}
}
}
Component.onCompleted: {
FavoritesUtils.init(favoriteModel)
}
}
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components/js/Favorites.js" as FavoritesUtils
FavoritesPageForm {
// Recives index as parameter from signal
onPlayFavorite: {
var station = getStation(index);
console.debug("Playing", station)
player.play(station)
}
// Recives index as parameter from signal
onRemoveFavorite: FavoritesUtils.removeFavorite(getStation(index));
function getStation(index) {
return favoriteModel.get(index);
}
Component.onCompleted: FavoritesUtils.init(favoriteModel)
}
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components/"
Page {
id: favoritePage
signal playFavorite(int index)
signal removeFavorite(int index)
allowedOrientations: Orientation.All
property bool firstPage: true
property alias favoriteModel: favoriteModel
SilicaListView {
id: favoritesListView
VerticalScrollDecorator { flickable: favoritesListView }
anchors.fill: parent
NavigationMenu {
id: pulleyMeny
}
header: Column {
PageHeader {
title: qsTr("Favorites")
width: favoritePage.width
}
}
model: ListModel {
id: favoriteModel
}
delegate: StationDelegate {
id: favoritItem
width: parent.width
image: stationLogo
title: name
subtitle: "From " + country + ": " + genre
menu: FavoritesListContextMenu {
id: contextMenu
}
Connections {
target: favoritItem
onClicked: playFavorite(index)
}
Connections {
target: contextMenu
onRemoveFavorite: removeFavorite(index)
}
}
}
}
......@@ -73,6 +73,20 @@
<translation>Ta bort från favoriter</translation>
</message>
</context>
<context>
<name>FavoritesListContextMenu</name>
<message>
<source>Remove from favorite</source>
<translation type="unfinished">Ta bort från favoriter</translation>
</message>
</context>
<context>
<name>FavoritesPageForm.ui</name>
<message>
<source>Favorites</source>
<translation type="unfinished">Favoriter</translation>
</message>
</context>
<context>
<name>NavigationMenuForm.ui</name>
<message>
......
......@@ -73,6 +73,20 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FavoritesListContextMenu</name>
<message>
<source>Remove from favorite</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FavoritesPageForm.ui</name>
<message>
<source>Favorites</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NavigationMenuForm.ui</name>
<message>
......
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