Skip to content

Commit

Permalink
Added casting videos to smart tv
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Dec 16, 2023
1 parent 74adc42 commit 0b968ca
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 95 deletions.
4 changes: 2 additions & 2 deletions lib/infrastructure/mqtt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class MqttServerRepository extends IMqttServerRepository {
final DeviceEntityAbstract deviceEntityAbstract =
entityFromTheApp.toDomain();
deviceEntityAbstract.entityStateGRPC =
EntityState(EntityStateGRPC.waitingInComp.toString());
EntityState.state(EntityStateGRPC.waitingInComp);

/// Sends directly to device connector conjecture
ISavedDevicesRepo.instance.addOrUpdateFromMqtt(deviceEntityAbstract);

return;
} else if (entityFromTheApp is DeviceEntityAbstract) {
entityFromTheApp.entityStateGRPC =
EntityState(EntityStateGRPC.waitingInComp.toString());
EntityState.state(EntityStateGRPC.waitingInComp);

/// Sends directly to device connector conjecture
// ConnectorDevicesStreamFromMqtt.fromMqttStream.add(entityFromTheApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LightCardMolecule extends StatelessWidget {

Future<void> _onChange(bool value) async {
final GenericLightDE tempDeviceEntity = entity!
..entityStateGRPC = EntityState(EntityStateGRPC.waitingInCloud.toString())
..entityStateGRPC = EntityState.state(EntityStateGRPC.waitingInCloud)
..lightSwitchState = GenericLightSwitchState(value.toString());

if (value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LightMolecule extends StatelessWidget {

final GenericLightDE entity;

Future<void> _onChange(bool value) async {
void _onChange(bool value) {
setEntityState(value ? EntityActions.on : EntityActions.off);
}

Expand Down
116 changes: 55 additions & 61 deletions lib/presentation/molecules/devices/smart_tv_molecule.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:collection';

import 'package:another_flushbar/flushbar_helper.dart';
import 'package:auto_route/auto_route.dart';
import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/entity_type_utils.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_smart_tv_entity/generic_smart_tv_entity.dart';
import 'package:cybear_jinni/domain/device/i_device_repository.dart';
import 'package:cybear_jinni/domain/i_phone_as_hub.dart';
import 'package:cybear_jinni/presentation/atoms/atoms.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Expand All @@ -18,63 +21,69 @@ class SmartTvMolecule extends StatefulWidget {
}

class _SmartTvMoleculeState extends State<SmartTvMolecule> {
Future _stopState() async {
Future onStop() async {
FlushbarHelper.createLoading(
message: 'Stop smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

IDeviceRepository.instance
.stopStateDevices(devicesId: [widget.entity.getDeviceId()]);
setEntityState(EntityProperties.smartTvSwitchState, EntityActions.close);
}

Future _playState() async {
Future onPlay() async {
FlushbarHelper.createLoading(
message: 'Play smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

IDeviceRepository.instance
.playStateDevices(devicesId: [widget.entity.getDeviceId()]);
}

Future _queuePrevEvent(List<String> smartTvId) async {
FlushbarHelper.createLoading(
message: 'Change volume smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

IDeviceRepository.instance.queuePrevStateDevices(devicesId: smartTvId);
setEntityState(EntityProperties.smartTvSwitchState, EntityActions.play);
}

Future _queueNextEvent(List<String> smartTvId) async {
void onPause() {
FlushbarHelper.createLoading(
message: 'Change volume smart tv',
message: 'Close current app on smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

IDeviceRepository.instance.queueNextStateDevices(devicesId: smartTvId);
setEntityState(EntityProperties.smartTvSwitchState, EntityActions.pause);
}

void closeEvent(BuildContext context) {
final String deviceId = widget.entity.getDeviceId();

void playVideo(String url) {
FlushbarHelper.createLoading(
message: 'Close current app on smart tv',
message: 'Open url on smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

IDeviceRepository.instance.closeStateDevices(devicesId: [deviceId]);
}

void queueNextEvent(BuildContext context) {
final String deviceId = widget.entity.getDeviceId();
_queueNextEvent([deviceId]);
setEntityState(EntityProperties.openUrl, EntityActions.open, value: url);
}

void queuePrevEvent(BuildContext context) {
final String deviceId = widget.entity.getDeviceId();
_queuePrevEvent([deviceId]);
void setEntityState(
EntityProperties property,
EntityActions action, {
String? value,
}) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
IPhoneAsHub.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
);
}

@override
Expand Down Expand Up @@ -105,10 +114,7 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
// hintText: 'Enter a search term',
// ),
// );
OpenUrlPopUp(
context,
widget.entity,
);
OpenUrlPopUp(context, playVideo);
},
child: Tab(
icon: FaIcon(
Expand Down Expand Up @@ -140,7 +146,7 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
),
),
),
onPressed: _stopState,
onPressed: onStop,
child: Tab(
icon: FaIcon(
FontAwesomeIcons.xmark,
Expand Down Expand Up @@ -171,9 +177,7 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
),
),
),
onPressed: () {
closeEvent(context);
},
onPressed: onPause,
child: Tab(
icon: FaIcon(
FontAwesomeIcons.pause,
Expand Down Expand Up @@ -204,7 +208,7 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
),
),
),
onPressed: _playState,
onPressed: onPlay,
child: Tab(
icon: FaIcon(
FontAwesomeIcons.play,
Expand Down Expand Up @@ -302,15 +306,16 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
}

class OpenUrlPopUp {
OpenUrlPopUp(this.contextFromParent, this._deviceEntity) {
OpenUrlPopUp(this.contextFromParent, this.onOpenUrl) {
openUrlPopUp();
}

BuildContext contextFromParent;
final GenericSmartTvDE _deviceEntity;
final Function(String) onOpenUrl;

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

showDialog(
context: contextFromParent,
Expand All @@ -327,7 +332,7 @@ class OpenUrlPopUp {
top: 10.0,
),
title: const TextAtom(
"Open URL",
'Open URL',
style: TextStyle(fontSize: 24.0),
),
content: SizedBox(
Expand All @@ -340,7 +345,8 @@ class OpenUrlPopUp {
children: <Widget>[
Container(
padding: const EdgeInsets.all(8.0),
child: TextField(
child: TextFormField(
initialValue: url,
onChanged: (textInUrl) {
url = textInUrl;
},
Expand All @@ -357,8 +363,8 @@ class OpenUrlPopUp {
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
playVideo(contextFromParent, url);
context.router.pop();
Navigator.pop(context);
onOpenUrl(url);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
Expand All @@ -377,16 +383,4 @@ class OpenUrlPopUp {
},
);
}

void playVideo(BuildContext context, String url) {
final String deviceId = _deviceEntity.getDeviceId();
FlushbarHelper.createLoading(
message: 'Open url on smart tv',
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);
IDeviceRepository.instance.openUrlOnDevices(
devicesId: [deviceId],
url: url,
);
}
}
34 changes: 22 additions & 12 deletions lib/presentation/organisms/open_room_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,29 @@ class _OpenRoomOrganismState extends State<OpenRoomOrganism> {
return EmptyOpenRoomOrganism();
}

return Expanded(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15),
child: ListView.builder(
reverse: true,
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
final DeviceEntityAbstract device = devices![index];
final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;

return DeviceByTypeMolecule(device);
},
itemCount: devices!.length,
),
return Container(
margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15),
child: ListView.builder(
reverse: true,
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
final DeviceEntityAbstract device = devices![index];

return Column(
children: [
TextAtom(
device.cbjEntityName.getOrCrash() ?? '',
style: textTheme.titleMedium,
),
const SeparatorAtom(),
DeviceByTypeMolecule(device),
],
);
},
itemCount: devices!.length,
),
);
}
Expand Down
30 changes: 13 additions & 17 deletions lib/presentation/organisms/page_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ class PageOrganism extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
final ColorScheme colorScheme = themeData.colorScheme;

return Scaffold(
body: Material(
color: colorScheme.background,
child: Expanded(
child: Column(
children: [
TopBarMolecule(
pageName: pageName,
backgroundColor: topBarColor,
leftIcon: FontAwesomeIcons.arrowLeft,
leftIconFunction: (_) => context.router.pop(),
),
child,
],
body: Column(
children: [
SafeArea(
child: TopBarMolecule(
pageName: pageName,
backgroundColor: topBarColor,
leftIcon: FontAwesomeIcons.arrowLeft,
leftIconFunction: (_) => context.router.pop(),
),
),
Expanded(
child: child,
),
),
],
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/pages/devices_in_network_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _DevicesInNetworkPageState extends State<DevicesInNetworkPage> {
device.entityOriginalName.getOrCrash();
final String? deviceHostName = device.deviceHostName.getOrCrash();
final String? deviceMdns = device.deviceMdns.getOrCrash();
final String devicePort = device.devicePort.getOrCrash();
final String? devicePort = device.devicePort.getOrCrash();
final String cbjDeviceVendor = device.cbjDeviceVendor.getOrCrash();
final String? devicesMacAddress =
device.devicesMacAddress.getOrCrash();
Expand Down

0 comments on commit 0b968ca

Please sign in to comment.