Skip to content

Commit

Permalink
Added TTS and open URL support
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 6, 2024
1 parent ae80a13 commit 8871fd8
Show file tree
Hide file tree
Showing 13 changed files with 806 additions and 883 deletions.
19 changes: 0 additions & 19 deletions lib/domain/device/i_device_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ abstract interface class IDeviceRepository {
DeviceEntityBase deviceEntity,
);

/// Update document in the database in the following fields
Future<Either<DevicesFailure, Unit>> updateDatabase({
required Map<String, dynamic> documentPath,
required Map<String, dynamic> fieldsToUpdate,
});

Future<Either<DevicesFailure, Unit>> updateWithDeviceEntity({
required DeviceEntityBase deviceEntity,
});
Expand Down Expand Up @@ -115,11 +109,6 @@ abstract interface class IDeviceRepository {
required List<String>? devicesId,
});

Future<Either<DevicesFailure, Unit>> openUrlOnDevices({
required List<String>? devicesId,
required String url,
});

Future<Either<DevicesFailure, Unit>> closeStateDevices({
required List<String>? devicesId,
});
Expand All @@ -132,10 +121,6 @@ abstract interface class IDeviceRepository {
required List<String>? devicesId,
});

Future<Either<DevicesFailure, Unit>> skipVideoDevices({
required List<String>? devicesId,
});

Future<Either<DevicesFailure, Unit>> changeVolumeDevices({
required List<String>? devicesId,
});
Expand All @@ -148,10 +133,6 @@ abstract interface class IDeviceRepository {
required List<String>? devicesId,
});

Future<Either<DevicesFailure, Unit>> delete(
DeviceEntityBase deviceEntity,
);

BehaviorSubject<KtList<dynamic>> allResponseFromTheHubStreamController =
BehaviorSubject<KtList<dynamic>>();

Expand Down
94 changes: 1 addition & 93 deletions lib/infrastructure/device_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,44 +251,11 @@ class _DeviceRepository implements IDeviceRepository {
}
}

@override
Future<Either<DevicesFailure, Unit>> updateDatabase({
required Map<String, dynamic> documentPath,
required Map<String, dynamic> fieldsToUpdate,
String? forceUpdateLocation,
}) async {
try {
// await documentPath.update(fieldsToUpdate);
return right(unit);
} on PlatformException catch (e) {
if (e.message!.contains('NOT_FOUND')) {
return left(const DevicesFailure.unableToUpdate());
} else {
// log.error(e.toString());
return left(const DevicesFailure.unexpected());
}
}
}

@override
Future<Either<DevicesFailure, Unit>> updateWithDeviceEntity({
required DeviceEntityBase deviceEntity,
}) async {
const String updateLocation = 'L';

try {
if (updateLocation == 'L') {
return updateComputer(deviceEntity);
}
return updateRemoteDB(deviceEntity);
} on PlatformException catch (e) {
if (e.message!.contains('NOT_FOUND')) {
return left(const DevicesFailure.unableToUpdate());
} else {
// log.error(e.toString());
return left(const DevicesFailure.unexpected());
}
}
return left(const DevicesFailure.unexpected());
}

@override
Expand Down Expand Up @@ -852,44 +819,6 @@ class _DeviceRepository implements IDeviceRepository {
throw UnimplementedError();
}

@override
Future<Either<DevicesFailure, Unit>> openUrlOnDevices({
required List<String>? devicesId,
required String url,
}) async {
final List<DeviceEntityBase?> deviceEntityListToUpdate =
await getDeviceEntityListFromId(devicesId!);

try {
for (final DeviceEntityBase? deviceEntity in deviceEntityListToUpdate) {
if (deviceEntity == null) {
continue;
}
if (deviceEntity is GenericSmartTvDE) {
deviceEntity.openUrl = GenericSmartTvOpenUrl(url);
} else {
logger.w(
'Open url action not supported for'
' ${deviceEntity.entityTypes.getOrCrash()} type',
);
continue;
}

updateWithDeviceEntity(deviceEntity: deviceEntity);
}
} on PlatformException catch (e) {
if (e.message!.contains('PERMISSION_DENIED')) {
return left(const DevicesFailure.insufficientPermission());
} else if (e.message!.contains('NOT_FOUND')) {
return left(const DevicesFailure.unableToUpdate());
} else {
// log.error(e.toString());
return left(const DevicesFailure.unexpected());
}
}
return right(unit);
}

