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

Redesign calendar #19

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
11 changes: 6 additions & 5 deletions lib/components/animes/anime_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ class AnimeComponent extends StatelessWidget {
maxLines: 2,
),
),
for (final langType in anime.langTypes)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: LangTypeComponent(langType: langType),
),
if (anime.langTypes != null)
for (final langType in anime.langTypes!)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: LangTypeComponent(langType: langType),
),
const SizedBox(height: 8),
],
),
Expand Down
75 changes: 50 additions & 25 deletions lib/components/animes/calendar_anime_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import 'package:application/components/lang_type_component.dart';
import 'package:application/components/platforms/list_platform.dart';
import 'package:application/controllers/anime_controller.dart';
import 'package:application/dtos/week_day_release_dto.dart';
import 'package:application/utils/constant.dart';
import 'package:application/views/anime_details_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:palette_generator/palette_generator.dart';

class CalendarAnimeComponent extends StatelessWidget {
static const bookmarkColor = Colors.yellow;
Expand All @@ -29,7 +31,25 @@ class CalendarAnimeComponent extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!release.isMultipleReleased) {
return buildCustomCard(context);
}

return FutureBuilder<Color>(
future: _getDominantColor(),
builder: (context, snapshot) {
final layerColor = snapshot.connectionState == ConnectionState.waiting
? null
: snapshot.data;
return buildCustomCard(context, layerColor: layerColor);
},
);
}

CustomCard buildCustomCard(BuildContext context, {Color? layerColor}) {
return CustomCard(
activateLayers: layerColor != null,
layerColor: layerColor,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
Expand All @@ -45,8 +65,10 @@ class CalendarAnimeComponent extends StatelessWidget {
Stack(
children: [
ImageComponent(
uuid: release.anime.uuid,
type: 'banner',
uuid: release.isReleased
? release.mappings.first
: release.anime.uuid,
type: release.isReleased ? 'image' : 'banner',
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
Expand Down Expand Up @@ -90,32 +112,25 @@ class CalendarAnimeComponent extends StatelessWidget {
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
if (release.isReleased)
Text(
AppLocalizations.of(context)!.minInformation(
AppLocalizations.of(context)!.episodeType(
release.episodeType!.toLowerCase(),
),
release.isMultipleReleased
? '${release.minNumber} - ${release.maxNumber}'
: release.number!,
),
style: Theme.of(context).textTheme.bodyMedium,
overflow: TextOverflow.ellipsis,
),
LangTypeComponent(langType: release.langType),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
if (release.variant != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: GestureDetector(
onTap: () {
launchUrl(
Uri.parse(release.variant!.url),
mode: LaunchMode.externalNonBrowserApplication,
);
},
child: const Icon(
Icons.live_tv_outlined,
),
),
),
WatchlistButton(anime: release.anime),
],
),
const SizedBox(width: 8),
WatchlistButton(anime: release.anime),
],
),
),
Expand All @@ -124,4 +139,14 @@ class CalendarAnimeComponent extends StatelessWidget {
),
);
}

Future<Color> _getDominantColor() async {
return (await PaletteGenerator.fromImageProvider(
Image.network(
'${Constant.apiUrl}/v1/attachments?uuid=${release.mappings.first}&type=image',
).image,
))
.dominantColor!
.color;
}
}
85 changes: 63 additions & 22 deletions lib/components/card_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ class CustomCard extends StatefulWidget {
final Color? backgroundColor;
final Function()? onTap;
final Function(TapDownDetails?)? onLongPress;
final bool activateLayers;
final Color? layerColor;

const CustomCard({
super.key,
required this.child,
this.backgroundColor,
this.onTap,
this.onLongPress,
this.activateLayers = false,
this.layerColor,
});

@override
Expand All @@ -28,29 +32,66 @@ class _CustomCardState extends State<CustomCard> {

return RepaintBoundary(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: widget.backgroundColor ?? withOpacity,
border: Border.all(
color: widget.backgroundColor ?? withOpacity,
width: 1,
),
),
child: GestureDetector(
onTap: widget.onTap,
onLongPress: () {
widget.onLongPress?.call(_tapDownDetails);
},
onTapDown: (details) {
_tapDownDetails = details;
},
child: Padding(
padding: const EdgeInsets.all(1),
child: widget.child,
padding: EdgeInsets.only(
left: 8,
right: 8,
top: widget.activateLayers ? 8 : 4,
bottom: 4,
),
child: Stack(
fit: StackFit.passthrough,
clipBehavior: Clip.none,
children: [
if (widget.activateLayers && widget.layerColor != null) ...[
Positioned(
top: -8,
left: 12,
right: 12,
height: 100,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: widget.layerColor!.withOpacity(0.5),
),
),
),
Positioned(
top: -4,
left: 6,
right: 6,
height: 100,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: widget.layerColor!,
),
),
),
],
DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: widget.backgroundColor ?? withOpacity,
border: Border.all(
color: widget.backgroundColor ?? withOpacity,
width: 1,
),
),
child: GestureDetector(
onTap: widget.onTap,
onLongPress: () {
widget.onLongPress?.call(_tapDownDetails);
},
onTapDown: (details) {
_tapDownDetails = details;
},
child: Padding(
padding: const EdgeInsets.all(1),
child: widget.child,
),
),
),
),
],
),
),
);
Expand Down
5 changes: 3 additions & 2 deletions lib/controllers/anime_weekly_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class AnimeWeeklyController {
);

streamController.add(weekDays);
} catch (e) {
debugPrint(e.toString());
} catch (exception, stackTrace) {
debugPrint(exception.toString());
debugPrint(stackTrace.toString());
} finally {
isLoading = false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/dtos/anime_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class AnimeDto with _$AnimeDto {
required String? banner,
required String? description,
required List<SimulcastDto>? simulcasts,
required List<String> audioLocales,
required List<String> langTypes,
required List<SeasonDto> seasons,
required List<String>? audioLocales,
required List<String>? langTypes,
required List<SeasonDto>? seasons,
required String? status,
}) = _AnimeDto;

Expand Down
Loading