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 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
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
32 changes: 32 additions & 0 deletions 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(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 Down Expand Up @@ -263,6 +265,36 @@ class _PlainScrollCards extends StatelessWidget {
}
}

class _ExternalLinkScrollCards extends StatelessWidget {
const _ExternalLinkScrollCards(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) => Row(
children: [
if (items[i].color != null)
Container(
padding: Consts.padding,
margin: const EdgeInsets.only(right: 10),
decoration: BoxDecoration(
borderRadius: Consts.borderRadiusMin,
color: items[i].color,
),
),
Text(items[i].site)
],
),
);
}
}

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 {
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) + 0xFF000000)
: null,
);

final String url;
final String site;
final Color? color;
}

class MediaStats {
MediaStats._();

Expand Down