Fixed a few issues with re-paging after rotation

The situation when device is rotated before the current paging task
has completed wasn't handled correctly. E.g. current book position
wasn't restored after rotating the device back, page count in the
progress indicator wasn't restarted etc.
This commit is contained in:
Slava Monich 2015-07-11 04:56:38 +03:00
parent d6cacd2fd1
commit 213828811c
2 changed files with 56 additions and 45 deletions

View file

@ -43,8 +43,7 @@ SilicaFlickable {
signal pageClicked(var page) signal pageClicked(var page)
property int _currentPage: bookListWatcher.currentIndex property int _currentPage: bookListWatcher.currentIndex
property bool _loading: minLoadingDelay.running || !bookModel.pageCount property bool _loading: minLoadingDelay.running || bookModel.loading
property bool _pagerVisible: (_currentState.pager && book && bookModel.pageCount) ? 1 : 0
property var _currentState: _visibilityStates[settings.pageDetails % _visibilityStates.length] property var _currentState: _visibilityStates[settings.pageDetails % _visibilityStates.length]
readonly property var _visibilityStates: [ readonly property var _visibilityStates: [
{ pager: false, page: false, title: false, tools: false }, { pager: false, page: false, title: false, tools: false },
@ -204,23 +203,12 @@ SilicaFlickable {
} }
pageCount: bookModel.pageCount pageCount: bookModel.pageCount
width: parent.width width: parent.width
opacity: _pagerVisible ? 1 : 0 opacity: _currentState.pager ? 1 : 0
visible: opacity > 0 visible: opacity > 0 && book && bookModel.pageCount && !_loading
onPageChanged: bookView.jumpTo(page) onPageChanged: bookView.jumpTo(page)
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
Column {
id: loadingAnimation
opacity: _loading ? 1 : 0
visible: opacity > 0
anchors.centerIn: parent
spacing: Theme.paddingLarge
Behavior on opacity { FadeAnimation {} }
Item {
width: busyIndicator.width
height: busyIndicator.height
anchors.horizontalCenter: parent.horizontalCenter
BusyIndicator { BusyIndicator {
id: busyIndicator id: busyIndicator
anchors.centerIn: parent anchors.centerIn: parent
@ -229,7 +217,7 @@ SilicaFlickable {
} }
BooksFitLabel { BooksFitLabel {
anchors { anchors {
fill: parent fill: busyIndicator
margins: Theme.paddingMedium margins: Theme.paddingMedium
} }
maxFontSize: Theme.fontSizeMedium maxFontSize: Theme.fontSizeMedium
@ -238,16 +226,22 @@ SilicaFlickable {
color: Theme.highlightColor color: Theme.highlightColor
text: bookModel.progress > 0 ? bookModel.progress : "" text: bookModel.progress > 0 ? bookModel.progress : ""
visible: opacity > 0 visible: opacity > 0
opacity: bookModel.progress > 0 ? 1 : 0 opacity: (_loading && bookModel.progress) > 0 ? 1 : 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
}
Label { Label {
anchors.horizontalCenter: parent.horizontalCenter anchors {
top: busyIndicator.bottom
topMargin: Theme.paddingLarge
horizontalCenter: busyIndicator.horizontalCenter
}
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor color: Theme.highlightColor
opacity: _loading ? 1 : 0
visible: opacity > 0
Behavior on opacity { FadeAnimation {} }
//% "Loading..." //% "Loading..."
text: qsTrId("book-view-loading") text: qsTrId("book-view-loading")
} }
} }
}

View file

@ -403,19 +403,32 @@ void BooksBookModel::setSize(QSize aSize)
HDEBUG("size didn't change"); HDEBUG("size didn't change");
} else if (iData2 && iData2->iWidth == w && iData2->iHeight == h) { } else if (iData2 && iData2->iWidth == w && iData2->iHeight == h) {
HDEBUG("switching to backup layout"); HDEBUG("switching to backup layout");
const int oldPageCount(pageCount()); const int oldModelPageCount = pageCount();
BooksPos page1 = pageMark(iCurrentPage); int oldPageCount;
BooksPos page2 = pageMark(iCurrentPage+1); BooksPos page1, page2;
if (iTask) {
// Layout has been switched back before the paging task
// has completed
HDEBUG("not so fast please...");
oldPageCount = iTask->iOldPageCount;
page1 = iTask->iPagePos;
page2 = iTask->iNextPagePos;
} else {
oldPageCount = oldModelPageCount;
page1 = pageMark(iCurrentPage);
page2 = pageMark(iCurrentPage+1);
}
Data* tmp = iData; Data* tmp = iData;
iData = iData2; iData = iData2;
iData2 = tmp; iData2 = tmp;
if (iData) { if (iData) {
// Cancel unnecessary paging task // Cancel unnecessary paging task
if (iTask) { if (iTask) {
BooksLoadingSignalBlocker block(this);
iTask->release(this); iTask->release(this);
iTask = NULL; iTask = NULL;
} }
updateModel(oldPageCount); updateModel(oldModelPageCount);
Q_EMIT pageMarksChanged(); Q_EMIT pageMarksChanged();
Q_EMIT jumpToPage(iData->pickPage(page1, page2, oldPageCount)); Q_EMIT jumpToPage(iData->pickPage(page1, page2, oldPageCount));
} else { } else {
@ -459,6 +472,8 @@ void BooksBookModel::startReset(bool aFullReset)
iData = NULL; iData = NULL;
if (iBook && width() > 0 && height() > 0) { if (iBook && width() > 0 && height() > 0) {
HDEBUG("starting" << qPrintable(QString("%1x%2").arg(width()).
arg(height())) << "paging");
iTask = new Task(this, iBook->bookRef(), thisPage, nextPage, iTask = new Task(this, iBook->bookRef(), thisPage, nextPage,
iBook->lastPos(), oldPageCount); iBook->lastPos(), oldPageCount);
iTaskQueue->submit(iTask); iTaskQueue->submit(iTask);
@ -483,7 +498,9 @@ void BooksBookModel::startReset(bool aFullReset)
void BooksBookModel::onResetProgress(int aProgress) void BooksBookModel::onResetProgress(int aProgress)
{ {
if (iTask && aProgress > iProgress) { // progress -> onResetProgress is a queued connection, we may received
// this event from the task that has already been canceled.
if (iTask == sender() && aProgress > iProgress) {
iProgress = aProgress; iProgress = aProgress;
Q_EMIT progressChanged(); Q_EMIT progressChanged();
} }