multipage: faster default page
This commit is contained in:
parent
a6b99e7c2a
commit
b0cccd7d2d
5 changed files with 51 additions and 51 deletions
|
@ -98,21 +98,26 @@ class AvesEntry {
|
|||
|
||||
AvesEntry getPageEntry(SinglePageInfo pageInfo) {
|
||||
if (pageInfo == null) return this;
|
||||
return AvesPageEntry(
|
||||
pageInfo: pageInfo,
|
||||
|
||||
// do not provide the page ID for the default page,
|
||||
// so that we can treat this page like the main entry
|
||||
// and retrieve cached images for it
|
||||
final pageId = pageInfo.isDefault ? null : pageInfo.pageId;
|
||||
|
||||
return AvesEntry(
|
||||
uri: uri,
|
||||
path: path,
|
||||
contentId: contentId,
|
||||
pageId: pageInfo.pageId,
|
||||
sourceMimeType: sourceMimeType,
|
||||
width: width,
|
||||
height: height,
|
||||
pageId: pageId,
|
||||
sourceMimeType: pageInfo.mimeType ?? sourceMimeType,
|
||||
width: pageInfo.width ?? width,
|
||||
height: pageInfo.height ?? height,
|
||||
sourceRotationDegrees: sourceRotationDegrees,
|
||||
sizeBytes: sizeBytes,
|
||||
sourceTitle: sourceTitle,
|
||||
dateModifiedSecs: dateModifiedSecs,
|
||||
sourceDateTakenMillis: sourceDateTakenMillis,
|
||||
durationMillis: durationMillis,
|
||||
durationMillis: pageInfo.durationMillis ?? durationMillis,
|
||||
)
|
||||
..catalogMetadata = _catalogMetadata?.copyWith(
|
||||
mimeType: pageInfo.mimeType,
|
||||
|
|
|
@ -9,7 +9,9 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension ExtraAvesEntry on AvesEntry {
|
||||
ThumbnailProvider getThumbnail({double extent = 0}) => ThumbnailProvider(_getThumbnailProviderKey(extent));
|
||||
ThumbnailProvider getThumbnail({double extent = 0}) {
|
||||
return ThumbnailProvider(_getThumbnailProviderKey(extent));
|
||||
}
|
||||
|
||||
ThumbnailProviderKey _getThumbnailProviderKey(double extent) {
|
||||
// we standardize the thumbnail loading dimension by taking the nearest larger power of 2
|
||||
|
@ -28,9 +30,11 @@ extension ExtraAvesEntry on AvesEntry {
|
|||
);
|
||||
}
|
||||
|
||||
RegionProvider getRegion({@required int sampleSize, Rectangle<int> region}) => RegionProvider(getRegionProviderKey(sampleSize, region));
|
||||
RegionProvider getRegion({@required int sampleSize, Rectangle<int> region}) {
|
||||
return RegionProvider(_getRegionProviderKey(sampleSize, region));
|
||||
}
|
||||
|
||||
RegionProviderKey getRegionProviderKey(int sampleSize, Rectangle<int> region) {
|
||||
RegionProviderKey _getRegionProviderKey(int sampleSize, Rectangle<int> region) {
|
||||
return RegionProviderKey(
|
||||
uri: uri,
|
||||
mimeType: mimeType,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:aves/model/entry.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class MultiPageInfo {
|
||||
|
@ -8,12 +7,23 @@ class MultiPageInfo {
|
|||
|
||||
MultiPageInfo({
|
||||
this.pages,
|
||||
});
|
||||
}) {
|
||||
if (pages.isNotEmpty) {
|
||||
pages.sort();
|
||||
// make sure there is a page marked as default
|
||||
if (defaultPage == null) {
|
||||
final firstPage = pages.removeAt(0);
|
||||
pages.insert(0, firstPage.copyWith(isDefault: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
factory MultiPageInfo.fromPageMaps(List<Map> pageMaps) {
|
||||
return MultiPageInfo(pages: pageMaps.map((page) => SinglePageInfo.fromMap(page)).toList());
|
||||
}
|
||||
|
||||
SinglePageInfo get defaultPage => pages.firstWhere((page) => page.isDefault, orElse: () => null);
|
||||
|
||||
SinglePageInfo getByIndex(int index) => pages.firstWhere((page) => page.index == index, orElse: () => null);
|
||||
|
||||
SinglePageInfo getById(int pageId) => pages.firstWhere((page) => page.pageId == pageId, orElse: () => null);
|
||||
|
@ -22,13 +32,13 @@ class MultiPageInfo {
|
|||
String toString() => '$runtimeType#${shortHash(this)}{pages=$pages}';
|
||||
}
|
||||
|
||||
class SinglePageInfo {
|
||||
class SinglePageInfo implements Comparable<SinglePageInfo> {
|
||||
final int index, pageId;
|
||||
final String mimeType;
|
||||
final bool isDefault;
|
||||
final int width, height, durationMillis;
|
||||
|
||||
SinglePageInfo({
|
||||
const SinglePageInfo({
|
||||
this.index,
|
||||
this.pageId,
|
||||
this.mimeType,
|
||||
|
@ -38,6 +48,20 @@ class SinglePageInfo {
|
|||
this.durationMillis,
|
||||
});
|
||||
|
||||
SinglePageInfo copyWith({
|
||||
bool isDefault,
|
||||
}) {
|
||||
return SinglePageInfo(
|
||||
index: index,
|
||||
pageId: pageId,
|
||||
mimeType: mimeType,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
width: width,
|
||||
height: height,
|
||||
durationMillis: durationMillis,
|
||||
);
|
||||
}
|
||||
|
||||
factory SinglePageInfo.fromMap(Map map) {
|
||||
final index = map['page'] as int;
|
||||
return SinglePageInfo(
|
||||
|
@ -53,39 +77,7 @@ class SinglePageInfo {
|
|||
|
||||
@override
|
||||
String toString() => '$runtimeType#${shortHash(this)}{index=$index, pageId=$pageId, mimeType=$mimeType, isDefault=$isDefault, width=$width, height=$height, durationMillis=$durationMillis}';
|
||||
}
|
||||
|
||||
class AvesPageEntry extends AvesEntry {
|
||||
final SinglePageInfo pageInfo;
|
||||
|
||||
AvesPageEntry({
|
||||
@required this.pageInfo,
|
||||
String uri,
|
||||
String path,
|
||||
int contentId,
|
||||
int pageId,
|
||||
String sourceMimeType,
|
||||
int width,
|
||||
int height,
|
||||
int sourceRotationDegrees,
|
||||
int sizeBytes,
|
||||
String sourceTitle,
|
||||
int dateModifiedSecs,
|
||||
int sourceDateTakenMillis,
|
||||
int durationMillis,
|
||||
}) : super(
|
||||
uri: uri,
|
||||
path: path,
|
||||
contentId: contentId,
|
||||
pageId: pageId,
|
||||
sourceMimeType: pageInfo.mimeType ?? sourceMimeType,
|
||||
width: pageInfo.width ?? width,
|
||||
height: pageInfo.height ?? height,
|
||||
sourceRotationDegrees: sourceRotationDegrees,
|
||||
sizeBytes: sizeBytes,
|
||||
sourceTitle: sourceTitle,
|
||||
dateModifiedSecs: dateModifiedSecs,
|
||||
sourceDateTakenMillis: sourceDateTakenMillis,
|
||||
durationMillis: pageInfo.durationMillis ?? durationMillis,
|
||||
);
|
||||
@override
|
||||
int compareTo(SinglePageInfo other) => index.compareTo(other.index);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@ class MultiPageController extends ChangeNotifier {
|
|||
|
||||
MultiPageController(AvesEntry entry) {
|
||||
info = MetadataService.getMultiPageInfo(entry).then((value) {
|
||||
final defaultPage = value.pages.firstWhere((page) => page.isDefault, orElse: () => null);
|
||||
pageNotifier.value = defaultPage?.index ?? 0;
|
||||
pageNotifier.value = value.defaultPage.index;
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ class _PositionTitleRow extends StatelessWidget {
|
|||
// but fail to get information about these pages
|
||||
final pageCount = multiPageInfo.pageCount;
|
||||
if (pageCount > 0) {
|
||||
final page = multiPageInfo.getById(entry.pageId);
|
||||
final page = multiPageInfo.getById(entry.pageId) ?? multiPageInfo.defaultPage;
|
||||
pagePosition = '${(page?.index ?? 0) + 1}/$pageCount';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue