Commit 7871c075 authored by kempe's avatar kempe

Refactored Stations page part of #6

* Extracted components
* Divided in .qml and .ui.qml
parent 3d8d6db7
......@@ -32,7 +32,6 @@ OTHER_FILES += qml/harbour-received.qml \
qml/components/js/Favorites.js \
qml/pages/Browse.qml \
translations/harbour-received-sv.ts \
qml/pages/Stations.qml \
qml/pages/BrowseByCategory.qml \
qml/components/SleepTimer.qml \
qml/components/RadioAPI.qml \
......@@ -61,5 +60,9 @@ DISTFILES += \
qml/pages/FavoritesPageForm.ui.qml \
qml/pages/FavoritesPage.qml \
qml/components/FavoritesListContextMenu.qml \
qml/components/StationDelegate.qml
qml/components/StationDelegate.qml \
qml/pages/StationsPageForm.ui.qml \
qml/pages/StationsPage.qml \
qml/components/StationsListContextMenu.qml \
qml/components/CustomSearchField.qml
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components"
SearchField {
id: searchField
signal search(string text)
EnterKey.enabled: text.length > 0
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
if(text != "") {
search(text);
}
else {
searchField.focus = false;
}
}
}
......@@ -27,7 +27,7 @@ Python {
});
}
function addRadIoFavorit(id) {
function addRadIoAsFavorite(id) {
loading = true;
call('api.radio.getStationById', [''+id], function(response) {
var stationData = Rad.getStationFromRadioJson(response);
......
import QtQuick 2.6
import Sailfish.Silica 1.0
import "js/Favorites.js" as FavoritesUtils
/**
* Context menu intended for use within StationsPage list
*
* index is coming from that list and is the index in the list that the contextmenu was triggered for
*/
ContextMenu {
signal removeFavorite(var station)
signal addFavorite(int id)
property bool isFavorite: FavoritesUtils.isRadIoFavorite(id);
MenuItem {
text: qsTr("Remove from favorite")
visible: isFavorite
onClicked: {
remorseAction("Deleteing", function() {
removeFavorite(FavoritesUtils.getFavoriteByRadioId(id))
isFavorite = false
});
}
}
MenuItem {
text: qsTr("Add to favorite")
visible: !isFavorite
onClicked: {
addFavorite(id)
isFavorite = true
}
}
}
......@@ -72,8 +72,8 @@ function isFavorite(station) {
return DB.stationExists(station)
}
function isRadIoFavorite(station) {
return DB.stationExistsByRadIoId(station.radIoId)
function isRadIoFavorite(radioId) {
return DB.stationExistsByRadIoId(radioId)
}
function getFavoriteByRadioId(radIoId) {
......
......@@ -42,13 +42,13 @@ Page {
onClicked: {
if(action === "top100") {
pageStack.push(Qt.resolvedUrl("Stations.qml"), {listType: Utils.Top100});
pageStack.push(Qt.resolvedUrl("StationsPage.qml"), {listType: Utils.Top100});
}
else if(action === "recommended") {
pageStack.push(Qt.resolvedUrl("Stations.qml"), {listType: Utils.Recommended});
pageStack.push(Qt.resolvedUrl("StationsPage.qml"), {listType: Utils.Recommended});
}
else if(action === "localStations") {
pageStack.push(Qt.resolvedUrl("Stations.qml"), {listType: Utils.Local});
pageStack.push(Qt.resolvedUrl("StationsPage.qml"), {listType: Utils.Local});
}
else {
pageStack.push(Qt.resolvedUrl("BrowseByCategory.qml"), {category: originalTitle, headerTitle: title});
......
......@@ -20,7 +20,7 @@ Page {
pageStack.replaceAbove(
pageStack.find(function(page) {
return page.firstPage === true}),
Qt.resolvedUrl("Stations.qml"),
Qt.resolvedUrl("StationsPage.qml"),
{listType: Utils.Search});
}
}
......@@ -51,7 +51,7 @@ Page {
}
onClicked: {
pageStack.push(Qt.resolvedUrl("Stations.qml"), {listType: new Utils.ListType(title), category: category, value: title});
pageStack.push(Qt.resolvedUrl("StationsPage.qml"), {listType: new Utils.ListType(title), category: category, value: title});
}
}
}
......
......@@ -5,7 +5,7 @@ NavigationMenuForm {
property var settingsAction: function() { pageStack.push(Qt.resolvedUrl("Settings.qml")); }
property var showPlayerAction: function() { player.open = true; }
property var browseAction: function() { pageStack.push(Qt.resolvedUrl("Browse.qml"), {listType: Utils.Top100}); }
property var searchAction: function() { pageStack.push(Qt.resolvedUrl("Stations.qml"), {listType: Utils.Search}); }
property var searchAction: function() { pageStack.push(Qt.resolvedUrl("StationsPage.qml"), {listType: Utils.Search}); }
actionSettings.onClicked: settingsAction()
......
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: page
property var listType: Utils.Favorites
property string category: ""
property string value: ""
SilicaListView {
id: stationListView
VerticalScrollDecorator { flickable: stationListView }
anchors.fill: parent
NavigationMenu {
id: pulleyMeny
hideSearchAction: listType === Utils.Search
searchAction: function() {
pageStack.replaceAbove(
pageStack.find(function(page) {
return page.firstPage === true}),
Qt.resolvedUrl("Stations.qml"),
{listType: Utils.Search});
}
}
header: Column {
PageHeader {
title: qsTr(listType.header)
width: page.width
}
SearchField {
id: searchInput
width: page.width
visible: listType === Utils.Search
EnterKey.enabled: text.length > 0
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
if(text != "") {
radioAPI.search(text, stationModel);
}
else {
focus = false;
}
}
}
}
model: ListModel {
id: stationModel
}
delegate: ListItem {
id: listItem
menu: itemContextMenu
width: parent.width
contentHeight: Theme.itemSizeLarge
Row {
id: quickControlsItem
anchors.fill: parent
spacing: Theme.paddingLarge
Image {
id: stationIcon
source: pictureBaseURL + picture1Name
smooth: true
fillMode: Image.PreserveAspectFit
cache: true
sourceSize.height: parent.height - 20
}
Column {
id: trackInfo
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: qsTr("From") + " " + country + ": " + genresAndTopics.split(",")[0]
}
Label {
width: parent.width
font.pixelSize: Theme.fontSizeSmall
truncationMode: TruncationMode.Fade
color: Theme.secondaryHighlightColor
text: currentTrack ? currentTrack : "-"
}
}
}
onClicked: {
radioAPI.playStationById(id);
}
Component {
id: itemContextMenu
ContextMenu {
MenuItem {
text: qsTr("Remove from favorite")
visible: isFavorite()
onClicked: {
remove()
}
}
MenuItem {
text: qsTr("Add to favorite")
visible: !isFavorite()
onClicked: {
var station = stationModel.get(index);
radioAPI.addRadIoFavorit(station.id)
}
}
}
}
function remove() {
remorseAction("Deleteing", function() {
var station = stationModel.get(index);
FavoritesUtils.removeFavorite(station);
});
}
function isFavorite() {
var station = stationModel.get(index);
return FavoritesUtils.isRadIoFavorite(station)
}
}
}
Component.onCompleted: {
if(page.listType === Utils.Top100) {
radioAPI.getTop100(stationModel);
}
else if(page.listType === Utils.Recommended) {
radioAPI.getRecomended(stationModel);
}
else if(page.listType === Utils.Local) {
radioAPI.getLocal(stationModel)
}
else if(page.listType !== Utils.Search) {
radioAPI.getStationByCategory(category.toLocaleLowerCase(), value, stationModel);
}
}
}
import QtQuick 2.6
import "../components/js/Favorites.js" as FavoritesUtils
import "../components/js/Utils.js" as Utils
StationsPageForm {
// Set properties
showSearch: listType === Utils.Search
// Add listeners
onRemoveFavorite: FavoritesUtils.removeFavorite(station)
onAddFavorite: radioAPI.addRadIoAsFavorite(id)
onPlayStation: radioAPI.playStationById(id);
onSearch: radioAPI.search(text, stationModel);
// Helper functions
function getStation(index) {
return stationModel.get(index);
}
// Other
// Set a custom search action in navigation menu
navigationMenu.searchAction: function() {
pageStack.replaceAbove(
pageStack.find(function(page) {
return page.firstPage === true}),
Qt.resolvedUrl("StationsPage.qml"),
{listType: Utils.Search});
}
// Init
Component.onCompleted: {
if(listType === Utils.Top100) {
radioAPI.getTop100(stationModel);
}
else if(listType === Utils.Recommended) {
radioAPI.getRecomended(stationModel);
}
else if(listType === Utils.Local) {
radioAPI.getLocal(stationModel)
}
else if(listType !== Utils.Search) {
radioAPI.getStationByCategory(category.toLocaleLowerCase(), value, stationModel);
}
}
}
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components"
Page {
id: page
signal playStation(int id)
signal removeFavorite(var station)
signal addFavorite(int id)
signal search(string text)
property alias navigationMenu: navigationMenu
property alias stationModel: stationModel
property var listType: Utils.Favorites
property bool showSearch: false
property string category: ""
property string value: ""
SilicaListView {
id: stationListView
VerticalScrollDecorator { flickable: stationListView }
anchors.fill: parent
NavigationMenu {
id: navigationMenu
hideSearchAction: showSearch
}
header: Column {
PageHeader {
title: qsTr(listType.header)
width: page.width
}
CustomSearchField {
id: searchField
width: page.width
visible: showSearch
Connections {
target: searchField
onSearch: search(text)
}
}
}
model: ListModel {
id: stationModel
}
delegate: StationDelegate {
id: stationItem
width: parent.width
stationIcon: pictureBaseURL + picture1Name
stationTitle: name
stationInfo: qsTr("From") + " " + country + ": " + genresAndTopics.split(",")[0]
stationCurrent: currentTrack ? currentTrack : "-"
menu: StationsListContextMenu {
id: contextMenu
}
Connections {
target: stationItem
onClicked: playStation(id)
}
Connections {
target: contextMenu
onRemoveFavorite: removeFavorite(station)
}
Connections {
target: contextMenu
onAddFavorite: addFavorite(id)
}
}
}
}
......@@ -62,17 +62,6 @@
<translation type="unfinished">Ställ</translation>
</message>
</context>
<context>
<name>Favorites</name>
<message>
<source>Favorites</source>
<translation>Favoriter</translation>
</message>
<message>
<source>Remove from favorite</source>
<translation>Ta bort från favoriter</translation>
</message>
</context>
<context>
<name>FavoritesListContextMenu</name>
<message>
......@@ -107,18 +96,21 @@
</message>
</context>
<context>
<name>Stations</name>
<name>StationsListContextMenu</name>
<message>
<source>Remove from favorite</source>
<translation>Ta bort från favoriter</translation>
<translation type="unfinished">Ta bort från favoriter</translation>
</message>
<message>
<source>Add to favorite</source>
<translation>Lägg till i favoriter</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StationsPageForm.ui</name>
<message>
<source>From</source>
<translation>Från</translation>
<translation type="unfinished">Från</translation>
</message>
</context>
<context>
......
......@@ -62,17 +62,6 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Favorites</name>
<message>
<source>Favorites</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove from favorite</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FavoritesListContextMenu</name>
<message>
......@@ -107,7 +96,7 @@
</message>
</context>
<context>
<name>Stations</name>
<name>StationsListContextMenu</name>
<message>
<source>Remove from favorite</source>
<translation type="unfinished"></translation>
......@@ -116,6 +105,9 @@
<source>Add to favorite</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StationsPageForm.ui</name>
<message>
<source>From</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