diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 7979f47..a4a7b66 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ query( String apinode, String action, Object payload) async { - final Completer cmpl = Completer(); final t = await Token.getInstance().getToken(); if (t != null) { final resp = await http.post( @@ -20,11 +18,9 @@ class API { body: jsonEncode(payload), ); - cmpl.complete(resp.body); + return resp.body; } else { - cmpl.complete(""); + return ""; } - - return cmpl.future; } } diff --git a/lib/login/login_screen.dart b/lib/login/login_screen.dart index b1ba987..881e09e 100644 --- a/lib/login/login_screen.dart +++ b/lib/login/login_screen.dart @@ -21,7 +21,7 @@ class _LoginScreenState extends State { Future login(String password, String domain) async { Log.i("logging in..."); - final compl = Completer(); + // final compl = Completer(); final resp = await http.post( Uri.parse(domain + '/api/login/login'), headers: { @@ -33,7 +33,9 @@ class _LoginScreenState extends State { ); if (resp.statusCode != 200) { - compl.complete(resp.body); + return resp.body; + + // compl.complete(resp.body); } else { final json = jsonDecode(resp.body); final token = json["Token"]; @@ -41,12 +43,14 @@ class _LoginScreenState extends State { Token.getInstance().setToken(token, domain); LoginContext.of(context).onLoggin(true); - compl.complete(""); + return ""; + + // compl.complete(""); } // LoginContext.of(context).onLoggin(true); - return compl.future; + // return compl.future; } @override diff --git a/lib/preview_grid.dart b/lib/preview_grid.dart new file mode 100644 index 0000000..d971eb9 --- /dev/null +++ b/lib/preview_grid.dart @@ -0,0 +1,99 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; +import 'package:openmediacentermobile/platform.dart'; +import 'package:openmediacentermobile/preview_tile.dart'; + +class PreviewGrid extends StatefulWidget { + const PreviewGrid({Key? key, required this.videoLoader}) : super(key: key); + + final Future> Function() videoLoader; + + @override + State createState() => _PreviewGridState(); +} + +class _PreviewGridState extends State { + late Future> _data; + + Image? _previewImage; + + + @override + void initState() { + super.initState(); + _data = widget.videoLoader(); + } + + @override + Widget build(BuildContext context) { + double width = MediaQuery.of(context).size.width; + + return FutureBuilder>( + future: _data, // a previously-obtained Future or null + builder: (BuildContext context, AsyncSnapshot> snapshot) { + if (snapshot.hasError) { + return Text("Error"); + } else if (snapshot.hasData) { + return Stack( + children: [ + MasonryGridView.count( + // every tile should be at max 330 pixels long... + crossAxisCount: isTV() ? width ~/ 200 : width ~/ 275, + // crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330, + + mainAxisSpacing: 4, + crossAxisSpacing: 4, + padding: EdgeInsets.all(5), + itemBuilder: (context, index) { + return PreviewTile( + dta: snapshot.data![index], + onLongPress: (img) { + setState(() { + _previewImage = img; + }); + }, + onLongPressEnd: () { + setState(() { + _previewImage = null; + }); + }, + ); + }, + ), + if (_previewImage != null) ...[ + BackdropFilter( + filter: ImageFilter.blur( + sigmaX: 5.0, + sigmaY: 5.0, + ), + child: Container( + color: Colors.white.withOpacity(0.6), + ), + ), + Container( + child: Center( + child: Padding(padding: EdgeInsets.symmetric(horizontal: 50),child: ClipRRect(borderRadius: BorderRadius.circular(10.0), child: _previewImage!)), + ), + ), + ], + ], + ); + } else { + return Column(children: const [ + SizedBox( + width: 60, + height: 60, + child: CircularProgressIndicator(), + ), + Padding( + padding: EdgeInsets.only(top: 16), + child: Text('Awaiting result...'), + ) + ]); + } + }, + ); + } +} diff --git a/lib/preview_tile.dart b/lib/preview_tile.dart index 57dcac6..7645c82 100644 --- a/lib/preview_tile.dart +++ b/lib/preview_tile.dart @@ -1,6 +1,5 @@ import 'dart:convert'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:openmediacentermobile/videoscreen_desktop.dart' if (dart.library.html) 'package:openmediacentermobile/videoscreen_web.dart' @@ -23,8 +22,10 @@ class VideoT { } class PreviewTile extends StatefulWidget { - const PreviewTile({Key? key, required this.dta}) : super(key: key); + const PreviewTile({Key? key, required this.dta, this.onLongPress, this.onLongPressEnd}) : super(key: key); final VideoT dta; + final Function(Image img)? onLongPress; + final Function? onLongPressEnd; @override _PreviewTileState createState() => _PreviewTileState(); @@ -80,22 +81,39 @@ class _PreviewTileState extends State { children: [ Container( child: Column( - children: [Text(widget.dta.title, style: TextStyle(fontSize: isTV() ? 8 : 12)), snapshot.data!], + children: [ + Text( + widget.dta.title, + style: TextStyle(fontSize: isTV() ? 8 : 10.5), + overflow: TextOverflow.clip, + maxLines: 1, + ), + snapshot.data! + ], ), - color: Colors.green, + color: Color(0xFF6CE56F), ), Positioned.fill( child: Material( color: Colors.transparent, - child: InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => VideoScreen(MetaData: widget.dta), - ), - ); + child: GestureDetector( + behavior: HitTestBehavior.translucent, + onLongPress: () { + if (widget.onLongPress != null) widget.onLongPress!(snapshot.data!); }, + onLongPressEnd: (details) { + if (widget.onLongPressEnd != null) widget.onLongPressEnd!(); + }, + child: InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => VideoScreen(MetaData: widget.dta), + ), + ); + }, + ), ), ), ), diff --git a/lib/shufflescreen.dart b/lib/shufflescreen.dart index 3d1308e..1d82ed5 100644 --- a/lib/shufflescreen.dart +++ b/lib/shufflescreen.dart @@ -51,18 +51,23 @@ class _ShuffleScreenState extends State { crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330, mainAxisSpacing: 4, crossAxisSpacing: 4, + padding: EdgeInsets.all(5), itemCount: 4, itemBuilder: (context, index) { return PreviewTile(dta: snapshot.data![index]); }, ), - const SizedBox(height: 25,), - TextButton.icon(onPressed: () { - setState(() { - _data = loadData(); - }); - - }, icon: const Icon(Icons.update), label: const Text("Shuffle")) + const SizedBox( + height: 25, + ), + TextButton.icon( + onPressed: () { + setState(() { + _data = loadData(); + }); + }, + icon: const Icon(Icons.update), + label: const Text("Shuffle")) ]); } else { return Column(children: const [ diff --git a/lib/video_feed.dart b/lib/video_feed.dart index 43f9801..6b6384c 100644 --- a/lib/video_feed.dart +++ b/lib/video_feed.dart @@ -2,11 +2,10 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:openmediacentermobile/api/api.dart'; +import 'package:openmediacentermobile/preview_grid.dart'; import 'log/log.dart'; -import 'platform.dart'; import 'preview_tile.dart'; -import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; class VideoFeed extends StatefulWidget { const VideoFeed({Key? key}) : super(key: key); @@ -18,7 +17,6 @@ class VideoFeed extends StatefulWidget { } class VideoFeedState extends State { - late Future> _data; Future> loadData() async { final data = await API.query("video", "getMovies", {'Tag': 1, 'Sort': 0}); @@ -30,47 +28,11 @@ class VideoFeedState extends State { return dta; } - @override - void initState() { - super.initState(); - - _data = loadData(); - } - @override Widget build(BuildContext context) { double width = MediaQuery.of(context).size.width; Log.d(width); - return FutureBuilder>( - future: _data, // a previously-obtained Future or null - builder: (BuildContext context, AsyncSnapshot> snapshot) { - if (snapshot.hasError) { - return Text("Error"); - } else if (snapshot.hasData) { - return MasonryGridView.count( - // every tile should be at max 330 pixels long... - crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330, - mainAxisSpacing: 4, - crossAxisSpacing: 4, - itemBuilder: (context, index) { - return PreviewTile(dta: snapshot.data![index]); - }, - ); - } else { - return Column(children: const [ - SizedBox( - width: 60, - height: 60, - child: CircularProgressIndicator(), - ), - Padding( - padding: EdgeInsets.only(top: 16), - child: Text('Awaiting result...'), - ) - ]); - } - }, - ); + return PreviewGrid(videoLoader: () => loadData(),); } } diff --git a/lib/videoscreen_desktop.dart b/lib/videoscreen_desktop.dart index 12ff1e8..6a37ead 100644 --- a/lib/videoscreen_desktop.dart +++ b/lib/videoscreen_desktop.dart @@ -53,6 +53,10 @@ class _VideoScreenState extends State { videoPlayerController: _controller, autoPlay: true, looping: true, + allowFullScreen: true, + allowMuting: true, + allowPlaybackSpeedChanging: true, + zoomAndPan: true ); setState(() {}); diff --git a/pubspec.lock b/pubspec.lock index d7579e4..3cc3cbb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -56,7 +56,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" csslib: dependency: transitive description: @@ -133,7 +133,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: @@ -526,5 +526,5 @@ packages: source: hosted version: "0.2.0+1" sdks: - dart: ">=2.16.0-100.0.dev <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.8.0" diff --git a/test/widget_test.dart b/test/widget_test.dart index 4b17fcb..a165868 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -12,19 +12,6 @@ import 'package:openmediacentermobile/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); }); }