new categorie page

better folder structure
more info on video info page
This commit is contained in:
lukas-heiligenbrunner 2022-08-28 18:48:53 +02:00
parent ec66a6f4a8
commit 41a133b6c4
12 changed files with 404 additions and 111 deletions

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/shufflescreen.dart'; import 'navigation/categorie_screen.dart';
import 'package:openmediacentermobile/video_feed.dart'; import 'navigation/shufflescreen.dart';
import 'navigation/video_feed.dart';
import 'api/token.dart'; import 'api/token.dart';
import 'login/logincontext.dart'; import 'login/logincontext.dart';
@ -14,7 +15,7 @@ class DrawerPage extends StatefulWidget {
_DrawerPageState createState() => _DrawerPageState(); _DrawerPageState createState() => _DrawerPageState();
} }
enum Section { HOME, SHUFFLE, LOGOUT } enum Section { HOME, SHUFFLE, LOGOUT, CATEGORIE }
class _DrawerPageState extends State<DrawerPage> { class _DrawerPageState extends State<DrawerPage> {
Section _sec = Section.HOME; Section _sec = Section.HOME;
@ -39,6 +40,11 @@ class _DrawerPageState extends State<DrawerPage> {
body = const Text("also todo"); body = const Text("also todo");
title = "Settings"; title = "Settings";
break; break;
case Section.CATEGORIE:
body = CategorieScreen();
title = "Categories";
break;
} }
final loginCtx = LoginContext.of(context); final loginCtx = LoginContext.of(context);
@ -78,6 +84,16 @@ class _DrawerPageState extends State<DrawerPage> {
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
ListTile(
title: const Text('Categories'),
leading: const Icon(Icons.category),
onTap: () {
setState(() {
_sec = Section.CATEGORIE;
});
Navigator.pop(context);
},
),
ListTile( ListTile(
title: const Text('Settings'), title: const Text('Settings'),
leading: const Icon(Icons.settings), leading: const Icon(Icons.settings),

View File

@ -0,0 +1,82 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import '../navigation/video_feed.dart';
import '../screen_loading.dart';
import '../api/api.dart';
import '../types/tag.dart';
class CategorieScreen extends StatefulWidget {
const CategorieScreen({Key? key}) : super(key: key);
@override
State<CategorieScreen> createState() => _CategorieScreenState();
}
class _CategorieScreenState extends State<CategorieScreen> {
late Future<List<Tag>> _categories;
Future<List<Tag>> loadVideoData() async {
final data = await API.query("tags", "getAllTags", {});
final d = (jsonDecode(data) ?? []) as List<dynamic>;
final tags = d.map((e) => Tag.fromJson(e)).toList(growable: false);
return tags;
}
@override
void initState() {
super.initState();
_categories = loadVideoData();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _categories,
builder: (context, AsyncSnapshot<List<Tag>> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return ScreenLoading();
}
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
return Padding(
padding: EdgeInsets.all(5),
child: Wrap(
spacing: 5,
runSpacing: 5,
alignment: WrapAlignment.start,
children: snapshot.data!
.map((e) => ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text(e.tagName)),
body: VideoFeed(tag: e),
),
),
);
},
style: ElevatedButton.styleFrom(
primary: Color(0x6a94a6ff)),
child: SizedBox(
child: Center(child: Text(e.tagName)),
height: 100,
width: 100,
),
))
.toList(growable: false),
),
);
} else {
return ScreenLoading();
}
},
);
}
}

View File

