OpenMediacenterMobileFlutter/lib/video_screen/info_view.dart

172 lines
6.0 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:flutter/material.dart';
2022-08-30 21:25:21 +00:00
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 {
2022-08-30 21:25:21 +00:00
const InfoView({Key? key, required this.videoId}) : super(key: key);
final int videoId;
@override
State<InfoView> createState() => _InfoViewState();
}
class _InfoViewState extends State<InfoView> {
late Future<List<Actor>> _data;
2022-08-30 21:25:21 +00:00
late Future<VideoData> vdata;
@override
void initState() {
2022-08-30 21:25:21 +00:00
super.initState();
setState(() {
_data = loadData();
2022-08-30 21:25:21 +00:00
vdata = loadVideoData(widget.videoId);
});
2022-08-30 21:25:21 +00:00
}
@override
void didUpdateWidget(InfoView oldWidget) {
super.didUpdateWidget(oldWidget);
}
Future<List<Actor>> loadData() async {
final data = await API
2022-08-30 21:25:21 +00:00
.query("actor", "getActorsOfVideo", {'MovieId': widget.videoId});
if (data == 'null') {
return [];
}
final d = jsonDecode(data);
List<Actor> dta = (d as List).map((e) => Actor.fromJson(e)).toList();
return dta;
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
2022-08-30 21:25:21 +00:00
future: Future.wait([_data, vdata]),
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
2022-08-30 21:25:21 +00:00
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: [
2022-08-30 21:25:21 +00:00
Row(
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")
2022-08-30 21:25:21 +00:00
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _renderActors(actors),
),
),
2022-08-30 21:25:21 +00:00
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),
)
]));
} else {
return ScreenLoading();
}
},
);
}
List<Widget> _renderActors(List<Actor> actors) {
return actors.map((e) => ActorTile(actor: e)).toList(growable: false);
}
}