Skip to content

Commit

Permalink
chore: move datasafe mode check lower
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Jan 22, 2025
1 parent c3ddadc commit b09a955
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
2 changes: 0 additions & 2 deletions lib/app/view/mobile_musicpod_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class _MobileMusicPodAppState extends State<MobileMusicPodApp> {
? MobilePage(page: page)
: const SplashScreen(),
),
transitionsBuilder: (_, a, __, c) =>
FadeTransition(opacity: a, child: c),
);
},
debugShowCheckedModeBanner: false,
Expand Down
26 changes: 2 additions & 24 deletions lib/app/view/mobile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,16 @@ import '../../podcasts/podcast_search_state.dart';
import '../../podcasts/view/podcast_snackbar_contents.dart';
import '../../settings/settings_model.dart';
import '../app_model.dart';
import '../connectivity_model.dart';
import 'mobile_bottom_bar.dart';

class MobilePage extends StatefulWidget with WatchItStatefulWidgetMixin {
class MobilePage extends StatelessWidget with WatchItMixin {
const MobilePage({
super.key,
required this.page,
});

final Widget page;

@override
State<MobilePage> createState() => _MobilePageState();
}

class _MobilePageState extends State<MobilePage> {
@override
void initState() {
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) {
if (di<SettingsModel>().notifyDataSafeMode &&
di<ConnectivityModel>().isMaybeLowBandWidth &&
!di<PlayerModel>().dataSafeMode) {
showDialog(
context: context,
builder: (context) => const BandwidthDialog(),
);
}
});
}

@override
Widget build(BuildContext context) {
final fullWindowMode =
Expand Down Expand Up @@ -126,7 +104,7 @@ class _MobilePageState extends State<MobilePage> {
body: Stack(
fit: StackFit.expand,
children: [
widget.page,
page,
if (fullWindowMode)
Material(
color: context.theme.scaffoldBackgroundColor,
Expand Down
4 changes: 2 additions & 2 deletions lib/common/view/bandwidth_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class BandwidthDialog extends StatelessWidget {
? l10n.isBackInWifiDialogBody
: l10n.isMaybeLowBandwidthDialogBody,
),
onConfirm: () =>
onConfirm: () async =>
di<PlayerModel>().setDataSafeMode(!backOnBetterConnection),
cancelLabel: l10n.stopToNotifyAboutDataSafeMode,
onCancel: () => di<SettingsModel>().setNotifyDataSafeMode(false),
onCancel: () async => di<SettingsModel>().setNotifyDataSafeMode(false),
);
}
}
45 changes: 32 additions & 13 deletions lib/common/view/confirm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,44 @@ class ConfirmationDialog extends StatelessWidget {
if (showCancel)
OutlinedButton(
onPressed: enabled
? () {
onCancel?.call();
if (context.mounted &&
Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
? onCancel is Future
? () async {
await onCancel?.call();

if (context.mounted &&
Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
: () {
onCancel?.call();
if (context.mounted &&
Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
: null,
child: Text(cancelLabel ?? l10n.cancel),
),
ElevatedButton(
onPressed: enabled
? () {
onConfirm?.call();
? onConfirm is Future
? () async {
await onConfirm?.call();

if (context.mounted && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
if (context.mounted &&
Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
: () {
onConfirm?.call();

if (context.mounted &&
Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
: null,
child: Text(
confirmLabel ?? l10n.ok,
Expand Down
9 changes: 5 additions & 4 deletions lib/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,7 @@ class PlayerService {
),
);

if (!_dataSafeMode) {
await _processParsedIcyTitle(mpvMetaData!.icyTitle);
}
await _processParsedIcyTitle(mpvMetaData!.icyTitle);
}
_propertiesChangedController.add(true);
}
Expand Down Expand Up @@ -816,7 +814,10 @@ class PlayerService {

Future<void> _processParsedIcyTitle(String parsedIcyTitle) async {
final songInfo = parsedIcyTitle.splitByDash;
final albumArt = await _onlineArtService.fetchAlbumArt(parsedIcyTitle);
String? albumArt;
if (!_dataSafeMode) {
await _onlineArtService.fetchAlbumArt(parsedIcyTitle);
}

final mergedAudio =
(_audio ?? const Audio(audioType: AudioType.radio)).copyWith(
Expand Down

0 comments on commit b09a955

Please sign in to comment.