Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26089 from davidflanagan/bug1079692-v2.0
Browse files Browse the repository at this point in the history
Bug 1079692: update video thumbnail titles asynchonously so we don't blo...
  • Loading branch information
seinlin committed Nov 13, 2014
2 parents 7bc7f75 + d5d0880 commit 807aeda
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
41 changes: 37 additions & 4 deletions apps/video/js/thumbnail_list.js
Expand Up @@ -17,7 +17,7 @@
* isSelectMode: returns if ThumbnailList is in selection mode.
* setSelectMode: set ThumbnailList as selection mode or not.
* reset: clears all the internal data structure.
* upateAllThumbnailTitle: update all thuambnail title text.
* updateAllThumbnailTitles: update all thumbnail title text.
* findNextFocused: find the next focused item after the file name.
* filename: the referenced filename.
*
Expand Down Expand Up @@ -139,9 +139,42 @@ ThumbnailList.prototype.setSelectMode = function(select) {
}
};

ThumbnailList.prototype.upateAllThumbnailTitle = function() {
for (var key in this.thumbnailMap) {
this.thumbnailMap[key].updateTitleText();
// Asynchronously call updateTitleText on all of the thumbnails
ThumbnailList.prototype.updateAllThumbnailTitles = function() {
var self = this;

// Cancel any pending title text update. Note that we cancel not by
// deleting the array but by setting its length to zero. Previous
// invocations will see this new length in their closure and will
// terminate. This handles the case where the user is switching
// orientations back and forth. We need to be sure that we don't
// keep adding work in this case.
if (this.pendingTitleTextUpdate && this.pendingTitleTextUpdate.length) {
this.pendingTitleTextUpdate.length = 0;
}

// Get a list of thumbnails that need to be updated
var thumbnailKeys = Object.keys(this.thumbnailMap);

// Remember the list in case we need to cancel it.
this.pendingTitleTextUpdate = thumbnailKeys;

setTimeout(updateNextThumbnailBatch);

function updateNextThumbnailBatch() {
// If we just do one at a time, it takes quite a bit longer
for (var i = 0; i < 10; i++) {
// If there aren't any thumbnails left, we're done
if (thumbnailKeys.length === 0) {
return;
}

// Otherwise, update the next thumbnail
var nextKey = thumbnailKeys.shift();
self.thumbnailMap[nextKey].updateTitleText();
}
// And schedule another call ASAP
setTimeout(updateNextThumbnailBatch);
}
};

Expand Down
6 changes: 3 additions & 3 deletions apps/video/js/video.js
Expand Up @@ -349,7 +349,7 @@ function handleScreenLayoutChange() {
if (!thumbnailList) {
return;
}
thumbnailList.upateAllThumbnailTitle();
thumbnailList.updateAllThumbnailTitles();
} else {
pendingUpdateTitleText = true;
}
Expand All @@ -373,7 +373,7 @@ function switchLayout(mode) {
// Update title text when leaving fullscreen mode with pending task.
if (oldMode === LAYOUT_MODE.fullscreenPlayer && pendingUpdateTitleText) {
pendingUpdateTitleText = false;
thumbnailList.upateAllThumbnailTitle();
thumbnailList.updateAllThumbnailTitles();
}
}

Expand Down Expand Up @@ -1344,7 +1344,7 @@ function showPickView() {
// view.
if (!isPhone && !isPortrait) {
// update all title text when rotating.
thumbnailList.upateAllThumbnailTitle();
thumbnailList.updateAllThumbnailTitles();
}
}

Expand Down

0 comments on commit 807aeda

Please sign in to comment.