~ahayzen/music-app/trackqueue-speedup

« back to all changes in this revision

Viewing changes to MusicNowPlaying.qml

  • Committer: Andrew Hayzen
  • Date: 2014-08-24 23:00:11 UTC
  • Revision ID: ahayzen@gmail.com-20140824230011-p493z1n0txedfa9u
* Use worker loaded trackQueueUI infront of trackQueue

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
                return;
56
56
            }
57
57
 
58
 
            queuelist.currentIndex = player.currentIndex;
59
 
 
60
58
            customdebug("MusicQueue update currentIndex: " + player.source);
61
59
 
62
60
            // Always jump to current track
70
68
        // If the toolbar is shown, the page is now playing and snaptrack is enabled
71
69
        if (shown && currentPage === nowPlaying && Settings.getSetting("snaptrack") === "1")
72
70
        {
73
 
            // Then position the view at the current index
74
 
            queuelist.positionViewAtIndex(queuelist.currentIndex, ListView.Beginning);
 
71
 
 
72
            // Only jump if the item has been created otherwise jump on load
 
73
            if (queuelist.count >= player.currentIndex && trackQueueUI.workerCompleted) {
 
74
                // Then position the view at the current index
 
75
                queuelist.positionViewAtIndex(player.currentIndex, ListView.Beginning);
 
76
            } else {
 
77
                queuelist.jumpOnLoad = player.currentIndex
 
78
            }
75
79
        }
76
80
    }
77
81
 
78
82
    function positionAt(index) {
79
 
        queuelist.positionViewAtIndex(index, ListView.Beginning);
80
 
        queuelist.contentY -= header.height;
 
83
        if (queuelist.count >= index && trackQueueUI.workerCompleted) {
 
84
            queuelist.positionViewAtIndex(index, ListView.Beginning);
 
85
            queuelist.contentY -= header.height;
 
86
        } else {
 
87
            queuelist.jumpOnLoad = index
 
88
        }
81
89
    }
82
90
 
83
91
    ListView {
86
94
        anchors.fill: parent
87
95
        anchors.bottomMargin: musicToolbar.mouseAreaOffset + musicToolbar.minimizedHeight
88
96
        delegate: queueDelegate
89
 
        //model: trackQueue.model
 
97
        model: trackQueueUI.model
90
98
        highlightFollowsCurrentItem: false
91
99
        state: "normal"
92
100
        states: [
113
121
        property int currentHeight: units.gu(48)
114
122
        property int transitionDuration: 250  // transition length of animations
115
123
 
 
124
        property int jumpOnLoad: -1
 
125
 
116
126
        onCountChanged: {
117
 
            customdebug("Queue: Now has: " + queuelist.count + " tracks")
 
127
            customdebug("Queue: Now has: " + queuelist.count + " tracks" + " " + jumpOnLoad)
 
128
 
 
129
            if (jumpOnLoad < count && jumpOnLoad !== -1) {  // < due to count being +1 to index
 
130
                positionAtAfterDelay.start()
 
131
            }
118
132
        }
119
133
 
120
134
        onMovementStarted: {
121
135
            musicToolbar.hideToolbar();
122
136
        }
123
137
 
 
138
        Timer {
 
139
            id: positionAtAfterDelay
 
140
            interval: 250
 
141
            repeat: false
 
142
            onTriggered: {
 
143
                // Then position the view at the current index
 
144
                queuelist.positionViewAtIndex(queuelist.jumpOnLoad, ListView.Beginning);
 
145
 
 
146
                queuelist.jumpOnLoad = -1
 
147
            }
 
148
        }
 
149
 
124
150
        Component {
125
151
            id: queueDelegate
126
152
            ListItemWithActions {
127
153
                id: queueListItem
128
154
                color: "transparent"
129
155
                height: queuelist.normalHeight
130
 
                state: queuelist.currentIndex == index && !reordering ? "current" : ""
 
156
                state: player.currentIndex == index && !reordering ? "current" : ""
131
157
 
132
158
                leftSideAction: Remove {
133
159
                    onTriggered: {
140
166
                            player.currentIndex -= 1;
141
167
                        }
142
168
 
143
 
                        queuelist.model.remove(index);
 
169
                        trackQueueUI.remove(index);
144
170
                    }
145
171
                }
146
172
                reorderable: true
158
184
                onReorder: {
159
185
                    console.debug("Move: ", from, to);
160
186
 
161
 
                    queuelist.model.move(from, to, 1);
162
 
 
 
187
                    trackQueueUI.move(from, to, 1);
163
188
 
164
189
                    // Maintain currentIndex with current song
165
190
                    if (from === player.currentIndex) {