@override
Future<Either<DevicesFailure, Unit>> closeStateDevices({
List<String>? devicesId,
Expand Down Expand Up @@ -1085,27 +1014,6 @@ class _DeviceRepository implements IDeviceRepository {
return right(unit);
}

@override
Future<Either<DevicesFailure, Unit>> skipVideoDevices({
required List<String>? devicesId,
}) async {
// TODO: implement skipVideoDevices
throw UnimplementedError();
}

@override
Future<Either<DevicesFailure, Unit>> delete(
DeviceEntityBase deviceEntity,
) async {
return left(const DevicesFailure.unexpected());
}

Future<Either<DevicesFailure, Unit>> updateRemoteDB(
DeviceEntityBase deviceEntity,
) async {
return left(const DevicesFailure.unexpected());
}

Future<Either<DevicesFailure, Unit>> updateComputer(
DeviceEntityBase deviceEntity,
) async {
Expand Down
134 changes: 126 additions & 8 deletions lib/presentation/molecules/devices/smart_tv_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,42 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
);
}

void playVideo(String url) {
void openUrl(String? url) {
if (url == null) {
return;
}

FlushbarHelper.createLoading(
message: 'Open the url',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

setEntityState(
EntityProperties.openUrl,
EntityActions.open,
EntityActions.openUrl,
value: HashMap.from({ActionValues.url: url}),
);
}

void sendTtl(String? text) {
if (text == null) {
return;
}

FlushbarHelper.createLoading(
message: 'Send tts text',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

setEntityState(
EntityProperties.speekers,
EntityActions.speek,
value: HashMap.from({ActionValues.text: text}),
);
}

void openUrlPopUp() {
String url =
'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';
String? url;

showDialog(
context: context,
Expand Down Expand Up @@ -149,7 +169,6 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
Container(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
initialValue: url,
onChanged: (textInUrl) {
url = textInUrl;
},
Expand All @@ -167,7 +186,77 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
playVideo(url);
openUrl(url);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
// fixedSize: Size(250, 50),
),
child: const TextAtom(
"Submit",
),
),
),
],
),
),
),
);
},
);
}

void ttsPopUp() {
String? text = 'Welcome Home';

showDialog(
context: context,
builder: (context) {
return AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(
20.0,
),
),
),
contentPadding: const EdgeInsets.only(
top: 10.0,
),
title: const TextAtom(
'Text To Speech',
style: TextStyle(fontSize: 24.0),
),
content: SizedBox(
height: 400,
child: SingleChildScrollView(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
initialValue: 'Welcome Home',
onChanged: (textInUrl) {
text = textInUrl;
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter TTS here',
labelText: 'Text',
),
),
),
Container(
width: double.infinity,
height: 60,
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
sendTtl(text);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
Expand Down Expand Up @@ -308,11 +397,40 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
onPressed: openUrlPopUp,
child: Tab(
icon: FaIcon(
FontAwesomeIcons.video,
FontAwesomeIcons.globe,
color: Theme.of(context).textTheme.bodyLarge!.color,
),
child: TextAtom(
'Open URL',
style: TextStyle(
color: Theme.of(context).textTheme.bodyLarge!.color,
fontSize: 16,
),
),
),
),
const SeparatorAtom(),
TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Colors.grey,
),
side: MaterialStateProperty.all(
BorderSide.lerp(
const BorderSide(color: Colors.white60),
const BorderSide(color: Colors.white60),
22,
),
),
),
onPressed: ttsPopUp,
child: Tab(
icon: FaIcon(
FontAwesomeIcons.globe,
color: Theme.of(context).textTheme.bodyLarge!.color,
),
child: TextAtom(
'Video',
'TTS',
style: TextStyle(
color: Theme.of(context).textTheme.bodyLarge!.color,
fontSize: 16,
Expand Down
10 changes: 5 additions & 5 deletions lib/presentation/molecules/scenes_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ class _ScenesGridState extends State<ScenesGrid> {
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;

final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;

int gridCrossAxisCount = 2;
if (screenSize.width > 700) {
gridCrossAxisCount = 4;
}

if (widget.scenes.isEmpty) {
return const Center(
return Center(
child: TextAtom(
'You can add automations in the plus button',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
style: textTheme.bodyLarge,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/organisms/devices_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DevicesListView extends StatelessWidget {
geEntitiesByType();

return ListViewMolecule(
ListViewVeriant.builder,
ListViewVeriant.separated,
shrinkWrap: true,
itemBuilder: (context, index) {
final EntityTypes type = entitiesByType.keys.elementAt(index);
Expand Down
Loading

0 comments on commit 8871fd8

Please sign in to comment.