Skip to content

Commit

Permalink
feature(filters): toggle filters now possible and some minor layout u…
Browse files Browse the repository at this point in the history
…pdates
  • Loading branch information
Kounex committed Nov 29, 2023
1 parent 882a788 commit aa3a619
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 40 deletions.
28 changes: 28 additions & 0 deletions lib/stores/views/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import '../../types/classes/stream/events/input_volume_changed.dart';
import '../../types/classes/stream/events/input_volume_meters.dart';
import '../../types/classes/stream/events/scene_collection_list_changed.dart';
import '../../types/classes/stream/events/scene_item_enable_state_changed.dart';
import '../../types/classes/stream/events/source_filter_enable_state_changed.dart';
import '../../types/classes/stream/events/studio_mode_switched.dart';
import '../../types/classes/stream/events/virtual_cam_state_changed.dart';
import '../../types/classes/stream/responses/base.dart';
Expand Down Expand Up @@ -881,6 +882,33 @@ abstract class _DashboardStore with Store {
}));

break;

case EventType.SourceFilterEnableStateChanged:
SourceFilterEnableStateChangedEvent
sourceFilterEnableStateChangedEvent =
SourceFilterEnableStateChangedEvent(event.jsonRAW);

this.currentSceneItems = ObservableList.of(
this.currentSceneItems.map((sceneItem) {
if ((sceneItem.filters?.isNotEmpty ?? false) &&
sceneItem.sourceName ==
sourceFilterEnableStateChangedEvent.sourceName) {
return sceneItem.copyWith(
filters: sceneItem.filters?.map((filter) {
if (filter.filterName ==
sourceFilterEnableStateChangedEvent.filterName) {
return filter.copyWith(
filterEnabled:
sourceFilterEnableStateChangedEvent.filterEnabled,
);
}
return filter;
}).toList());
}
return sceneItem;
}),
);
break;
case EventType.ExitStarted:
await _finishPastStreamData();
await _finishPastRecordData();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'base.dart';

