Commit fb46a71e authored by kempe's avatar kempe
Browse files

Refactored Favorite page part of #6

* Extracted components
* Decided in .qml and .ui.qml
parent f832d5a0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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
+20 −0
Original line number Diff line number Diff line
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)
            });
        }
    }
}
+48 −0
Original line number Diff line number Diff line
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 !== ""
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ ApplicationWindow
    initialPage: favorites
    cover: Qt.resolvedUrl("cover/CoverPage.qml")

    Favorites {
    FavoritesPage {
        id: favorites
    }

qml/pages/Favorites.qml

deleted100644 → 0
+0 −110
Original line number Diff line number Diff line
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)
    }
}

Loading