Skip to content

Commit

Permalink
[CastIt.Android] Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Aug 30, 2020
1 parent e37a03c commit 6816a90
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CastIt.Android/lib/bloc/play/play_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class PlayBloc extends Bloc<PlayEvent, PlayState> {
if (currentState.isDraggingSlider) {
return currentState.copyWith.call(isPaused: false);
}
//A live stream is being played
if (currentState.duration <= 0) {
return currentState.copyWith.call(currentSeconds: e.seconds, isPaused: false);
}
final s = e.seconds >= currentState.duration ? currentState.duration : e.seconds;
return currentState.copyWith.call(currentSeconds: s, isPaused: false);
},
Expand Down
3 changes: 3 additions & 0 deletions CastIt.Android/lib/common/extensions/duration_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extension DurationExtensions on Duration {
String formatDuration() {
if (isNegative) {
return '∞';
}
String twoDigits(num n) => n.toString().padLeft(2, '0');
final twoDigitHour = twoDigits(inHours);
final twoDigitMinutes = twoDigits(inMinutes.remainder(60));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:castit/bloc/server_ws/server_ws_bloc.dart';
import 'package:castit/models/dtos/responses/file_item_options_response_dto.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../bloc/played_file_options/played_file_options_bloc.dart';
import '../../../bloc/server_ws/server_ws_bloc.dart';
import '../../../common/styles.dart';
import '../../../generated/i18n.dart';
import '../../../models/dtos/responses/file_item_options_response_dto.dart';
import 'bottom_sheet_title.dart';
import 'modal_sheet_separator.dart';

Expand All @@ -20,7 +20,11 @@ class PlayedFileOptionsBottomSheetDialog extends StatelessWidget {
child: BlocConsumer<PlayedFileOptionsBloc, PlayedFileOptionsState>(
listener: (ctx, state) {
state.maybeWhen(
closed: () => Navigator.of(ctx).pop(),
closed: () {
if (ModalRoute.of(context).isCurrent) {
Navigator.of(ctx).pop();
}
},
orElse: () {},
);
},
Expand Down Expand Up @@ -107,9 +111,7 @@ class PlayedFileOptionsBottomSheetDialog extends StatelessWidget {
if (options.isEmpty) {
options.add(dummy);
}
final selected = options.firstWhere(
(element) => element.isSelected,
);
final selected = options.firstWhere((element) => element.isSelected);
final dropdown = DropdownButton<FileItemOptionsResponseDto>(
isExpanded: true,
hint: Text(selected.text),
Expand Down Expand Up @@ -196,8 +198,8 @@ class PlayedFileOptionsBottomSheetDialog extends StatelessWidget {
isSubtitle: option.isSubTitle,
isQuality: option.isQuality,
);
context.bloc<PlayedFileOptionsBloc>().add(event);
Navigator.of(context).pop();
context.bloc<PlayedFileOptionsBloc>().add(event);
}

void _setVolume(BuildContext context, double volumeLevel, bool isMuted) => context
Expand Down
39 changes: 26 additions & 13 deletions CastIt.Android/lib/ui/widgets/play/play_progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,36 @@ class PlayProgressBar extends StatelessWidget {
connected: (state) => dummySlider,
fileLoading: (state) => dummySlider,
fileLoadingFailed: (state) => dummySlider,
playing: (state) => Slider(
onChanged: (double value) =>
context.bloc<PlayBloc>().add(PlayEvent.sliderValueChanged(newValue: value, triggerGoToSeconds: false)),
value: state.currentSeconds,
max: state.duration,
activeColor: theme.accentColor,
label: _generateLabel(state.currentSeconds),
divisions: state.duration.round(),
onChangeStart: (startValue) => context.bloc<PlayBloc>().add(PlayEvent.sliderDragChanged(isSliding: true)),
onChangeEnd: (finalValue) => context
.bloc<PlayBloc>()
.add(PlayEvent.sliderValueChanged(newValue: finalValue.roundToDouble(), triggerGoToSeconds: true)),
),
playing: (state) => _buildPlayingSlider(state, context),
);
},
);
}

Slider _buildPlayingSlider(PlayingState state, BuildContext context) {
final theme = Theme.of(context);
if (state.duration <= 0) {
return Slider(
onChanged: null,
value: 100,
max: 100,
activeColor: theme.accentColor,
);
}
return Slider(
onChanged: (double value) =>
context.bloc<PlayBloc>().add(PlayEvent.sliderValueChanged(newValue: value, triggerGoToSeconds: false)),
value: state.currentSeconds,
max: state.duration,
activeColor: theme.accentColor,
label: _generateLabel(state.currentSeconds),
divisions: state.duration.round(),
onChangeStart: (startValue) => context.bloc<PlayBloc>().add(PlayEvent.sliderDragChanged(isSliding: true)),
onChangeEnd: (finalValue) => context
.bloc<PlayBloc>()
.add(PlayEvent.sliderValueChanged(newValue: finalValue.roundToDouble(), triggerGoToSeconds: true)),
);
}

String _generateLabel(double seconds) => Duration(seconds: seconds.round()).formatDuration();
}
8 changes: 2 additions & 6 deletions CastIt.Android/lib/ui/widgets/play/play_progress_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ class PlayProgressText extends StatelessWidget {
children: <Widget>[
Text(
current,
style: TextStyle(
color: isDarkTheme ? Colors.white : Colors.black,
),
style: TextStyle(color: isDarkTheme ? Colors.white : Colors.black),
),
Text(
total,
style: TextStyle(
color: isDarkTheme ? Colors.white : Colors.black,
),
style: TextStyle(color: isDarkTheme ? Colors.white : Colors.black),
)
],
),
Expand Down
36 changes: 25 additions & 11 deletions CastIt.Android/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ packages:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0+1"
version: "2.3.1"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -252,7 +252,7 @@ packages:
name: equatable
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
version: "1.2.4"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -292,7 +292,14 @@ packages:
name: flutter_bloc
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
version: "6.0.2"
flutter_blurhash:
dependency: transitive
description:
name: flutter_blurhash
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
flutter_cache_manager:
dependency: transitive
description:
Expand Down Expand Up @@ -342,7 +349,7 @@ packages:
name: freezed
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.5"
version: "0.11.6"
freezed_annotation:
dependency: "direct main"
description:
Expand Down Expand Up @@ -440,7 +447,7 @@ packages:
name: json_serializable
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.0"
version: "3.4.1"
lint:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -518,6 +525,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
octo_image:
dependency: transitive
description:
name: octo_image
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -746,7 +760,7 @@ packages:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.3.1+1"
sqflite_common:
dependency: transitive
description:
Expand Down Expand Up @@ -823,7 +837,7 @@ packages:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.5.0"
version: "5.5.1"
url_launcher_linux:
dependency: transitive
description:
Expand All @@ -844,21 +858,21 @@ packages:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
version: "1.0.8"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2+1"
version: "0.1.3"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.2.2"
vector_math:
dependency: transitive
description:
Expand Down Expand Up @@ -903,4 +917,4 @@ packages:
version: "2.2.1"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.16.0 <2.0.0"
flutter: ">=1.20.0 <2.0.0"

0 comments on commit 6816a90

Please sign in to comment.