Skip to content

Commit

Permalink
fix: flags not showing up, html in descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 4, 2023
1 parent d8cf2ae commit 5a563ef
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 22 deletions.
35 changes: 22 additions & 13 deletions lib/components/shared/playbutton_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import 'package:spotube/hooks/use_breakpoint_value.dart';
import 'package:spotube/hooks/use_brightness_value.dart';
import 'package:spotube/utils/platform.dart';

final htmlTagRegexp = RegExp(r"<[^>]*>", caseSensitive: true);

String? useDescription(String? description) {
return useMemoized(() {
if (description == null) return null;
return description.replaceAll(htmlTagRegexp, '');
}, [description]);
}

class PlaybuttonCard extends HookWidget {
final void Function()? onTap;
final void Function()? onPlaybuttonPressed;
Expand Down Expand Up @@ -40,19 +49,17 @@ class PlaybuttonCard extends HookWidget {
final radius = BorderRadius.circular(15);

final double size = useBreakpointValue<double>(
xs: 130,
sm: 130,
md: 150,
others: 170,
) ??
170;
xs: 130,
sm: 130,
md: 150,
others: 170,
);

final end = useBreakpointValue<double>(
xs: 15,
sm: 15,
others: 20,
) ??
20;
xs: 15,
sm: 15,
others: 20,
);

final textsHeight = useState(
(textsKey.currentContext?.findRenderObject() as RenderBox?)
Expand All @@ -61,6 +68,8 @@ class PlaybuttonCard extends HookWidget {
110.00,
);

final cleanDescription = useDescription(description);

useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) {
textsHeight.value =
Expand Down Expand Up @@ -123,11 +132,11 @@ class PlaybuttonCard extends HookWidget {
overflow: TextOverflow.ellipsis,
),
),
if (description != null)
if (cleanDescription != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: AutoSizeText(
description!,
cleanDescription,
maxLines: 2,
style: theme.textTheme.bodySmall?.copyWith(
color:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/album/album_card.dart';
import 'package:spotube/components/shared/image/universal_image.dart';
import 'package:spotube/components/shared/playbutton_card.dart';
import 'package:spotube/extensions/constrains.dart';
import 'package:spotube/extensions/context.dart';

Expand Down Expand Up @@ -42,6 +43,8 @@ class TrackCollectionHeading<T> extends HookConsumerWidget {
Widget build(BuildContext context, ref) {
final theme = Theme.of(context);

final cleanDescription = useDescription(description);

return LayoutBuilder(
builder: (context, constrains) {
return DecoratedBox(
Expand Down Expand Up @@ -111,13 +114,13 @@ class TrackCollectionHeading<T> extends HookConsumerWidget {
fontWeight: FontWeight.normal,
),
),
if (description != null)
if (cleanDescription != null)
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: constrains.mdAndDown ? 400 : 300,
),
child: Text(
description!,
cleanDescription,
style: const TextStyle(color: Colors.white),
maxLines: 2,
overflow: TextOverflow.fade,
Expand Down
27 changes: 23 additions & 4 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:piped_client/piped_client.dart';
import 'package:spotube/collections/env.dart';
Expand Down Expand Up @@ -323,17 +324,35 @@ class SettingsPage extends HookConsumerWidget {
title:
Text(context.l10n.piped_instance),
subtitle: Text(
context.l10n.piped_description),
context.l10n.piped_description,
),
value: preferences.pipedInstance,
showValueWhenUnfolded: false,
options: data
.sortedBy((e) => e.name)
.map(
(e) => DropdownMenuItem(
value: e.apiUrl,
child: Text(
"${e.name}\n"
"${e.locations.map(countryCodeToEmoji).join(" ")}",
child: RichText(
text: TextSpan(
children: [
TextSpan(
text:
"${e.name.trim()}\n",
style: Theme.of(context)
.textTheme
.labelLarge,
),
TextSpan(
text: e.locations
.map(
countryCodeToEmoji)
.join(""),
style: GoogleFonts
.notoColorEmoji(),
),
],
),
),
),
)
Expand Down
6 changes: 3 additions & 3 deletions lib/provider/user_preferences_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class UserPreferences extends PersistedChangeNotifier {
this.checkUpdate = true,
this.audioQuality = AudioQuality.high,
this.downloadLocation = "",
this.closeBehavior = CloseBehavior.minimizeToTray,
this.closeBehavior = CloseBehavior.close,
this.showSystemTrayIcon = true,
this.locale = const Locale("system", "system"),
this.pipedInstance = "https://pipedapi.kavin.rocks",
this.searchMode = SearchMode.youtube,
this.searchMode = SearchMode.youtubeMusic,
this.skipNonMusic = true,
this.youtubeApiType = YoutubeApiType.youtube,
this.youtubeApiType = YoutubeApiType.piped,
}) : super() {
if (downloadLocation.isEmpty) {
_getDefaultDownloadDirectory().then(
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.6"
google_fonts:
dependency: "direct main"
description:
name: google_fonts
sha256: "6b6f10f0ce3c42f6552d1c70d2c28d764cf22bb487f50f66cca31dcd5194f4d6"
url: "https://pub.dev"
source: hosted
version: "4.0.4"
gotrue:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ dependencies:
disable_battery_optimization: ^1.1.0+1
youtube_explode_dart: ^1.12.4
flutter_displaymode: ^0.6.0
google_fonts: ^4.0.4

dev_dependencies:
build_runner: ^2.3.2
Expand Down

0 comments on commit 5a563ef

Please sign in to comment.