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)
property int _currentPage: bookListWatcher.currentIndex
property bool _loading: minLoadingDelay.running || !bookModel.pageCount
property bool _pagerVisible: (_currentState.pager && book && bookModel.pageCount) ? 1 : 0
property bool _loading: minLoadingDelay.running || bookModel.loading
property var _currentState: _visibilityStates[settings.pageDetails % _visibilityStates.length]
readonly property var _visibilityStates: [
{ pager: false, page: false, title: false, tools: false },
@ -204,50 +203,45 @@ SilicaFlickable {
}
pageCount: bookModel.pageCount
width: parent.width
opacity: _pagerVisible ? 1 : 0
visible: opacity > 0
opacity: _currentState.pager ? 1 : 0
visible: opacity > 0 && book && bookModel.pageCount && !_loading
onPageChanged: bookView.jumpTo(page)
Behavior on opacity { FadeAnimation {} }
}
Column {
id: loadingAnimation
BusyIndicator {
id: busyIndicator
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: _loading
}
BooksFitLabel {
anchors {
fill: busyIndicator
margins: Theme.paddingMedium
}
maxFontSize: Theme.fontSizeMedium
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
text: bookModel.progress > 0 ? bookModel.progress : ""
visible: opacity > 0
opacity: (_loading && bookModel.progress) > 0 ? 1 : 0
Behavior on opacity { FadeAnimation {} }
}
Label {
anchors {
top: busyIndicator.bottom
topMargin: Theme.paddingLarge
horizontalCenter: busyIndicator.horizontalCenter
}
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
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 {
id: busyIndicator
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: _loading
}
BooksFitLabel {
anchors {
fill: parent
margins: Theme.paddingMedium
}
maxFontSize: Theme.fontSizeMedium
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
text: bookModel.progress > 0 ? bookModel.progress : ""
visible: opacity > 0
opacity: bookModel.progress > 0 ? 1 : 0
Behavior on opacity { FadeAnimation {} }
}
}
Label {
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
//% "Loading..."
text: qsTrId("book-view-loading")
}
//% "Loading..."
text: qsTrId("book-view-loading")
}
}

View file

@ -403,19 +403,32 @@ void BooksBookModel::setSize(QSize aSize)
HDEBUG("size didn't change");
} else if (iData2 && iData2->iWidth == w && iData2->iHeight == h) {
HDEBUG("switching to backup layout");
const int oldPageCount(pageCount());
BooksPos page1 = pageMark(iCurrentPage);
BooksPos page2 = pageMark(iCurrentPage+1);
const int oldModelPageCount = pageCount();
int oldPageCount;
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;
iData = iData2;
iData2 = tmp;
if (iData) {
// Cancel unnecessary paging task
if (iTask) {
BooksLoadingSignalBlocker block(this);
iTask->release(this);
iTask = NULL;
}
updateModel(oldPageCount);
updateModel(oldModelPageCount);
Q_EMIT pageMarksChanged();
Q_EMIT jumpToPage(iData->pickPage(page1, page2, oldPageCount));
} else {
@ -459,6 +472,8 @@ void BooksBookModel::startReset(bool aFullReset)
iData = NULL;
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,
iBook->lastPos(), oldPageCount);
iTaskQueue->submit(iTask);
@ -483,7 +498,9 @@ void BooksBookModel::startReset(bool aFullReset)
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;
Q_EMIT progressChanged();
}