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

Show external links for media #86

Merged
merged 8 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions lib/common/utils/graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ abstract class GqlQuery {
siteUrl
rankings {rank type year season allTime}
stats {scoreDistribution {score amount} statusDistribution {status amount}}
externalLinks {url site color}
relations {
edges {
relationType(version: 2)
Expand Down
30 changes: 29 additions & 1 deletion lib/modules/media/media_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class MediaInfoView extends StatelessWidget {
discoverType: DiscoverType.studio,
),
),
if (info.externalLinks.isNotEmpty)
_ExternalLinkScrollCards(items: info.externalLinks),
if (info.hashtag != null) _Title('Hashtag', info.hashtag!),
if (info.romajiTitle != null) _Title('Romaji', info.romajiTitle!),
if (info.englishTitle != null) _Title('English', info.englishTitle!),
Expand All @@ -185,6 +187,7 @@ class _ScrollCards extends StatelessWidget {
required this.onTap,
required this.onLongPress,
this.trailingAction,
this.color,
});

final String title;
Expand All @@ -193,6 +196,7 @@ class _ScrollCards extends StatelessWidget {
final void Function(int) onTap;
final void Function(int) onLongPress;
final Widget? trailingAction;
final Color? Function(int)? color;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -225,8 +229,12 @@ class _ScrollCards extends StatelessWidget {
onLongPress: () => onLongPress(i),
child: Card(
margin: const EdgeInsets.only(right: 10),
child: Padding(
child: Container(
padding: Consts.padding,
decoration: BoxDecoration(
borderRadius: Consts.borderRadiusMin,
color: color != null ? color!(i) : null,
),
child: builder(context, i),
),
),
Expand Down Expand Up @@ -263,6 +271,26 @@ class _PlainScrollCards extends StatelessWidget {
}
}

class _ExternalLinkScrollCards extends StatelessWidget {
const _ExternalLinkScrollCards({
crxssed7 marked this conversation as resolved.
Show resolved Hide resolved
required this.items,
});

final List<ExternalLink> items;

@override
Widget build(BuildContext context) {
return _ScrollCards(
title: "External Links",
itemCount: items.length,
onTap: (i) => Toast.launch(context, items[i].url),
onLongPress: (i) => Toast.copy(context, items[i].url),
builder: (context, i) => Text(items[i].site),
color: (i) => items[i].color,
);
}
}

class _TagScrollCards extends StatefulWidget {
const _TagScrollCards(this.info, this.ref);

Expand Down
25 changes: 25 additions & 0 deletions lib/modules/media/media_models.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:otraku/modules/collection/collection_models.dart';
import 'package:otraku/common/models/paged.dart';
Expand Down Expand Up @@ -308,6 +309,7 @@ class MediaInfo {
final String? siteUrl;
final String? countryOfOrigin;
final bool isAdult;
final externalLinks = <ExternalLink>[];

factory MediaInfo(Map<String, dynamic> map) {
String? duration;
Expand Down Expand Up @@ -380,10 +382,33 @@ class MediaInfo {
}
}

if (map['externalLinks'] != null) {
for (final link in map['externalLinks']) {
model.externalLinks.add(ExternalLink(link));
}
}

return model;
}
}

class ExternalLink {
final String url;
crxssed7 marked this conversation as resolved.
Show resolved Hide resolved
final String site;
final Color? color;

ExternalLink._({required this.url, required this.site, required this.color});

factory ExternalLink(Map<String, dynamic> map) => ExternalLink._(
lotusprey marked this conversation as resolved.
Show resolved Hide resolved
url: map['url'],
site: map['site'],
color: map['color'] != null
? Color(
int.parse(map['color'].substring(1, 7), radix: 16) + 0x8C000000)
: null,
lotusprey marked this conversation as resolved.
Show resolved Hide resolved
);
}

class MediaStats {
MediaStats._();

Expand Down