mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Improve comic image loading retry
This commit is contained in:
@@ -9,7 +9,7 @@ abstract class GlobalState {
|
||||
|
||||
static T find<T extends State>([Object? key]) {
|
||||
for (var pair in _state) {
|
||||
if (pair.left == key && pair.right is T) {
|
||||
if ((key == null || pair.left == key) && pair.right is T) {
|
||||
return pair.right as T;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ abstract class GlobalState {
|
||||
|
||||
static T? findOrNull<T extends State>([Object? key]) {
|
||||
for (var pair in _state) {
|
||||
if (pair.left == key && pair.right is T) {
|
||||
if ((key == null || pair.left == key) && pair.right is T) {
|
||||
return pair.right as T;
|
||||
}
|
||||
}
|
||||
|
@@ -24,8 +24,7 @@ class ComicImage extends StatefulWidget {
|
||||
Map<String, String>? headers,
|
||||
int? cacheWidth,
|
||||
int? cacheHeight,
|
||||
}
|
||||
): image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, image),
|
||||
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, image),
|
||||
assert(cacheWidth == null || cacheWidth > 0),
|
||||
assert(cacheHeight == null || cacheHeight > 0);
|
||||
|
||||
@@ -138,8 +137,8 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
void _updateInvertColors() {
|
||||
_invertColors = MediaQuery.maybeInvertColorsOf(context)
|
||||
?? SemanticsBinding.instance.accessibilityFeatures.invertColors;
|
||||
_invertColors = MediaQuery.maybeInvertColorsOf(context) ??
|
||||
SemanticsBinding.instance.accessibilityFeatures.invertColors;
|
||||
}
|
||||
|
||||
void _resolveImage() {
|
||||
@@ -150,12 +149,15 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
final ImageStream newStream =
|
||||
provider.resolve(createLocalImageConfiguration(
|
||||
context,
|
||||
size: widget.width != null && widget.height != null ? Size(widget.width!, widget.height!) : null,
|
||||
size: widget.width != null && widget.height != null
|
||||
? Size(widget.width!, widget.height!)
|
||||
: null,
|
||||
));
|
||||
_updateSourceStream(newStream);
|
||||
}
|
||||
|
||||
ImageStreamListener? _imageStreamListener;
|
||||
|
||||
ImageStreamListener _getListener({bool recreateListener = false}) {
|
||||
if (_imageStreamListener == null || recreateListener) {
|
||||
_lastException = null;
|
||||
@@ -191,7 +193,8 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
|
||||
void _replaceImage({required ImageInfo? info}) {
|
||||
final ImageInfo? oldImageInfo = _imageInfo;
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) => oldImageInfo?.dispose());
|
||||
SchedulerBinding.instance
|
||||
.addPostFrameCallback((_) => oldImageInfo?.dispose());
|
||||
_imageInfo = info;
|
||||
}
|
||||
|
||||
@@ -208,7 +211,9 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
if (!widget.gaplessPlayback) {
|
||||
setState(() { _replaceImage(info: null); });
|
||||
setState(() {
|
||||
_replaceImage(info: null);
|
||||
});
|
||||
}
|
||||
|
||||
setState(() {
|
||||
@@ -247,7 +252,9 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
return;
|
||||
}
|
||||
|
||||
if (keepStreamAlive && _completerHandle == null && _imageStream?.completer != null) {
|
||||
if (keepStreamAlive &&
|
||||
_completerHandle == null &&
|
||||
_imageStream?.completer != null) {
|
||||
_completerHandle = _imageStream!.completer!.keepAlive();
|
||||
}
|
||||
|
||||
@@ -269,26 +276,41 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(_lastException.toString(), maxLines: 3,),
|
||||
child: Text(
|
||||
_lastException.toString(),
|
||||
maxLines: 3,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4,),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 4,
|
||||
),
|
||||
MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: Listener(
|
||||
onPointerDown: (details) {
|
||||
GlobalState.find<_ReaderGestureDetectorState>().ignoreNextTap();
|
||||
setState(() {
|
||||
_loadingProgress = null;
|
||||
_lastException = null;
|
||||
});
|
||||
_resolveImage();
|
||||
},
|
||||
child: const SizedBox(
|
||||
child: SizedBox(
|
||||
width: 84,
|
||||
height: 36,
|
||||
child: Center(
|
||||
child: Text("Retry", style: TextStyle(color: Colors.blue),),
|
||||
child: Text(
|
||||
"Retry".tl,
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16,),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -302,10 +324,8 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
|
||||
if (_imageInfo != null) {
|
||||
// Record the height and the width of the image
|
||||
_cache[widget.image.hashCode] = Size(
|
||||
_imageInfo!.image.width.toDouble(),
|
||||
_imageInfo!.image.height.toDouble()
|
||||
);
|
||||
_cache[widget.image.hashCode] = Size(_imageInfo!.image.width.toDouble(),
|
||||
_imageInfo!.image.height.toDouble());
|
||||
}
|
||||
|
||||
Size? cacheSize = _cache[widget.image.hashCode];
|
||||
@@ -379,11 +399,12 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
backgroundColor: context.colorScheme.surfaceContainerLow,
|
||||
backgroundColor: context.colorScheme.surfaceContainer,
|
||||
value: (_loadingProgress != null &&
|
||||
_loadingProgress!.expectedTotalBytes != null &&
|
||||
_loadingProgress!.expectedTotalBytes! != 0)
|
||||
?_loadingProgress!.cumulativeBytesLoaded / _loadingProgress!.expectedTotalBytes!
|
||||
? _loadingProgress!.cumulativeBytesLoaded /
|
||||
_loadingProgress!.expectedTotalBytes!
|
||||
: 0,
|
||||
),
|
||||
),
|
||||
@@ -398,8 +419,10 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
||||
super.debugFillProperties(description);
|
||||
description.add(DiagnosticsProperty<ImageStream>('stream', _imageStream));
|
||||
description.add(DiagnosticsProperty<ImageInfo>('pixels', _imageInfo));
|
||||
description.add(DiagnosticsProperty<ImageChunkEvent>('loadingProgress', _loadingProgress));
|
||||
description.add(DiagnosticsProperty<ImageChunkEvent>(
|
||||
'loadingProgress', _loadingProgress));
|
||||
description.add(DiagnosticsProperty<int>('frameNumber', _frameNumber));
|
||||
description.add(DiagnosticsProperty<bool>('wasSynchronouslyLoaded', _wasSynchronouslyLoaded));
|
||||
description.add(DiagnosticsProperty<bool>(
|
||||
'wasSynchronouslyLoaded', _wasSynchronouslyLoaded));
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ class _ReaderGestureDetector extends StatefulWidget {
|
||||
State<_ReaderGestureDetector> createState() => _ReaderGestureDetectorState();
|
||||
}
|
||||
|
||||
class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDetector> {
|
||||
late TapGestureRecognizer _tapGestureRecognizer;
|
||||
|
||||
static const _kDoubleTapMaxTime = Duration(milliseconds: 200);
|
||||
@@ -26,6 +26,12 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
|
||||
late _ReaderState reader;
|
||||
|
||||
bool ignoreNextTag = false;
|
||||
|
||||
void ignoreNextTap() {
|
||||
ignoreNextTag = true;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_tapGestureRecognizer = TapGestureRecognizer()
|
||||
@@ -44,6 +50,10 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (event) {
|
||||
fingers++;
|
||||
if (ignoreNextTag) {
|
||||
ignoreNextTag = false;
|
||||
return;
|
||||
}
|
||||
_lastTapPointer = event.pointer;
|
||||
_lastTapMoveDistance = Offset.zero;
|
||||
_tapGestureRecognizer.addPointer(event);
|
||||
@@ -290,6 +300,9 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
void removeDragListener(_DragListener listener) {
|
||||
_dragListeners.remove(listener);
|
||||
}
|
||||
|
||||
@override
|
||||
Object? get key => "reader_gesture";
|
||||
}
|
||||
|
||||
class _DragListener {
|
||||
|
@@ -22,6 +22,7 @@ import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/global_state.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/reader_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
|
Reference in New Issue
Block a user