Skip to content

Commit

Permalink
[CastIt.Android] Added a common_bottom_sheet.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jun 28, 2021
1 parent 4be80f0 commit 35fc0aa
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ part 'playlist_rename_bloc.freezed.dart';
part 'playlist_rename_event.dart';
part 'playlist_rename_state.dart';

final _initialState = PlayListRenameState.loaded(currentName: '', isNameValid: false);

class PlayListRenameBloc extends Bloc<PlayListRenameEvent, PlayListRenameState> {
PlayListRenameBloc() : super(PlayListRenameState.initial());
PlayListRenameBloc() : super(_initialState);

_LoadedState get currentState => state as _LoadedState;

@override
Stream<PlayListRenameState> mapEventToState(
PlayListRenameEvent event,
) async* {
if (event is! _LoadedState) {
yield PlayListRenameState.initial();
}

Stream<PlayListRenameState> mapEventToState(PlayListRenameEvent event) async* {
final s = event.map(
load: (e) => PlayListRenameState.loaded(currentName: e.name, isNameValid: _isNameValid(e.name)),
nameChanged: (e) => currentState.copyWith(isNameValid: _isNameValid(e.name)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ part of 'playlist_rename_bloc.dart';

@freezed
class PlayListRenameState with _$PlayListRenameState {
factory PlayListRenameState.initial() = _InitialState;

factory PlayListRenameState.loaded({
required String currentName,
required bool isNameValid,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,52 @@
import 'package:castit/application/bloc.dart';
import 'package:castit/domain/models/models.dart';
import 'package:castit/generated/l10n.dart';
import 'package:castit/presentation/shared/bottom_sheet_title.dart';
import 'package:castit/presentation/shared/extensions/styles.dart';
import 'package:castit/presentation/shared/modal_sheet_separator.dart';
import 'package:castit/presentation/shared/common_bottom_sheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class PlayedFileOptionsBottomSheetDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
margin: Styles.modalBottomSheetContainerMargin,
padding: Styles.modalBottomSheetContainerPadding,
child: BlocConsumer<PlayedFileOptionsBloc, PlayedFileOptionsState>(
listener: (ctx, state) {
state.maybeWhen(
closed: () {
if (ModalRoute.of(context)!.isCurrent) {
Navigator.of(ctx).pop();
}
},
orElse: () {},
);
final s = S.of(context);
return BlocConsumer<PlayedFileOptionsBloc, PlayedFileOptionsState>(
listener: (ctx, state) {
state.maybeWhen(
closed: () {
if (ModalRoute.of(context)!.isCurrent) {
Navigator.of(ctx).pop();
}
},
builder: (ctx, state) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
..._buildPage(ctx, state),
orElse: () {},
);
},
builder: (ctx, state) => CommonBottomSheet(
title: s.fileOptions,
titleIcon: Icons.play_circle_filled,
showOkButton: false,
showCancelButton: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: state.map(
loaded: (state) => <Widget>[
_buildAudioOptions(context, s, state.options),
_buildSubtitleOptions(context, s, state.options),
_buildQualitiesOptions(context, s, state.options),
_buildVolumeOptions(context, s, state.volumeLvl, state.isMuted),
OutlinedButton.icon(
onPressed: () => _stopPlayback(context),
icon: const Icon(Icons.stop),
label: Text(s.stopPlayback),
),
],
closed: (_) => [],
),
),
),
);
}

List<Widget> _buildPage(BuildContext context, PlayedFileOptionsState state) {
final i18n = S.of(context);
final separator = ModalSheetSeparator();
final title = BottomSheetTitle(icon: Icons.play_circle_filled, title: i18n.fileOptions);
return state.map(
loaded: (s) {
return [
separator,
title,
_buildAudioOptions(context, i18n, s.options),
_buildSubtitleOptions(context, i18n, s.options),
_buildQualitiesOptions(context, i18n, s.options),
_buildVolumeOptions(context, i18n, s.volumeLvl, s.isMuted),
OutlinedButton.icon(
onPressed: () => _stopPlayback(context),
icon: const Icon(Icons.stop),
label: Text(i18n.stopPlayback),
),
];
},
closed: (s) {
return [
separator,
title,
];
},
);
}

Widget _buildAudioOptions(BuildContext context, S i18n, List<FileItemOptionsResponseDto> options) {
final audioOptions = options.where((element) => element.isAudio).toList();
return _buildDropDown(context, i18n, i18n.audio, i18n.audio, Icons.audiotrack, audioOptions);
Expand All @@ -81,14 +62,7 @@ class PlayedFileOptionsBottomSheetDialog extends StatelessWidget {
return _buildDropDown(context, i18n, i18n.quality, i18n.quality, Icons.high_quality, qualitiesOptions);
}

Widget _buildDropDown(
BuildContext context,
S i18n,
String title,
String hint,
IconData icon,
List<FileItemOptionsResponseDto> options,
) {
Widget _buildDropDown(BuildContext context, S i18n, String title, String hint, IconData icon, List<FileItemOptionsResponseDto> options) {
final theme = Theme.of(context);
final dummy = FileItemOptionsResponseDto(
id: -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeleteFileBottomSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final i18n = S.of(context)!;
final i18n = S.of(context);
return ConfirmBottomSheet(
title: i18n.delete,
icon: Icons.delete,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:castit/application/bloc.dart';
import 'package:castit/generated/l10n.dart';
import 'package:castit/presentation/shared/bottom_sheet_title.dart';
import 'package:castit/presentation/shared/common_bottom_sheet.dart';
import 'package:castit/presentation/shared/extensions/styles.dart';
import 'package:castit/presentation/shared/modal_sheet_separator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand All @@ -21,54 +20,52 @@ class FileOptionsBottomSheetDialog extends StatelessWidget {

@override
Widget build(BuildContext context) {
final i18n = S.of(context)!;
final i18n = S.of(context);
final theme = Theme.of(context);
final textColor = theme.brightness == Brightness.dark ? Colors.white : Colors.black;
return SingleChildScrollView(
child: Container(
margin: Styles.modalBottomSheetContainerMargin,
padding: Styles.modalBottomSheetContainerPadding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ModalSheetSeparator(),
BottomSheetTitle(icon: Icons.insert_drive_file, title: i18n.fileOptions),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _playFile(context, false),
child: Row(
children: <Widget>[
const Icon(Icons.play_arrow),
const SizedBox(width: 10),
Text(i18n.playFile),
],
),
return CommonBottomSheet(
title: i18n.fileOptions,
titleIcon: Icons.insert_drive_file,
showOkButton: false,
showCancelButton: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _playFile(context, false),
child: Row(
children: <Widget>[
const Icon(Icons.play_arrow),
const SizedBox(width: 10),
Text(i18n.playFile),
],
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _playFile(context, true),
child: Row(
children: <Widget>[
const Icon(Icons.play_circle_filled),
const SizedBox(width: 10),
Text(i18n.playFileFromTheBeginning),
],
),
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _playFile(context, true),
child: Row(
children: <Widget>[
const Icon(Icons.play_circle_filled),
const SizedBox(width: 10),
Text(i18n.playFileFromTheBeginning),
],
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showDeleteModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.delete),
const SizedBox(width: 10),
Text(i18n.deleteFile),
],
),
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showDeleteModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.delete),
const SizedBox(width: 10),
Text(i18n.deleteFile),
],
),
],
),
),
],
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeletePlayListBottomSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final i18n = S.of(context)!;
final i18n = S.of(context);
return ConfirmBottomSheet(
title: i18n.delete,
icon: Icons.delete,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:castit/generated/l10n.dart';
import 'package:castit/presentation/shared/bottom_sheet_title.dart';
import 'package:castit/presentation/shared/common_bottom_sheet.dart';
import 'package:castit/presentation/shared/extensions/styles.dart';
import 'package:castit/presentation/shared/modal_sheet_separator.dart';
import 'package:flutter/material.dart';

import 'delete_playlist_bottom_sheet.dart';
Expand All @@ -21,40 +20,38 @@ class PlayListOptionsBottomSheetDialog extends StatelessWidget {
final i18n = S.of(context);
final theme = Theme.of(context);
final textColor = theme.brightness == Brightness.dark ? Colors.white : Colors.black;
return SingleChildScrollView(
child: Container(
margin: Styles.modalBottomSheetContainerMargin,
padding: Styles.modalBottomSheetContainerPadding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ModalSheetSeparator(),
BottomSheetTitle(icon: Icons.playlist_play, title: i18n.playlistOptions),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showRenameModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.edit),
const SizedBox(width: 10),
Text(i18n.rename),
],
),
return CommonBottomSheet(
title: i18n.playlistOptions,
titleIcon: Icons.playlist_play,
showOkButton: false,
showCancelButton: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showRenameModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.edit),
const SizedBox(width: 10),
Text(i18n.rename),
],
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showDeleteModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.delete),
const SizedBox(width: 10),
Text(i18n.delete),
],
),
),
TextButton(
style: TextButton.styleFrom(primary: textColor),
onPressed: () => _showDeleteModal(context),
child: Row(
children: <Widget>[
const Icon(Icons.delete),
const SizedBox(width: 10),
Text(i18n.delete),
],
),
],
),
),
],
),
);
}
Expand Down
Loading

0 comments on commit 35fc0aa

Please sign in to comment.