Skip to content

Commit

Permalink
Merge pull request #73 from bdlukaa/beta-5
Browse files Browse the repository at this point in the history
Beta 5
  • Loading branch information
curtishall authored Mar 2, 2023
2 parents 444c542 + b00101d commit 49d1163
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 163 deletions.
6 changes: 6 additions & 0 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class API {
);
}
} catch (exception, stacktrace) {
debugPrint('Failed to checkServerCredentials on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
Expand Down Expand Up @@ -104,6 +105,7 @@ class API {
..addAll(devices);
return devices;
} catch (exception, stacktrace) {
debugPrint('Failed to getDevices on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
Expand Down Expand Up @@ -162,6 +164,7 @@ class API {
);
}).cast<Event>();
} catch (exception, stacktrace) {
debugPrint('Failed to getEvents on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
Expand All @@ -187,6 +190,7 @@ class API {
final body = jsonDecode(response.body);
return body['notification_api_endpoint'];
} catch (exception, stacktrace) {
debugPrint('Failed to getNotificationAPIEndpoint on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
Expand Down Expand Up @@ -228,6 +232,7 @@ class API {
debugPrint(response.body);
return true;
} catch (exception, stacktrace) {
debugPrint('Failed to registerNotificationToToken on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
return false;
Expand Down Expand Up @@ -261,6 +266,7 @@ class API {
debugPrint(response.body);
return true;
} catch (exception, stacktrace) {
debugPrint('Failed to unregisterNotificationToken on server $server');
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
return false;
Expand Down
23 changes: 5 additions & 18 deletions lib/widgets/device_grid/desktop_device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

part of 'device_grid.dart';

const kGridInnerPadding = 8.0;
const kGridPadding = EdgeInsets.all(10.0);

typedef FoldedDevices = List<List<Device>>;

class DesktopDeviceGrid extends StatefulWidget {
Expand Down Expand Up @@ -172,27 +169,17 @@ class _DesktopDeviceGridState extends State<DesktopDeviceGrid> {

final crossAxisCount = calculateCrossAxisCount(dl);

return ReorderableGridView.builder(
return StaticGrid(
key: ValueKey(view.currentLayout.hashCode),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount.clamp(1, 50),
mainAxisSpacing: kGridInnerPadding,
crossAxisSpacing: kGridInnerPadding,
childAspectRatio: 16 / 9,
),
padding: kGridPadding,
crossAxisCount: crossAxisCount.clamp(1, 50),
childAspectRatio: 16 / 9,
onReorder: view.reorder,
itemCount: devices.length,
itemBuilder: (context, index) {
final device = devices[index];

children: devices.map((device) {
return DesktopDeviceTile(
key: ValueKey('$device.${device.server.serverUUID}'),
device: device,
);
},
}).toList(),
);
}(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/device_grid/device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import 'package:bluecherry_client/widgets/device_tile_selector.dart';
import 'package:bluecherry_client/widgets/error_warning.dart';
import 'package:bluecherry_client/widgets/hover_button.dart';
import 'package:bluecherry_client/widgets/misc.dart';
import 'package:bluecherry_client/widgets/reorderable_static_grid.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:reorderable_grid_view/reorderable_grid_view.dart';
import 'package:unity_video_player/unity_video_player.dart';

part 'desktop_device_grid.dart';
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/device_grid/mobile_device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ class _MobileDeviceGridChild extends StatelessWidget {
color: Colors.black,
height: double.infinity,
width: double.infinity,
child: ReorderableGridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
child: StaticGrid(
crossAxisCount: <int, int>{
4: 2,
2: 2,
Expand Down
6 changes: 4 additions & 2 deletions lib/widgets/events_playback/events_playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ abstract class EventsPlaybackState extends State<EventsPlaybackWidget> {
@override
void initState() {
super.initState();
timelineController.addListener(() {
if (mounted) setState(() {});
WidgetsBinding.instance.addPostFrameCallback((timestamp) {
timelineController.addListener(() {
if (mounted) setState(() {});
});
});
}

Expand Down
112 changes: 2 additions & 110 deletions lib/widgets/events_playback/events_playback_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import 'package:bluecherry_client/widgets/events/event_player_desktop.dart';
import 'package:bluecherry_client/widgets/events_playback/events_playback.dart';
import 'package:bluecherry_client/widgets/events_playback/timeline_controller.dart';
import 'package:bluecherry_client/widgets/misc.dart';
import 'package:bluecherry_client/widgets/reorderable_static_grid.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:reorderables/reorderables.dart';
import 'package:unity_video_player/unity_video_player.dart';

typedef FutureValueChanged<T> = Future<void> Function(T data);
Expand Down Expand Up @@ -101,8 +101,6 @@ class _EventsPlaybackDesktopState extends EventsPlaybackState {
timelineController.tiles.length,
),
childAspectRatio: 16 / 9,
mainAxisSpacing: kGridInnerPadding,
crossAxisSpacing: kGridInnerPadding,
onReorder: eventsProvider.onReorder,
children: timelineController.tiles.map((tile) {
final has = timelineController.currentItem
Expand All @@ -114,6 +112,7 @@ class _EventsPlaybackDesktopState extends EventsPlaybackState {
.canvasColor;

return IndexedStack(
key: ValueKey(tile),
index: !has ? 0 : 1,
children: [
Container(
Expand Down Expand Up @@ -654,110 +653,3 @@ class FilterTile extends StatelessWidget {
]);
}
}

/// A non-scrollable grid view
class StaticGrid extends StatefulWidget {
final int crossAxisCount;
final List<Widget> children;

final double childAspectRatio;

final double mainAxisSpacing;
final double crossAxisSpacing;

final ReorderCallback onReorder;
final bool reorderable;

const StaticGrid({
Key? key,
required this.crossAxisCount,
required this.children,
this.childAspectRatio = 1.0,
this.mainAxisSpacing = 0.0,
this.crossAxisSpacing = 0.0,
required this.onReorder,
this.reorderable = true,
}) : super(key: key);

@override
State<StaticGrid> createState() => StaticGridState();
}

class StaticGridState extends State<StaticGrid> {
List<Widget> realChildren = [];
int get gridFactor => (realChildren.length / widget.crossAxisCount).round();
void generateRealChildren() {
realChildren = [...widget.children];

bool check() {
if (realChildren.isEmpty) return false;

// if the children length is multiple of the crossAxisCount, return. This
// avoids adding multiple emtpy areas in the view
if (realChildren.length % widget.crossAxisCount == 0) return false;
if (gridFactor == 1) return false;

return true;
}

while (check()) {
realChildren.add(const SizedBox.shrink());
}
}

@override
void initState() {
super.initState();
generateRealChildren();
}

@override
void didUpdateWidget(covariant StaticGrid oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.children != widget.children) {
generateRealChildren();
}
}

@override
Widget build(BuildContext context) {
return Padding(
padding: kGridPadding.add(EdgeInsetsDirectional.only(
start: widget.crossAxisSpacing,
top: widget.mainAxisSpacing,
)),
child: LayoutBuilder(builder: (context, constraints) {
final width = (constraints.biggest.width / widget.crossAxisCount) -
widget.mainAxisSpacing;
return ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: ReorderableWrap(
enableReorder: widget.reorderable,
spacing: widget.mainAxisSpacing,
runSpacing: widget.crossAxisSpacing,
maxMainAxisCount: widget.crossAxisCount,
onReorder: widget.onReorder,
needsLongPressDraggable: isMobile,
alignment: WrapAlignment.center,
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
scrollPhysics: const NeverScrollableScrollPhysics(),
children: List.generate(realChildren.length, (index) {
return SizedBox(
key: ValueKey(index),
// height: height,
width: width,
child: Center(
child: AspectRatio(
aspectRatio: widget.childAspectRatio,
child: realChildren[index],
),
),
);
}),
),
);
}),
);
}
}
4 changes: 1 addition & 3 deletions lib/widgets/events_playback/events_playback_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import 'package:bluecherry_client/widgets/device_grid/device_grid.dart';
import 'package:bluecherry_client/widgets/device_selector_screen.dart';
import 'package:bluecherry_client/widgets/error_warning.dart';
import 'package:bluecherry_client/widgets/events_playback/events_playback.dart';
import 'package:bluecherry_client/widgets/events_playback/events_playback_desktop.dart';
import 'package:bluecherry_client/widgets/events_playback/timeline_controller.dart';
import 'package:bluecherry_client/widgets/reorderable_static_grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -85,8 +85,6 @@ class _EventsPlaybackMobileState extends EventsPlaybackState {
timelineController.tiles.length,
),
childAspectRatio: 16 / 9,
mainAxisSpacing: kGridInnerPadding,
crossAxisSpacing: kGridInnerPadding,
onReorder: eventsProvider.onReorder,
children: timelineController.tiles.map((tile) {
final has =
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/events_playback/timeline_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ class TimelineController extends ChangeNotifier {
}

void setVideoPosition(Duration precision) {
// to avoid issues on the client
if (currentItem == null) return;

assert(currentItem != null);
assert(currentItem is TimelineValue);

Expand Down
Loading

0 comments on commit 49d1163

Please sign in to comment.