Merge lp:~tintou/appcenter/lazy-loading into lp:~elementary-apps/appcenter/appcenter

Proposed by Corentin Noël on 2017-02-15
Status: Merged
Approved by: Daniel Fore on 2017-02-15
Approved revision: 398
Merged at revision: 400
Proposed branch: lp:~tintou/appcenter/lazy-loading
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 165 lines (+66/-19)
5 files modified
src/AbstractAppList.vala (+11/-2)
src/Views/AppListView.vala (+52/-0)
src/Views/CategoryView.vala (+1/-3)
src/Views/InstalledView.vala (+1/-3)
src/Views/SearchView.vala (+1/-11)
To merge this branch: bzr merge lp:~tintou/appcenter/lazy-loading
Reviewer Review Type Date Requested Status
elementary Apps team 2017-02-15 Pending
Review via email: mp+317311@code.launchpad.net

Commit message

Use lazy loading of apps in categories and search.
This removes the limit of results that can appear in the search view.

Description of the change

Load apps on-demand into the view

To post a comment you must log in.
Daniel Fore (danrabbit) wrote :

I can confirm that all categories open instantly now!

But I feel like we need some kind of feedback to indicate that more results are being loaded when you scroll to the end. Can we temporarily pack a spinner?

Daniel Fore (danrabbit) wrote :

After talking to Corentin, it seems like just connected to `edge_reached` instead of `edge_overshot` fixes the issue I was experiencing

lp:~tintou/appcenter/lazy-loading updated on 2017-02-15
398. By Corentin Noël on 2017-02-15

Use lazy loading of apps in categories and search.