/// A source filter's enable state has changed.
class SourceFilterEnableStateChangedEvent extends BaseEvent {
SourceFilterEnableStateChangedEvent(super.json);

/// Name of the source the filter is on
String get sourceName => this.json['sourceName'];

/// Name of the filter
String get filterName => this.json['filterName'];

/// Whether the filter is enabled
bool get filterEnabled => this.json['filterEnabled'];
}
3 changes: 3 additions & 0 deletions lib/types/enums/event_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ enum EventType {

/// The sync offset of an input has changed.
InputAudioSyncOffsetChanged,

/// A source filter's enable state has changed.
SourceFilterEnableStateChanged,
}
3 changes: 0 additions & 3 deletions lib/views/dashboard/widgets/obs_widgets/stats/stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class _StatsState extends State<Stats> {
SizedBox(
width: MediaQuery.sizeOf(context).width,
child: StatsContainer(
elevation: 0.0,
title: 'OBS Stats',
trailing: const QuestionMarkTooltip(
message:
Expand Down Expand Up @@ -123,7 +122,6 @@ class _StatsState extends State<Stats> {
SizedBox(
width: MediaQuery.sizeOf(context).width,
child: StatsContainer(
elevation: 0.0,
title: 'Stream',
children: [
FormattedText(
Expand Down Expand Up @@ -172,7 +170,6 @@ class _StatsState extends State<Stats> {
SizedBox(
width: MediaQuery.sizeOf(context).width,
child: StatsContainer(
elevation: 0.0,
title: 'Recording',
children: [
FormattedText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class StatsContainer extends StatelessWidget {
final List<FormattedText>? children;
final Widget? child;

final double? elevation;

final bool wrapWithDescribedBox;

const StatsContainer({
Expand All @@ -20,7 +18,6 @@ class StatsContainer extends StatelessWidget {
this.children,
this.child,
this.trailing,
this.elevation,
this.wrapWithDescribedBox = false,
}) : assert(child != null || children != null),
super(key: key);
Expand All @@ -30,7 +27,6 @@ class StatsContainer extends StatelessWidget {
return BaseCard(
topPadding: 0.0,
bottomPadding: 0.0,
elevation: this.elevation,
titlePadding: const EdgeInsets.symmetric(
horizontal: 18.0,
vertical: 12.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class HotkeyEntry extends StatelessWidget {
icon: this.hotkey.isInBox
? CupertinoIcons.star_fill
: CupertinoIcons.star,
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
foregroundColor: this.hotkey.isInBox
? Colors.amber
: Theme.of(context).colorScheme.onBackground,
iconSize: 20.0,
: Theme.of(context).colorScheme.onSurface,
iconSize: 18.0,
buttonSize: 32.0,
),
const SizedBox(width: 18.0),
Expand All @@ -60,9 +60,9 @@ class HotkeyEntry extends StatelessWidget {
);
},
icon: CupertinoIcons.play_arrow_solid,
backgroundColor: Theme.of(context).colorScheme.background,
foregroundColor: Theme.of(context).colorScheme.onBackground,
iconSize: 20.0,
backgroundColor: Theme.of(context).colorScheme.surface,
foregroundColor: Theme.of(context).colorScheme.onSurface,
iconSize: 18.0,
buttonSize: 32.0,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _HotkeyListState extends State<HotkeyList> {
placeholder: 'Filter...',
clearButtonMode: OverlayVisibilityMode.editing,
),
const SizedBox(height: 24.0),
const SizedBox(height: 12.0),
],
),
),
Expand Down Expand Up @@ -108,8 +108,9 @@ class _HotkeyListState extends State<HotkeyList> {
controller: this.widget.controller,
padding: const EdgeInsets.symmetric(horizontal: 24.0) +
EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom +
12.0),
bottom:
MediaQuery.paddingOf(context).bottom + 12.0,
),
children: [
if (hotkeyBox.values.isNotEmpty) ...[
const SectionHeader(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:get_it/get_it.dart';
import 'package:obs_blade/stores/views/dashboard.dart';

import '../../../../../../shared/general/nested_list_manager.dart';

Expand All @@ -21,24 +18,20 @@ class _MediaInputsState extends State<MediaInputs>

@override
Widget build(BuildContext context) {
DashboardStore dashboardStore = GetIt.instance<DashboardStore>();

super.build(context);
return Observer(builder: (_) {
return NestedScrollManager(
parentScrollController:
ModalRoute.of(context)!.settings.arguments as ScrollController,
child: Scrollbar(
return NestedScrollManager(
parentScrollController:
ModalRoute.of(context)!.settings.arguments as ScrollController,
child: Scrollbar(
controller: _controller,
thumbVisibility: true,
child: ListView(
controller: _controller,
thumbVisibility: true,
child: ListView(
controller: _controller,
physics: const ClampingScrollPhysics(),
padding: const EdgeInsets.all(0.0),
children: const [],
),
physics: const ClampingScrollPhysics(),
padding: const EdgeInsets.all(0.0),
children: const [],
),
);
});
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:get_it/get_it.dart';
import 'package:obs_blade/shared/general/base/divider.dart';
import 'package:obs_blade/stores/shared/network.dart';
import 'package:obs_blade/stores/views/dashboard.dart';
import 'package:obs_blade/types/classes/api/scene_item.dart';
import 'package:obs_blade/types/enums/request_type.dart';
import 'package:obs_blade/utils/network_helper.dart';

class FilterList extends StatelessWidget {
final SceneItem sceneItem;

const FilterList({
super.key,
required this.sceneItem,
});

@override
Widget build(BuildContext context) {
DashboardStore dashboardStore = GetIt.instance<DashboardStore>();

return Observer(builder: (context) {
/// Hacky approach... this widget will be displayed in a
/// CupertinoModalBottomSheet which will be provided the [SceneItem]
/// which filters we are editing. When we update the filters, the
/// underlying [SceneItem] is updated but not a new one is provided
/// here in the widget since it's being called imperatively...
late SceneItem sceneItem;
try {
sceneItem = dashboardStore.currentSceneItems.firstWhere(
(sceneItem) => sceneItem.sceneItemId == sceneItem.sceneItemId,
);
} catch (_) {
Navigator.of(context).pop();
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Filters',
style: Theme.of(context).textTheme.headlineSmall,
),
Text(
sceneItem.sourceName!,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 12.0),
const Text(
'List of filters which are attached to the selected scene item.'),
const SizedBox(height: 24.0),
const BaseDivider(),
Expanded(
child: Scrollbar(
child: ListView.builder(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 12.0,
),
itemCount: sceneItem.filters?.length ?? 0,
itemBuilder: (context, index) => ListTile(
contentPadding: const EdgeInsets.all(0),
title: Text(sceneItem.filters![index].filterName),
trailing: IconButton(
onPressed: () => NetworkHelper.makeRequest(
GetIt.instance<NetworkStore>().activeSession!.socket,
RequestType.SetSourceFilterEnabled,
{
'sourceName': sceneItem.sourceName,
'filterName': sceneItem.filters![index].filterName,
'filterEnabled':
!sceneItem.filters![index].filterEnabled,
},
),
icon: Icon(
sceneItem.filters![index].filterEnabled
? Icons.visibility
: Icons.visibility_off,
color: sceneItem.filters![index].filterEnabled
? Theme.of(context).buttonTheme.colorScheme!.primary
: CupertinoColors.destructiveRed,
),
),
),
),
),
),
],
),
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:obs_blade/utils/modal_handler.dart';
import 'package:obs_blade/views/dashboard/widgets/scenes/scene_content/scene_items/filter_list.dart';

import '../../../../../../shared/general/hive_builder.dart';
import '../../../../../../stores/shared/network.dart';
Expand Down Expand Up @@ -98,9 +99,8 @@ class SceneItemTile extends StatelessWidget {
this.sceneItem.filters!.isNotEmpty
? () => ModalHandler.showBaseCupertinoBottomSheet(
context: context,
modalWidgetBuilder: (context, controller) => const Column(
children: [Text('Test')],
),
modalWidgetBuilder: (context, controller) =>
FilterList(sceneItem: this.sceneItem),
)
: null,
icon: const Icon(CupertinoIcons.color_filter),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _SceneItemsState extends State<SceneItems>
child: ListView(
controller: _controller,
physics: const ClampingScrollPhysics(),
padding: const EdgeInsets.all(0.0),
padding: const EdgeInsets.only(top: 12.0),
children: [
...dashboardStore.currentSceneItems.isNotEmpty
? dashboardStore.currentSceneItems
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:get_it/get_it.dart';
import 'package:obs_blade/shared/general/hive_builder.dart';
import 'package:obs_blade/stores/views/dashboard.dart';
Expand Down

0 comments on commit aa3a619

Please sign in to comment.