@ -2,11 +2,11 @@ import 'dart:convert';
import 'dart:math'; import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/preview_grid.dart'; import 'package:openmediacentermobile/preview/preview_grid.dart';
import 'preview_tile.dart'; import '../preview/preview_tile.dart';
import 'api/api.dart'; import '../api/api.dart';
import 'platform.dart'; import '../platform.dart';
class ShuffleScreen extends StatefulWidget { class ShuffleScreen extends StatefulWidget {
const ShuffleScreen({Key? key}) : super(key: key); const ShuffleScreen({Key? key}) : super(key: key);

View File

@ -2,13 +2,15 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/api/api.dart'; import 'package:openmediacentermobile/api/api.dart';
import 'package:openmediacentermobile/preview_grid.dart'; import 'package:openmediacentermobile/preview/preview_grid.dart';
import 'log/log.dart'; import '../log/log.dart';
import 'preview_tile.dart'; import '../preview/preview_tile.dart';
import '../types/tag.dart';
class VideoFeed extends StatefulWidget { class VideoFeed extends StatefulWidget {
const VideoFeed({Key? key}) : super(key: key); const VideoFeed({Key? key, this.tag}) : super(key: key);
final Tag? tag;
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -18,7 +20,8 @@ class VideoFeed extends StatefulWidget {
class VideoFeedState extends State<VideoFeed> { class VideoFeedState extends State<VideoFeed> {
Future<List<VideoT>> loadData() async { Future<List<VideoT>> loadData() async {
final data = await API.query("video", "getMovies", {'Tag': 1, 'Sort': 0}); final data = await API.query(
"video", "getMovies", {'Tag': widget.tag?.tagId ?? 1, 'Sort': 0});
final d = jsonDecode(data); final d = jsonDecode(data);

View File

@ -3,7 +3,7 @@ import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:openmediacentermobile/platform.dart'; import 'package:openmediacentermobile/platform.dart';
import 'package:openmediacentermobile/preview_tile.dart'; import 'package:openmediacentermobile/preview/preview_tile.dart';
import 'package:openmediacentermobile/screen_loading.dart'; import 'package:openmediacentermobile/screen_loading.dart';
class PreviewGrid extends StatefulWidget { class PreviewGrid extends StatefulWidget {
@ -42,9 +42,17 @@ class _PreviewGridState extends State<PreviewGrid> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double width = MediaQuery.of(context).size.width; final double width = MediaQuery.of(context).size.width;
return FutureBuilder<List<VideoT>>( return RefreshIndicator(
onRefresh: () async {
loadData();
await Future.delayed(Duration(milliseconds: 600));
},
triggerMode: RefreshIndicatorTriggerMode.anywhere,
color: Colors.purple,
child: FutureBuilder<List<VideoT>>(
future: _data, future: _data,
builder: (BuildContext context, AsyncSnapshot<List<VideoT>> snapshot) { builder:
(BuildContext context, AsyncSnapshot<List<VideoT>> snapshot) {
if (snapshot.hasError) { if (snapshot.hasError) {
return Text("Error"); return Text("Error");
} else if (snapshot.hasData) { } else if (snapshot.hasData) {
@ -53,7 +61,7 @@ class _PreviewGridState extends State<PreviewGrid> {
return ScreenLoading(); return ScreenLoading();
} }
}, },
); ));
} }
Widget _mainGrid(List<VideoT> data, double width) { Widget _mainGrid(List<VideoT> data, double width) {

View File

@ -5,8 +5,8 @@ import 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart'
if (dart.library.html) 'package:openmediacentermobile/video_screen/videoscreen_web.dart' if (dart.library.html) 'package:openmediacentermobile/video_screen/videoscreen_web.dart'
if (dart.library.io) 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart'; if (dart.library.io) 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart';
import 'api/api.dart'; import '../api/api.dart';
import 'platform.dart'; import '../platform.dart';
// todo put this type in sperate class! // todo put this type in sperate class!
class VideoT { class VideoT {
@ -71,11 +71,31 @@ class _PreviewTileState extends State<PreviewTile> {
return img; return img;
} }
Widget _buildLoader() {
return Column(children: const <Widget>[
SizedBox(height: 50),
SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting result...'),
),
SizedBox(height: 50),
]);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Image>( return FutureBuilder<Image>(
future: _preview, // a previously-obtained Future<String> or null future: _preview, // a previously-obtained Future<String> or null
builder: (BuildContext context, AsyncSnapshot<Image> snapshot) { builder: (BuildContext context, AsyncSnapshot<Image> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return _buildLoader();
}
if (snapshot.hasError) { if (snapshot.hasError) {
return Text("Error"); return Text("Error");
} else if (snapshot.hasData) { } else if (snapshot.hasData) {
@ -128,19 +148,7 @@ class _PreviewTileState extends State<PreviewTile> {
), ),
); );
} else { } else {
return Column(children: const <Widget>[ return _buildLoader();
SizedBox(height: 100),
SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting result...'),
),
SizedBox(height: 100),
]);
} }
}, },
); );

17
lib/types/actor.dart Normal file
View File

@ -0,0 +1,17 @@
class Actor {
int actorId;
String name;
String thumbnail;
Actor(this.actorId, this.name, this.thumbnail);
factory Actor.fromJson(dynamic json) {
return Actor(json['ActorId'] as int, json['Name'] as String,
json['Thumbnail'] as String);
}
@override
String toString() {
return 'Actor{ActorId: $actorId, Name: $name, Thumbnail: $thumbnail}';
}
}

15
lib/types/tag.dart Normal file
View File

@ -0,0 +1,15 @@
class Tag {
String tagName;
int tagId;
Tag(this.tagName, this.tagId);
@override
String toString() {
return 'Tag{tagName: $tagName, tagId: $tagId}';
}
factory Tag.fromJson(dynamic json) {
return Tag(json['TagName'] as String, json['TagId'] as int);
}
}

54
lib/types/video_data.dart Normal file
View File

@ -0,0 +1,54 @@
import 'tag.dart';
import 'actor.dart';
class VideoData {
String movieName;
int movieId;
String movieUrl;
String poster;
int likes;
int quality;
int length;
List<Tag> tags;
List<Tag> suggestedTags;
List<Actor> actors;
VideoData(
this.movieName,
this.movieId,
this.movieUrl,
this.poster,
this.likes,
this.quality,
this.length,
this.tags,
this.suggestedTags,
this.actors);
@override
String toString() {
return 'VideoData{movieName: $movieName, movieId: $movieId, movieUrl: $movieUrl, poster: $poster, likes: $likes, quality: $quality, length: $length, tags: $tags, suggestedTags: $suggestedTags, actors: $actors}';
}
factory VideoData.fromJson(dynamic json) {
return VideoData(
json['MovieName'] as String,
json['MovieId'] as int,
json['MovieUrl'] as String,
json['Poster'] as String,
json['Likes'] as int,
json['Quality'] as int,
json['Length'] as int,
((json['Tags'] ?? <dynamic>[]) as List<dynamic>)
.map((e) => Tag.fromJson(e))
.toList(growable: false),
((json['SuggestedTag'] ?? []) as List<dynamic>)
.map((e) => Tag.fromJson(e))
.toList(growable: false),
((json['Actors'] ?? []) as List<dynamic>)
.map((e) => Actor.fromJson(e))
.toList(growable: false),
);
}
}

View File

@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import '../platform.dart';
import '../types/actor.dart';
class ActorTile extends StatefulWidget {
const ActorTile({Key? key, required this.actor}) : super(key: key);
final Actor actor;
@override
State<ActorTile> createState() => _ActorTileState();
}
class _ActorTileState extends State<ActorTile> {
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Stack(
children: [
Container(
child: Column(
children: [
Text(
widget.actor.name,
style: TextStyle(fontSize: isTV() ? 8 : 10.5),
overflow: TextOverflow.clip,
maxLines: 1,
),
SizedBox(
height: 100,
width: 100,
)
],
),
color: Color(0x6a94a6ff),
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onLongPress: () {},
onLongPressEnd: (details) {},
child: InkWell(
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) =>
// VideoScreen(metaData: widget.dta),
// ),
// );
},
),
),
),
),
],
),
);
}
}

View File

@ -2,12 +2,15 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/screen_loading.dart'; import 'package:openmediacentermobile/screen_loading.dart';
import 'package:openmediacentermobile/types/video_data.dart';
import 'package:openmediacentermobile/video_screen/actor_tile.dart';
import '../api/api.dart'; import '../api/api.dart';
import '../types/actor.dart';
class ActorView extends StatefulWidget { class ActorView extends StatefulWidget {
const ActorView({Key? key, required this.videoId}) : super(key: key); const ActorView({Key? key, required this.vdata}) : super(key: key);
final int videoId; final VideoData vdata;
@override @override
State<ActorView> createState() => _ActorViewState(); State<ActorView> createState() => _ActorViewState();
@ -26,7 +29,7 @@ class _ActorViewState extends State<ActorView> {
Future<List<Actor>> loadData() async { Future<List<Actor>> loadData() async {
final data = await API final data = await API
.query("actor", "getActorsOfVideo", {'MovieId': widget.videoId}); .query("actor", "getActorsOfVideo", {'MovieId': widget.vdata.movieId});
if (data == 'null') { if (data == 'null') {
return []; return [];
} }
@ -46,11 +49,27 @@ class _ActorViewState extends State<ActorView> {
return Text("Error"); return Text("Error");
} else if (snapshot.hasData) { } else if (snapshot.hasData) {
final actors = snapshot.data; final actors = snapshot.data;
if (actors?.isEmpty ?? true) { return Padding(
return Text("no actors available"); padding: EdgeInsets.only(left: 10, right: 10, top: 30),
} else { child: Column(
return Column(children: _renderActors(snapshot.data!)); crossAxisAlignment: CrossAxisAlignment.start,
} children: [
Text("Likes: ${widget.vdata.likes}"),
Text("Quality: ${widget.vdata.quality}"),
Text("Length: ${widget.vdata.length}sec"),
Text("Actors:"),
actors?.isEmpty ?? true
? Text("no actors available")
: Row(
children: _renderActors(snapshot.data!),
),
Text("Tags:"),
Row(
children: widget.vdata.tags
.map((e) => Text(e.tagName))
.toList(growable: false),
)
]));
} else { } else {
return ScreenLoading(); return ScreenLoading();
} }
@ -59,29 +78,6 @@ class _ActorViewState extends State<ActorView> {
} }
List<Widget> _renderActors(List<Actor> actors) { List<Widget> _renderActors(List<Actor> actors) {
return actors return actors.map((e) => ActorTile(actor: e)).toList(growable: false);
.map((e) => Text(
e.name,
style: TextStyle(color: Colors.black),
))
.toList(growable: false);
}
}
class Actor {
int actorId;
String name;
String thumbnail;
Actor(this.actorId, this.name, this.thumbnail);
factory Actor.fromJson(dynamic json) {
return Actor(json['ActorId'] as int, json['Name'] as String,
json['Thumbnail'] as String);
}
@override
String toString() {
return 'Actor{ActorId: $actorId, Name: $name, Thumbnail: $thumbnail}';
} }
} }

View File

@ -6,13 +6,15 @@ import 'package:chewie/chewie.dart';
import "package:dart_vlc/dart_vlc.dart"; import "package:dart_vlc/dart_vlc.dart";
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:openmediacentermobile/preview_tile.dart'; import 'package:openmediacentermobile/preview/preview_tile.dart';
import 'package:openmediacentermobile/screen_loading.dart';
import 'package:openmediacentermobile/video_screen/actor_view.dart'; import 'package:openmediacentermobile/video_screen/actor_view.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
import '../api/api.dart'; import '../api/api.dart';
import '../api/token.dart'; import '../api/token.dart';
import '../platform.dart'; import '../platform.dart';
import '../types/video_data.dart';
class VideoScreen extends StatefulWidget { class VideoScreen extends StatefulWidget {
const VideoScreen({Key? key, required this.metaData}) : super(key: key); const VideoScreen({Key? key, required this.metaData}) : super(key: key);
@ -29,20 +31,26 @@ class _VideoScreenState extends State<VideoScreen> {
bool _appBarVisible = true; bool _appBarVisible = true;
Timer? _appBarTimer; Timer? _appBarTimer;
late Future<VideoData> _videoData;
void loadData() async { Future<VideoData> loadVideoData() async {
final data = final data =
await API.query("video", "loadVideo", {'MovieId': widget.metaData.id}); await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
final d = jsonDecode(data); final d = jsonDecode(data);
final video = VideoData.fromJson(d);
return video;
}
void initPlayer() async {
final videodata = await _videoData;
final url = d["MovieUrl"];
final token = await Token.getInstance().getToken(); final token = await Token.getInstance().getToken();
if (token == null) return; if (token == null) return;
final baseurl = token.domain; final baseurl = token.domain;
// todo not static middle path // todo not static middle path
final path = baseurl + "/videos/vids/" + url; final path = baseurl + "/videos/vids/" + videodata.movieUrl;
if (isDesktop()) { if (isDesktop()) {
final media2 = Media.network(path); final media2 = Media.network(path);
@ -73,6 +81,9 @@ class _VideoScreenState extends State<VideoScreen> {
void initState() { void initState() {
super.initState(); super.initState();
_videoData = loadVideoData();
initPlayer();
if (isDesktop()) { if (isDesktop()) {
RawKeyboard.instance.addListener((value) { RawKeyboard.instance.addListener((value) {
if (value.logicalKey == LogicalKeyboardKey.arrowRight) { if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
@ -85,7 +96,6 @@ class _VideoScreenState extends State<VideoScreen> {
}); });
} }
loadData();
_setAppBarTimer(); _setAppBarTimer();
} }
@ -121,23 +131,38 @@ class _VideoScreenState extends State<VideoScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: MouseRegion( body: FutureBuilder(
onHover: (PointerEvent event) { future: _videoData,
builder: (context, AsyncSnapshot<VideoData> snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
return MouseRegion(
onHover: (PointerEvent event) async {
if (event.delta.dx != 0 || event.delta.dy != 0) { if (event.delta.dx != 0 || event.delta.dy != 0) {
if (_appBarVisible) {
await Future.delayed(Duration(milliseconds: 100));
setState(() {
_appBarVisible = false;
});
} else {
setState(() { setState(() {
_appBarVisible = true; _appBarVisible = true;
}); });
_setAppBarTimer(); _setAppBarTimer();
} }
}
}, },
child: Stack(children: [ child: Stack(children: [
PageView( PageView(
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
controller: _controller, controller: _controller,
children: [ children: [
Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()), Center(
child:
isDesktop() ? videoDesktop() : videoNotDesktop()),
ActorView( ActorView(
videoId: widget.metaData.id, vdata: snapshot.data!,
) )
]), ]),
if (_appBarVisible) if (_appBarVisible)
@ -148,7 +173,8 @@ class _VideoScreenState extends State<VideoScreen> {
child: AppBar( child: AppBar(
title: Text(widget.metaData.title), title: Text(widget.metaData.title),
leading: new IconButton( leading: new IconButton(
icon: new Icon(Icons.arrow_back_ios, color: Colors.grey), icon:
new Icon(Icons.arrow_back_ios, color: Colors.grey),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
backgroundColor: backgroundColor:
@ -157,6 +183,11 @@ class _VideoScreenState extends State<VideoScreen> {
), ),
), ),
]), ]),
);
} else {
return ScreenLoading();
}
},
), ),
); );
} }