addactor, addtag dialogs

This commit is contained in:
2022-08-30 23:25:21 +02:00
parent b0f913f8d1
commit 405d7e420e
10 changed files with 302 additions and 64 deletions

View File

@ -1,18 +1,21 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:openmediacentermobile/screen_loading.dart';
import 'package:openmediacentermobile/preview/tag_tile.dart';
import 'package:openmediacentermobile/types/video_data.dart';
import 'package:openmediacentermobile/preview/actor_tile.dart';
import '../api/video_api.dart';
import '../dialog/add_actor_dialog.dart';
import '../dialog/add_tag_dialog.dart';
import '../navigation/video_feed.dart';
import '../screen_loading.dart';
import '../types/video_data.dart';
import '../preview/actor_tile.dart';
import '../api/api.dart';
import '../log/log.dart';
import '../types/actor.dart';
class InfoView extends StatefulWidget {
const InfoView({Key? key, required this.vdata}) : super(key: key);
final VideoData vdata;
const InfoView({Key? key, required this.videoId}) : super(key: key);
final int videoId;
@override
State<InfoView> createState() => _InfoViewState();
@ -20,18 +23,25 @@ class InfoView extends StatefulWidget {
class _InfoViewState extends State<InfoView> {
late Future<List<Actor>> _data;
late Future<VideoData> vdata;
@override
void initState() {
super.initState();
setState(() {
_data = loadData();
vdata = loadVideoData(widget.videoId);
});
super.initState();
}
@override
void didUpdateWidget(InfoView oldWidget) {
super.didUpdateWidget(oldWidget);
}
Future<List<Actor>> loadData() async {
final data = await API
.query("actor", "getActorsOfVideo", {'MovieId': widget.vdata.movieId});
.query("actor", "getActorsOfVideo", {'MovieId': widget.videoId});
if (data == 'null') {
return [];
}
@ -45,42 +55,106 @@ class _InfoViewState extends State<InfoView> {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _data,
builder: (context, AsyncSnapshot<List<Actor>> snapshot) {
future: Future.wait([_data, vdata]),
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
final actors = snapshot.data;
final actors = snapshot.data![0] as List<Actor>;
final videoData = snapshot.data![1] as VideoData;
return Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: 60),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Likes: ${widget.vdata.likes}"),
IconButton(
onPressed: () async {
final data = await API.query("video", "addLike",
{'MovieId': widget.vdata.movieId});
final d = jsonDecode(data);
if (d["result"] != 'success') {
Log.w(d);
}
// bit hacky but it works
widget.vdata.likes += 1;
},
icon: Icon(Icons.thumb_up)),
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) => TagTile(tag: e))
children: [
IconButton(
onPressed: () async {
final data = await API.query("video", "addLike",
{'MovieId': videoData.movieId});
final d = jsonDecode(data);
if (d["result"] != 'success') {
Log.w(d);
}
setState(() {
vdata = loadVideoData(widget.videoId);
});
},
icon: Icon(Icons.thumb_up)),
TextButton(
onPressed: () async {
await showDialog(
context: context,
builder: (context) => AddActorDialog(
movieId: videoData.movieId,
),
);
Log.d("finished dialog");
setState(() {
_data = loadData();
});
},
child: Text("Add Actor"),
),
TextButton(
onPressed: () async {
await showDialog(
context: context,
builder: (context) => AddTagDialog(
movieId: videoData.movieId,
),
);
Log.d("finished dialog");
setState(() {
vdata = loadVideoData(widget.videoId);
});
},
child: Text("Add Tag"),
)
],
),
Text(
"General info:",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text("Likes: ${videoData.likes}"),
Text("Quality: ${videoData.quality}"),
Text("Length: ${videoData.length}sec"),
Text("Actors:",
style: TextStyle(fontWeight: FontWeight.bold)),
actors.isEmpty
? Text("no actors available")
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _renderActors(actors),
),
),
Text("Tags:",
style: TextStyle(fontWeight: FontWeight.bold)),
SizedBox(
height: 5,
),
Wrap(
spacing: 4,
runSpacing: 4,
children: videoData.tags
.map(
(e) => ActionChip(
backgroundColor:
Theme.of(context).secondaryHeaderColor,
label: Text(e.tagName),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoFeed(tag: e),
),
);
},
),
)
.toList(growable: false),
)
]));

View File

@ -1,9 +1,8 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import '../api/api.dart';
import '../api/token.dart';
import '../api/video_api.dart';
import '../platform.dart';
import '../screen_loading.dart';
import '../types/video.dart';
@ -32,15 +31,6 @@ class _VideoScreenState extends State<VideoScreen> {
String url = "";
Future<VideoData> loadVideoData() async {
final data =
await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
final d = jsonDecode(data);
final video = VideoData.fromJson(d);
return video;
}
void initPlayer() async {
final videodata = await _videoData;
@ -57,7 +47,7 @@ class _VideoScreenState extends State<VideoScreen> {
@override
void initState() {
super.initState();
_videoData = loadVideoData();
_videoData = loadVideoData(widget.metaData.id);
initPlayer();
_setAppBarTimer();
}
@ -117,7 +107,7 @@ class _VideoScreenState extends State<VideoScreen> {
}
}
},
behavior: HitTestBehavior.opaque,
// behavior: HitTestBehavior.opaque,
child: Stack(children: [
PageView(
scrollDirection: Axis.vertical,
@ -132,7 +122,7 @@ class _VideoScreenState extends State<VideoScreen> {
url: url,
)),
InfoView(
vdata: snapshot.data!,
videoId: widget.metaData.id,
)
]),
if (_appBarVisible)