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

Proposed by Corentin Noël
Status: Merged
Approved by: Danielle Foré
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 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.
Revision history for this message
Danielle Foré (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?

Revision history for this message
Danielle Foré (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
398. By Corentin Noël

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
=== modified file 'src/AbstractAppList.vala'
--- src/AbstractAppList.vala 2016-09-14 16:58:13 +0000
+++ src/AbstractAppList.vala 2017-02-15 18:04:46 +0000
@@ -43,6 +43,15 @@
43 action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);43 action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
44 }44 }
4545
46 public virtual void add_packages (Gee.Collection<AppCenterCore.Package> packages) {
47 foreach (var package in packages) {
48 var row = make_row (package);
49 set_up_row (row);
50 }
51
52 after_add_remove_change_row ();
53 }
54
46 public virtual void add_package (AppCenterCore.Package package) {55 public virtual void add_package (AppCenterCore.Package package) {
47 var row = make_row (package);56 var row = make_row (package);
48 set_up_row (row);57 set_up_row (row);
@@ -64,7 +73,7 @@
64 after_add_remove_change_row ();73 after_add_remove_change_row ();
65 }74 }
6675
67 public void clear () {76 public virtual void clear () {
68 foreach (var r in list_box.get_children ()) {77 foreach (var r in list_box.get_children ()) {
69 var row = (Widgets.AppListRow)r;78 var row = (Widgets.AppListRow)r;
70 if (row.has_package ()) {79 if (row.has_package ()) {
@@ -85,7 +94,7 @@
8594
86 protected virtual void after_add_remove_change_row () {}95 protected virtual void after_add_remove_change_row () {}
8796
88 protected Gee.Collection<AppCenterCore.Package> get_packages () {97 protected virtual Gee.Collection<AppCenterCore.Package> get_packages () {
89 var tree_set = new Gee.TreeSet<AppCenterCore.Package> ();98 var tree_set = new Gee.TreeSet<AppCenterCore.Package> ();
90 foreach (var r in list_box.get_children ()) {99 foreach (var r in list_box.get_children ()) {
91 var row = (Widgets.AppListRow)r;100 var row = (Widgets.AppListRow)r;
92101
=== modified file 'src/Views/AppListView.vala'
--- src/Views/AppListView.vala 2017-02-04 17:18:30 +0000
+++ src/Views/AppListView.vala 2017-02-15 18:04:46 +0000
@@ -22,12 +22,64 @@
22namespace AppCenter.Views {22namespace AppCenter.Views {
23 /** AppList for Category and Search Views. Sorts by name and does not show Uninstall Button **/23 /** AppList for Category and Search Views. Sorts by name and does not show Uninstall Button **/
24 public class AppListView : AbstractAppList {24 public class AppListView : AbstractAppList {
25 private uint current_visible_index = 0U;
26 private GLib.ListStore list_store;
2527
26 public AppListView () {}28 public AppListView () {}
2729
30 construct {
31 list_store = new GLib.ListStore (typeof (AppCenterCore.Package));
32 edge_reached.connect ((position) => {
33 if (position == Gtk.PositionType.BOTTOM) {
34 show_more_apps ();
35 }
36 });
37 }
38
39 public override void add_packages (Gee.Collection<AppCenterCore.Package> packages) {
40 list_store.splice (0, 0, (GLib.Object[]) packages.to_array ());
41 list_store.sort ((GLib.CompareDataFunc<AppCenterCore.Package>) compare_packages);
42 if (current_visible_index < 20) {
43 show_more_apps ();
44 }
45 }
46
47 public override void add_package (AppCenterCore.Package package) {
48 list_store.insert_sorted (package, (GLib.CompareDataFunc<AppCenterCore.Package>) compare_packages);
49 if (current_visible_index < 20) {
50 show_more_apps ();
51 }
52 }
53
54 public override void clear () {
55 base.clear ();
56 list_store.remove_all ();
57 current_visible_index = 0U;
58 }
59
28 protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {60 protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
29 return (Widgets.AppListRow)(new Widgets.PackageRow.list (package, action_button_group, false));61 return (Widgets.AppListRow)(new Widgets.PackageRow.list (package, action_button_group, false));
30 }62 }
63
64 // Show 20 more apps on the listbox
65 private void show_more_apps () {
66 uint old_index = current_visible_index;
67 while (current_visible_index < list_store.get_n_items ()) {
68 var package = (AppCenterCore.Package?) list_store.get_object (current_visible_index);
69 var row = make_row (package);
70 set_up_row (row);
71 current_visible_index++;
72 if (old_index + 20 < current_visible_index) {
73 break;
74 }
75 }
76
77 after_add_remove_change_row ();
78 }
79
80 private static int compare_packages (AppCenterCore.Package p1, AppCenterCore.Package p2) {
81 return p1.get_name ().collate (p2.get_name ());
82 }
31 }83 }
3284
33 /** AppList for the Updates View. Sorts update_available first and shows headers.85 /** AppList for the Updates View. Sorts update_available first and shows headers.
3486
=== modified file 'src/Views/CategoryView.vala'
--- src/Views/CategoryView.vala 2016-10-26 12:59:05 +0000
+++ src/Views/CategoryView.vala 2017-02-15 18:04:46 +0000
@@ -96,9 +96,7 @@
9696
97 unowned Client client = Client.get_default ();97 unowned Client client = Client.get_default ();
98 var apps = client.get_applications_for_category (category);98 var apps = client.get_applications_for_category (category);
99 foreach (var app in apps) {99 app_list_view.add_packages (apps);
100 app_list_view.add_package (app);
101 }
102100
103 }101 }
104102
105103
=== modified file 'src/Views/InstalledView.vala'
--- src/Views/InstalledView.vala 2016-09-22 14:10:06 +0000
+++ src/Views/InstalledView.vala 2017-02-15 18:04:46 +0000
@@ -55,9 +55,7 @@
55 unowned Client client = Client.get_default ();55 unowned Client client = Client.get_default ();
5656
57 var installed_apps = yield client.get_installed_applications ();57 var installed_apps = yield client.get_installed_applications ();
58 foreach (var app in installed_apps) {58 app_list_view.add_packages (installed_apps);
59 app_list_view.add_package (app);
60 }
6159
62 yield client.get_updates ();60 yield client.get_updates ();
63 }61 }
6462
=== modified file 'src/Views/SearchView.vala'
--- src/Views/SearchView.vala 2016-10-07 17:58:37 +0000
+++ src/Views/SearchView.vala 2017-02-15 18:04:46 +0000
@@ -21,7 +21,6 @@
21using AppCenterCore;21using AppCenterCore;
2222
23public class AppCenter.Views.SearchView : View {23public class AppCenter.Views.SearchView : View {
24 const int MAX_NUMBER_OF_SEARCH_RESULTS = 100;
25 AppListView app_list_view;24 AppListView app_list_view;
2625
27 public SearchView () {26 public SearchView () {
@@ -46,15 +45,6 @@
46 app_list_view.clear ();45 app_list_view.clear ();
47 unowned Client client = Client.get_default ();46 unowned Client client = Client.get_default ();
48 var found_apps = client.search_applications (search_term, category);47 var found_apps = client.search_applications (search_term, category);
49 48 app_list_view.add_packages (found_apps);
50 if (found_apps.size > 0) {
51 var apps_array = found_apps.to_array ();
52 int i = 0;
53 while (i < apps_array.length && i < MAX_NUMBER_OF_SEARCH_RESULTS) {
54 var app = apps_array[i];
55 app_list_view.add_package (app);
56 i++;
57 }
58 }
59 }49 }
60}50}

Subscribers

People subscribed via source and target branches