Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After rotate, scroll the view back to the event we were looking at #990

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions www/js/EventCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ angular.module('zmApp.controllers')
'large':$translate.instant('kEventViewThumbsLarge'),
};

var currEventNum = 0;
var currEventPos = 0;
var currOrientation;

//---------------------------------------------------
// initial code
Expand All @@ -87,12 +90,40 @@ angular.module('zmApp.controllers')
$scope.$on('sizechanged', function() {
recomputeRowHeights();
$ionicScrollDelegate.resize();
$timeout (function() {
navTitle();
},300);

NVR.debug("screen.orientation.type: " + screen.orientation.type);
if (currOrientation != screen.orientation.type) {
//$scope.$apply();
NVR.debug("sizechanged, scroll to item: " + currEventNum + ", postion: " + currEventPos);
scrollTo(currEventNum, currEventPos);
currOrientation = screen.orientation.type;
} else {
$timeout (function() {
navTitle();
},300);
}
});

function scrollTo(eventNum, eventPos) {
var eventHeightCounter = 0;
var i = 0;
var lastEventHeight = 0;
//loop until we pass the event...
for (i = 0; i < $scope.events.length; i++) {
lastEventHeight = getRowHeight($scope.events[i]);
if ( i >= eventNum ) {
//$scope.navTitle = ($scope.events[i].Event.humanizeTime); // we don't need to update the navTitle as we're staying in the same place
break;
}
//console.log(getRowHeight($scope.events[i]));
eventHeightCounter = eventHeightCounter + lastEventHeight;
}
var scrl = eventHeightCounter + (lastEventHeight * eventPos);
//console.log("eventHeightCounter: " + eventHeightCounter + " lastEventHeight: " + lastEventHeight + ", scrl To " + scrl + ", len: " + $scope.events.length);
NVR.debug("scrollTo: " + scrl);
$ionicScrollDelegate.$getByHandle("mainScroll").scrollTo(0, scrl, false);
}

function getRowHeight(event) {
var ld = NVR.getLogin();
var rowHeight = 134; // ViewThumbs == none
Expand Down Expand Up @@ -176,6 +207,7 @@ angular.module('zmApp.controllers')
timedPageReload();
}.bind(this), zm.eventPageRefresh);

currOrientation = screen.orientation.type;
});

function timedPageReload() {
Expand Down Expand Up @@ -2247,14 +2279,18 @@ angular.module('zmApp.controllers')
$scope.navTitle = "";
} else {
var eventHeightCounter = 0;
var i;
//loop until we pass the event...
for (var i = 0; i < $scope.events.length; i++) {
for (i = 0; i < $scope.events.length; i++) {
eventHeightCounter = eventHeightCounter + getRowHeight($scope.events[i]);
if ( eventHeightCounter > scrl ) {
$scope.navTitle = ($scope.events[i].Event.humanizeTime);
break;
}
}
currEventNum = i;
currEventPos = 1 - ((eventHeightCounter - scrl) / getRowHeight($scope.events[i]));
//console.log("i: " + i + " scrl: " + scrl + " " + currEventPos);
}
$scope.$evalAsync();
//return Math.random();
Expand Down