~ahayzen/ubuntu-weather-app/transparent-legacy-listitems

« back to all changes in this revision

Viewing changes to app/ui/HomePage.qml

* Split day delegate extra info into a separate component that is loaded on demand
* Use ListView per Location Pane so that scrolling vertically only affect the currently focused pane.

Approved by Ubuntu Phone Apps Jenkins Bot, Victor Thompson.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
    }
94
94
 
95
95
    /*
96
 
      Flickable to scroll the location vertically.
97
 
      The respective contentHeight gets calculated after the Location is filled with data.
 
96
      ListView for locations with snap-scrolling horizontally.
98
97
    */
99
 
    Flickable {
100
 
        id: locationFlickable
101
 
        width: parent.width
102
 
        height: parent.height
103
 
 
104
 
        // FIXME: not sure where the 3GU comes from, PullToRefresh or something in HomePage?
105
 
        contentHeight: locationPages.currentItem ? locationPages.currentItem.childrenRect.height + units.gu(3) : 0
106
 
        contentWidth: parent.width
107
 
 
108
 
        Behavior on contentHeight {
109
 
            NumberAnimation {
110
 
 
111
 
            }
112
 
        }
113
 
 
114
 
        PullToRefresh {
115
 
            id: pullToRefresh
116
 
            parent: locationFlickable
117
 
            refreshing: false
118
 
            onRefresh: {
119
 
                locationPages.loaded = false
120
 
                refreshing = true
121
 
                refreshData(false, true)
122
 
            }
123
 
        }
124
 
 
125
 
        /*
126
 
          ListView for locations with snap-scrolling horizontally.
127
 
        */
128
 
        ListView {
129
 
            id: locationPages
130
 
            objectName: "locationPages"
131
 
            anchors.fill: parent
132
 
            currentIndex: settings.current
133
 
            delegate: LocationPane {}
134
 
            height: childrenRect.height
135
 
            highlightRangeMode: ListView.StrictlyEnforceRange
136
 
            model: weatherApp.locationsList.length
137
 
            orientation: ListView.Horizontal
138
 
            // TODO with snapMode, currentIndex is not properly set and setting currentIndex fails
139
 
            //snapMode: ListView.SnapOneItem
140
 
            width: parent.width
141
 
 
142
 
            property bool loaded: false
143
 
 
144
 
            signal collapseOtherDelegates(int index)
145
 
 
146
 
            onCurrentIndexChanged: {
147
 
                if (loaded) {
148
 
                    // FIXME: when a model is reloaded this causes the currentIndex to be lost
149
 
                    settings.current = currentIndex
150
 
 
151
 
                    collapseOtherDelegates(-1)  // collapse all
152
 
                }
153
 
            }
154
 
            onModelChanged: {
155
 
                currentIndex = settings.current
156
 
 
157
 
                if (model > 0) {
158
 
                    pullToRefresh.refreshing = false
159
 
                    loading = false
160
 
                    loaded = true
161
 
                }
162
 
            }
163
 
            onVisibleChanged: {
164
 
                if (!visible && loaded) {
165
 
                    collapseOtherDelegates(-1)  // collapse all
166
 
                }
167
 
            }
168
 
 
169
 
            // TODO: workaround for not being able to use snapMode property
170
 
            Component.onCompleted: {
171
 
                var scaleFactor = units.gridUnit * 10;
172
 
                maximumFlickVelocity = maximumFlickVelocity * scaleFactor;
173
 
                flickDeceleration = flickDeceleration * scaleFactor;
174
 
            }
175
 
 
176
 
            Connections {
177
 
                target: settings
178
 
                onCurrentChanged: {
179
 
                    locationPages.currentIndex = settings.current
180
 
                }
 
98
    ListView {
 
99
        id: locationPages
 
100
        objectName: "locationPages"
 
101
        anchors.fill: parent
 
102
        contentHeight: parent.height
 
103
        currentIndex: settings.current
 
104
        delegate: LocationPane {}
 
105
        highlightRangeMode: ListView.StrictlyEnforceRange
 
106
        model: weatherApp.locationsList.length
 
107
        orientation: ListView.Horizontal
 
108
        // TODO with snapMode, currentIndex is not properly set and setting currentIndex fails
 
109
        //snapMode: ListView.SnapOneItem
 
110
 
 
111
        property bool loaded: false
 
112
 
 
113
        signal collapseOtherDelegates(int index)
 
114
 
 
115
        onCurrentIndexChanged: {
 
116
            if (loaded) {
 
117
                // FIXME: when a model is reloaded this causes the currentIndex to be lost
 
118
                settings.current = currentIndex
 
119
 
 
120
                collapseOtherDelegates(-1)  // collapse all
 
121
            }
 
122
        }
 
123
        onModelChanged: {
 
124
            currentIndex = settings.current
 
125
 
 
126
            if (model > 0) {
 
127
                loading = false
 
128
                loaded = true
 
129
            }
 
130
        }
 
131
        onVisibleChanged: {
 
132
            if (!visible && loaded) {
 
133
                collapseOtherDelegates(-1)  // collapse all
 
134
            }
 
135
        }
 
136
 
 
137
        // TODO: workaround for not being able to use snapMode property
 
138
        Component.onCompleted: {
 
139
            var scaleFactor = units.gridUnit * 10;
 
140
            maximumFlickVelocity = maximumFlickVelocity * scaleFactor;
 
141
            flickDeceleration = flickDeceleration * scaleFactor;
 
142
        }
 
143
 
 
144
        Connections {
 
145
            target: settings
 
146
            onCurrentChanged: {
 
147
                locationPages.currentIndex = settings.current
181
148
            }
182
149
        }
183
150
    }