This removes the limit of results that can appear in the search view.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/AbstractAppList.vala'
2--- src/AbstractAppList.vala 2016-09-14 16:58:13 +0000
3+++ src/AbstractAppList.vala 2017-02-15 18:04:46 +0000
4@@ -43,6 +43,15 @@
5 action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
6 }
7
8+ public virtual void add_packages (Gee.Collection<AppCenterCore.Package> packages) {
9+ foreach (var package in packages) {
10+ var row = make_row (package);
11+ set_up_row (row);
12+ }
13+
14+ after_add_remove_change_row ();
15+ }
16+
17 public virtual void add_package (AppCenterCore.Package package) {
18 var row = make_row (package);
19 set_up_row (row);
20@@ -64,7 +73,7 @@
21 after_add_remove_change_row ();
22 }
23
24- public void clear () {
25+ public virtual void clear () {
26 foreach (var r in list_box.get_children ()) {
27 var row = (Widgets.AppListRow)r;
28 if (row.has_package ()) {
29@@ -85,7 +94,7 @@
30
31 protected virtual void after_add_remove_change_row () {}
32
33- protected Gee.Collection<AppCenterCore.Package> get_packages () {
34+ protected virtual Gee.Collection<AppCenterCore.Package> get_packages () {
35 var tree_set = new Gee.TreeSet<AppCenterCore.Package> ();
36 foreach (var r in list_box.get_children ()) {
37 var row = (Widgets.AppListRow)r;
38
39=== modified file 'src/Views/AppListView.vala'
40--- src/Views/AppListView.vala 2017-02-04 17:18:30 +0000
41+++ src/Views/AppListView.vala 2017-02-15 18:04:46 +0000
42@@ -22,12 +22,64 @@
43 namespace AppCenter.Views {
44 /** AppList for Category and Search Views. Sorts by name and does not show Uninstall Button **/
45 public class AppListView : AbstractAppList {
46+ private uint current_visible_index = 0U;
47+ private GLib.ListStore list_store;
48
49 public AppListView () {}
50
51+ construct {
52+ list_store = new GLib.ListStore (typeof (AppCenterCore.Package));
53+ edge_reached.connect ((position) => {
54+ if (position == Gtk.PositionType.BOTTOM) {
55+ show_more_apps ();
56+ }
57+ });
58+ }
59+
60+ public override void add_packages (Gee.Collection<AppCenterCore.Package> packages) {
61+ list_store.splice (0, 0, (GLib.Object[]) packages.to_array ());
62+ list_store.sort ((GLib.CompareDataFunc<AppCenterCore.Package>) compare_packages);
63+ if (current_visible_index < 20) {
64+ show_more_apps ();
65+ }
66+ }
67+
68+ public override void add_package (AppCenterCore.Package package) {
69+ list_store.insert_sorted (package, (GLib.CompareDataFunc<AppCenterCore.Package>) compare_packages);
70+ if (current_visible_index < 20) {
71+ show_more_apps ();
72+ }
73+ }
74+
75+ public override void clear () {
76+ base.clear ();
77+ list_store.remove_all ();
78+ current_visible_index = 0U;
79+ }
80+
81 protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
82 return (Widgets.AppListRow)(new Widgets.PackageRow.list (package, action_button_group, false));
83 }
84+
85+ // Show 20 more apps on the listbox
86+ private void show_more_apps () {
87+ uint old_index = current_visible_index;
88+ while (current_visible_index < list_store.get_n_items ()) {
89+ var package = (AppCenterCore.Package?) list_store.get_object (current_visible_index);
90+ var row = make_row (package);
91+ set_up_row (row);
92+ current_visible_index++;
93+ if (old_index + 20 < current_visible_index) {
94+ break;
95+ }
96+ }
97+
98+ after_add_remove_change_row ();
99+ }
100+
101+ private static int compare_packages (AppCenterCore.Package p1, AppCenterCore.Package p2) {
102+ return p1.get_name ().collate (p2.get_name ());
103+ }
104 }
105
106 /** AppList for the Updates View. Sorts update_available first and shows headers.
107
108=== modified file 'src/Views/CategoryView.vala'
109--- src/Views/CategoryView.vala 2016-10-26 12:59:05 +0000
110+++ src/Views/CategoryView.vala 2017-02-15 18:04:46 +0000
111@@ -96,9 +96,7 @@
112
113 unowned Client client = Client.get_default ();
114 var apps = client.get_applications_for_category (category);
115- foreach (var app in apps) {
116- app_list_view.add_package (app);
117- }
118+ app_list_view.add_packages (apps);
119
120 }
121
122
123=== modified file 'src/Views/InstalledView.vala'
124--- src/Views/InstalledView.vala 2016-09-22 14:10:06 +0000
125+++ src/Views/InstalledView.vala 2017-02-15 18:04:46 +0000
126@@ -55,9 +55,7 @@
127 unowned Client client = Client.get_default ();
128
129 var installed_apps = yield client.get_installed_applications ();
130- foreach (var app in installed_apps) {
131- app_list_view.add_package (app);
132- }
133+ app_list_view.add_packages (installed_apps);
134
135 yield client.get_updates ();
136 }
137
138=== modified file 'src/Views/SearchView.vala'
139--- src/Views/SearchView.vala 2016-10-07 17:58:37 +0000
140+++ src/Views/SearchView.vala 2017-02-15 18:04:46 +0000
141@@ -21,7 +21,6 @@
142 using AppCenterCore;
143
144 public class AppCenter.Views.SearchView : View {
145- const int MAX_NUMBER_OF_SEARCH_RESULTS = 100;
146 AppListView app_list_view;
147
148 public SearchView () {
149@@ -46,15 +45,6 @@
150 app_list_view.clear ();
151 unowned Client client = Client.get_default ();
152 var found_apps = client.search_applications (search_term, category);
153-
154- if (found_apps.size > 0) {
155- var apps_array = found_apps.to_array ();
156- int i = 0;
157- while (i < apps_array.length && i < MAX_NUMBER_OF_SEARCH_RESULTS) {
158- var app = apps_array[i];
159- app_list_view.add_package (app);
160- i++;
161- }
162- }
163+ app_list_view.add_packages (found_apps);
164 }
165 }

Subscribers

People subscribed via source and target branches