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

Double-click unlikes is odd #524

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions lib/ui/widgets/cached_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ class CachedImage extends CachedNetworkImage {
BoxFit super.fit = BoxFit.cover,
Duration super.fadeOutDuration = const Duration(milliseconds: 200),
super.fadeInDuration = const Duration(milliseconds: 200),
required String placeholder,
String? placeholder,
}) : super(
key: ValueKey(imageUrl),
cacheManager: cache.ThaliaCacheManager(),
cacheKey: _getCacheKey(imageUrl),
placeholder: (_, __) => Image.asset(placeholder, fit: fit),
placeholder: placeholder == null
? null
: (_, __) => Image.asset(placeholder, fit: fit),
);
}

Expand Down
36 changes: 28 additions & 8 deletions lib/ui/widgets/gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:reaxit/models.dart';
import 'package:reaxit/ui/theme.dart';
import 'package:share_plus/share_plus.dart';
import 'package:gal/gal.dart';
import 'package:reaxit/ui/widgets/cached_image.dart';

abstract class GalleryCubit<T> extends StateStreamableSource<T> {
Future<void> updateLike({required bool liked, required int index});
Expand Down Expand Up @@ -121,6 +122,23 @@ class _GalleryState<C extends GalleryCubit> extends State<Gallery>
}

Future<void> _likePhoto(List<AlbumPhoto> photos, int index) async {
final messenger = ScaffoldMessenger.of(context);
likeController.forward();
try {
await BlocProvider.of<C>(context).updateLike(
liked: true,
index: index,
);
} on ApiException {
messenger.showSnackBar(
const SnackBar(
content: Text('Something went wrong while liking the photo.'),
),
);
}
}

Future<void> _toggleLikePhoto(List<AlbumPhoto> photos, int index) async {
final messenger = ScaffoldMessenger.of(context);
if (photos[index].liked) {
unlikeController.forward();
Expand Down Expand Up @@ -169,9 +187,11 @@ class _GalleryState<C extends GalleryCubit> extends State<Gallery>
child = GestureDetector(
onDoubleTap: () => _likePhoto(photos, i),
child: RotatedBox(
quarterTurns: photos[i].rotation ~/ 90,
child: Image.network(photos[i].full),
),
quarterTurns: photos[i].rotation ~/ 90,
child: CachedImage(
imageUrl: photos[i].full,
fit: BoxFit.contain,
)),
);
} else {
child = const Center(
Expand All @@ -181,7 +201,7 @@ class _GalleryState<C extends GalleryCubit> extends State<Gallery>

return PhotoViewGalleryPageOptions.customChild(
child: child,
minScale: PhotoViewComputedScale.contained * 0.8,
minScale: PhotoViewComputedScale.contained * 1,
maxScale: PhotoViewComputedScale.covered * 2,
);
},
Expand Down Expand Up @@ -238,7 +258,7 @@ class _GalleryState<C extends GalleryCubit> extends State<Gallery>
widget.initialPage,
widget.photos,
widget.photoAmount,
_likePhoto,
_toggleLikePhoto,
_loadMorePhotos,
),
),
Expand Down Expand Up @@ -295,15 +315,15 @@ class _PageCounter extends StatefulWidget {
final int initialPage;
final List<AlbumPhoto> photos;
final int photoAmount;
final void Function(List<AlbumPhoto> photos, int index) likePhoto;
final void Function(List<AlbumPhoto> photos, int index) toggleLikePhoto;
final void Function() loadMorePhotos;

const _PageCounter(
this.controller,
this.initialPage,
this.photos,
this.photoAmount,
this.likePhoto,
this.toggleLikePhoto,
this.loadMorePhotos,
);

Expand Down Expand Up @@ -363,7 +383,7 @@ class __PageCounterState extends State<_PageCounter> {
photo.liked ? Icons.favorite : Icons.favorite_outline,
),
onPressed: () {
widget.likePhoto(
widget.toggleLikePhoto(
widget.photos,
currentIndex,
);
Expand Down
Loading