[gnome-music/autopopulate: 245/245] Autopopulate on scrolling to the end of the list
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/autopopulate: 245/245] Autopopulate on scrolling to the end of the list
- Date: Fri, 7 Jun 2013 11:41:12 +0000 (UTC)
commit afbe539416984f95d8ebd4fbcb31f69a202b1843
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Fri Jun 7 13:39:49 2013 +0200
Autopopulate on scrolling to the end of the list
src/view.js | 23 ++++++++++++------
src/widgets.js | 68 ++++++++-----------------------------------------------
2 files changed, 25 insertions(+), 66 deletions(-)
---
diff --git a/src/view.js b/src/view.js
index 6959da6..a1753d0 100644
--- a/src/view.js
+++ b/src/view.js
@@ -62,7 +62,9 @@ const ViewContainer = new Lang.Class({
this._grid = new Gtk.Grid({orientation: Gtk.Orientation.VERTICAL})
this._iconWidth = -1
this._iconHeight = 128
+ this._populated = false;
this._offset = 0;
+ this._offset_old = 0;
this._adjustmentValueId = 0;
this._adjustmentChangedId = 0;
this._scrollbarVisibleId = 0;
@@ -98,9 +100,6 @@ const ViewContainer = new Lang.Class({
this._grid.add(_box);
}
- this._loadMore = new Widgets.LoadMoreButton(this._getRemainingItemCount);
- _box.pack_end(this._loadMore.widget, false, false, 0);
- this._loadMore.widget.connect("clicked", Lang.bind(this, this.populate))
this.view.connect('item-activated',
Lang.bind(this, this._onItemActivated));
this._cursor = null;
@@ -110,7 +109,6 @@ const ViewContainer = new Lang.Class({
this.show_all();
this._items = [];
- this._loadMore.widget.hide();
this._connectView();
this._symbolicIcon = albumArtCache.makeDefaultIcon(this._iconHeight, this._iconWidth);
@@ -159,7 +157,6 @@ const ViewContainer = new Lang.Class({
// if there's no vscrollbar, or if it's not visible, hide the button
if (!vScrollbar ||
!vScrollbar.get_visible()) {
- this._loadMore.setBlock(true);
return;
}
@@ -175,7 +172,12 @@ const ViewContainer = new Lang.Class({
end = !(value < (upper - page_size - revealAreaHeight));
if (this._getRemainingItemCount() <= 0)
end = false;
- this._loadMore.setBlock(!end);
+ if (end && this._populated) {
+ if ((this._offset - this._offset_old) >= 5) {
+ this._offset_old = this._offset;
+ this.populate();
+ }
+ }
},
populate: function() {
@@ -322,8 +324,10 @@ const Albums = new Lang.Class({
},
populate: function() {
+ this._populated = false;
if (grilo.tracker != null)
grilo.populateAlbums (this._offset, Lang.bind(this, this._addItem, null));
+ this._populated = true;
},
});
@@ -475,8 +479,10 @@ const Songs = new Lang.Class({
},
populate: function() {
+ this._populated = false;
if (grilo.tracker != null)
grilo.populateSongs (this._offset, Lang.bind(this, this._addItem, null));
+ this._populated = true;
},
});
@@ -594,9 +600,10 @@ const Artists = new Lang.Class({
},
populate: function () {
- if(grilo.tracker != null) {
+ this._populated = false;
+ if(grilo.tracker != null)
grilo.populateArtists(this._offset, Lang.bind(this, this._addItem, null));
//FIXME: We're emitting this too early, need to wait for all artists to be filled in
- }
+ this._populated = true;
},
});
diff --git a/src/widgets.js b/src/widgets.js
index 2b1e724..e9fcd7e 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -39,59 +39,6 @@ const albumArtCache = AlbumArtCache.AlbumArtCache.getDefault();
const nowPlayingIconName = 'media-playback-start-symbolic';
const errorIconName = 'dialog-error-symbolic';
-const LoadMoreButton = new Lang.Class({
- Name: 'LoadMoreButton',
- _init: function(counter) {
- this._block = false;
- this._counter = counter;
- let child = new Gtk.Grid({ column_spacing: 10,
- hexpand: false,
- halign: Gtk.Align.CENTER,
- visible: true });
-
- this._spinner = new Gtk.Spinner({ halign: Gtk.Align.CENTER,
- no_show_all: true });
- this._spinner.set_size_request(16, 16);
- child.add(this._spinner);
-
- this._label = new Gtk.Label({ label: "Load More",
- visible: true });
- child.add(this._label);
-
- this.widget = new Gtk.Button({ no_show_all: true,
- child: child });
- this.widget.get_style_context().add_class('documents-load-more');
- this.widget.connect('clicked', Lang.bind(this,
- function() {
- this._label.label = "Loading...";
- this._spinner.show();
- this._spinner.start();
- }));
-
- this._onItemCountChanged();
- },
-
- _onItemCountChanged: function() {
- let remainingDocs = this._counter();
- let visible = !(remainingDocs <= 0 || this._block);
- this.widget.set_visible(visible);
-
- if (!visible) {
- this._label.label = "Load More";
- this._spinner.stop();
- this._spinner.hide();
- }
- },
-
- setBlock: function(block) {
- if (this._block == block)
- return;
-
- this._block = block;
- this._onItemCountChanged();
- }
-});
-
const AlbumWidget = new Lang.Class({
Name: "AlbumWidget",
Extends: Gtk.EventBox,
@@ -422,9 +369,8 @@ const AllArtistsAlbums = new Lang.Class({
this.parent("All Artists", [], player);
this._offset = 0;
this.countQuery = Query.album_count;
- this._loadMore = new LoadMoreButton(Lang.bind(this, this._getRemainingItemCount));
- this.pack_end(this._loadMore.widget, false, false, 0);
- this._loadMore.widget.connect("clicked", Lang.bind(this, this._populate))
+ this._populated = false;
+ this._offset_old = 0;
this._connectView();
this._populate();
},
@@ -453,7 +399,6 @@ const AllArtistsAlbums = new Lang.Class({
// if there's no vscrollbar, or if it's not visible, hide the button
if (!vScrollbar ||
!vScrollbar.get_visible()) {
- this._loadMore.setBlock(true);
return;
}
@@ -469,11 +414,17 @@ const AllArtistsAlbums = new Lang.Class({
end = !(value < (upper - page_size - revealAreaHeight));
if (this._getRemainingItemCount() <= 0)
end = false;
- this._loadMore.setBlock(!end);
+ if (end && this._populated) {
+ if ((this._offset - this._offset_old) >= 5) {
+ this._offset_old = this._offset;
+ this._populate();
+ }
+ }
},
_populate: function () {
+ this._populated = false;
if (grilo.tracker != null)
grilo.populateAlbums (this._offset, Lang.bind(this,
function (source, param, item, remaining) {
@@ -482,6 +433,7 @@ const AllArtistsAlbums = new Lang.Class({
this.addAlbum(item);
}
}), 5);
+ this._populated = true;
},
_getRemainingItemCount: function () {let count = -1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]