Skip to content

Commit

Permalink
Localize amazon links
Browse files Browse the repository at this point in the history
Fixes #661
  • Loading branch information
Feichtmeier committed May 12, 2024
1 parent f9ee6d8 commit ff83492
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
54 changes: 43 additions & 11 deletions lib/src/common/stream_provider_share_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_tabler_icons/flutter_tabler_icons.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../get.dart';
import '../app/app_model.dart';
import 'icons.dart';
import '../l10n/l10n.dart';

Expand Down Expand Up @@ -40,17 +42,8 @@ class StreamProviderShareButton extends StatelessWidget {
final clearedText =
text?.replaceAll(RegExp(r"[:/?#\[\]@!$&'()*+,;=%]"), ' ') ?? '';

final address = switch (streamProvider) {
StreamProvider.youTubeMusic =>
'https://music.youtube.com/search?q=$clearedText',
StreamProvider.appleMusic =>
'https://music.apple.com/us/search?term=$clearedText',
StreamProvider.spotify => 'https://open.spotify.com/search/$clearedText',
StreamProvider.amazonMusic =>
'https://music.amazon.de/search/$clearedText?filter=IsLibrary%7Cfalse&sc=none',
StreamProvider.amazon =>
'https://www.amazon.de/s?k=$clearedText&i=digital-music'
};
String address = buildAddress(clearedText);

return IconButton(
tooltip: onSearch != null
? context.l10n.search
Expand All @@ -70,6 +63,45 @@ class StreamProviderShareButton extends StatelessWidget {
),
);
}

String buildAddress(String query) {
final address = switch (streamProvider) {
StreamProvider.youTubeMusic =>
'https://music.youtube.com/search?q=$query',
StreamProvider.appleMusic =>
'https://music.apple.com/us/search?term=$query',
StreamProvider.spotify => 'https://open.spotify.com/search/$query',
StreamProvider.amazonMusic =>
'https://music.amazon.${getAmazonSuffix()}/search/$query?filter=IsLibrary%7Cfalse&sc=none',
StreamProvider.amazon =>
'https://www.amazon.${getAmazonSuffix()}/s?k=$query&i=digital-music'
};
return address;
}

String getAmazonSuffix() {
final countryCode = getIt<AppModel>().countryCode;
return switch (countryCode) {
'au' => 'com.au',
'at' => 'at',
'br' => 'com.br',
'ca' => 'ca',
'fr' => 'fr',
'de' => 'de',
'in' => 'in',
'it' => 'it',
'jp' => 'co.jp',
'mx' => 'com.mx',
'nl' => 'nl',
'pl' => 'pl',
'sg' => 'com.sg',
'es' => 'es',
'ae' => 'ae',
'uk' || 'ie' => 'co.uk',
'us' => 'com',
_ => 'com',
};
}
}

class StreamProviderRow extends StatelessWidget {
Expand Down
9 changes: 7 additions & 2 deletions lib/src/player/view/player_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class PlayerTrack extends StatelessWidget with WatchItMixin {
disabledThumbRadius: bottomPlayer ? 0 : 5.0,
);

final bufferActive = active &&
buffer != null &&
position != null &&
buffer.inSeconds >= position.inSeconds;
final secondaryTrackValue =
bufferActive ? buffer.inSeconds.toDouble() : 0.0;
final slider = Tooltip(
preferBelow: false,
message:
Expand All @@ -65,8 +71,7 @@ class PlayerTrack extends StatelessWidget with WatchItMixin {
min: 0,
max: sliderActive ? duration.inSeconds.toDouble() : 1.0,
value: sliderActive ? position.inSeconds.toDouble() : 0,
secondaryTrackValue:
sliderActive ? buffer?.inSeconds.toDouble() : 0,
secondaryTrackValue: secondaryTrackValue,
onChanged: sliderActive
? (v) async {
setPosition(Duration(seconds: v.toInt()));
Expand Down

0 comments on commit ff83492

Please sign in to comment.