linux build
cache previews in sqlite db actor page outsouce different players in seperate classes
This commit is contained in:
37
lib/preview/actor_feed.dart
Normal file
37
lib/preview/actor_feed.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/api.dart';
|
||||
import 'preview_grid.dart';
|
||||
import '../types/actor.dart';
|
||||
import '../types/video.dart';
|
||||
|
||||
class ActorFeed extends StatefulWidget {
|
||||
const ActorFeed({Key? key, required this.actor}) : super(key: key);
|
||||
final Actor actor;
|
||||
|
||||
@override
|
||||
State<ActorFeed> createState() => _ActorFeedState();
|
||||
}
|
||||
|
||||
class _ActorFeedState extends State<ActorFeed> {
|
||||
Future<List<VideoT>> loadData() async {
|
||||
final data = await API
|
||||
.query("actor", "getActorInfo", {'ActorId': widget.actor.actorId});
|
||||
|
||||
final d = jsonDecode(data);
|
||||
|
||||
List<VideoT> dta =
|
||||
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
||||
|
||||
return dta;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PreviewGrid(
|
||||
videoLoader: () => loadData(),
|
||||
);
|
||||
}
|
||||
}
|
73
lib/preview/actor_tile.dart
Normal file
73
lib/preview/actor_tile.dart
Normal file
@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/preview/actor_feed.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,
|
||||
),
|
||||
// todo implement case where we have really an picture
|
||||
SizedBox(
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.person_outline,
|
||||
size: 56,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
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) => Scaffold(
|
||||
appBar: AppBar(title: Text(widget.actor.name)),
|
||||
body: ActorFeed(actor: widget.actor),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -2,9 +2,11 @@ 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/preview_tile.dart';
|
||||
import 'package:openmediacentermobile/screen_loading.dart';
|
||||
|
||||
import '../platform.dart';
|
||||
import '../screen_loading.dart';
|
||||
import '../types/video.dart';
|
||||
import 'preview_tile.dart';
|
||||
|
||||
class PreviewGrid extends StatefulWidget {
|
||||
const PreviewGrid(
|
||||
@ -70,32 +72,45 @@ class _PreviewGridState extends State<PreviewGrid> {
|
||||
Column(
|
||||
children: [
|
||||
if (widget.headerBuilder != null) widget.headerBuilder!(this),
|
||||
Expanded(
|
||||
child: MasonryGridView.count(
|
||||
// every tile should be at max 330 pixels long...
|
||||
crossAxisCount: isTV() ? width ~/ 200 : width ~/ 275,
|
||||
// crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330,
|
||||
itemCount: data.length,
|
||||
mainAxisSpacing: 4,
|
||||
crossAxisSpacing: 4,
|
||||
padding: EdgeInsets.all(5),
|
||||
itemBuilder: (context, index) {
|
||||
return PreviewTile(
|
||||
dta: data[index],
|
||||
onLongPress: (img) {
|
||||
setState(() {
|
||||
_previewImage = img;
|
||||
});
|
||||
},
|
||||
onLongPressEnd: () {
|
||||
setState(() {
|
||||
_previewImage = null;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
data.length > 0
|
||||
? Expanded(
|
||||
child: MasonryGridView.count(
|
||||
// every tile should be at max 330 pixels long...
|
||||
crossAxisCount: isTV() ? width ~/ 200 : width ~/ 275,
|
||||
// crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330,
|
||||
itemCount: data.length,
|
||||
mainAxisSpacing: 4,
|
||||
crossAxisSpacing: 4,
|
||||
padding: EdgeInsets.all(5),
|
||||
itemBuilder: (context, index) {
|
||||
return PreviewTile(
|
||||
dta: data[index],
|
||||
onLongPress: (img) {
|
||||
setState(() {
|
||||
_previewImage = img;
|
||||
});
|
||||
},
|
||||
onLongPressEnd: () {
|
||||
setState(() {
|
||||
_previewImage = null;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
Icon(Icons.warning_amber, size: 52),
|
||||
Text("no item available")
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.footerBuilder != null) widget.footerBuilder!(this),
|
||||
],
|
||||
),
|
||||
|
@ -1,26 +1,16 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart'
|
||||
if (dart.library.html) 'package:openmediacentermobile/video_screen/videoscreen_web.dart'
|
||||
if (dart.library.io) 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
import '../api/api.dart';
|
||||
import '../db/database.dart';
|
||||
import '../log/log.dart';
|
||||
import '../platform.dart';
|
||||
|
||||
// todo put this type in sperate class!
|
||||
class VideoT {
|
||||
int id;
|
||||
String title;
|
||||
double ratio;
|
||||
|
||||
VideoT(this.title, this.id, this.ratio);
|
||||
|
||||
factory VideoT.fromJson(dynamic json) {
|
||||
return VideoT(json['MovieName'] as String, json['MovieId'] as int,
|
||||
(json['Ratio'] as num).toDouble());
|
||||
}
|
||||
}
|
||||
import '../types/video.dart';
|
||||
import '../video_screen/videoscreen.dart';
|
||||
|
||||
class PreviewTile extends StatefulWidget {
|
||||
const PreviewTile(
|
||||
@ -42,6 +32,7 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
super.initState();
|
||||
|
||||
_preview = loadData();
|
||||
Log.d("initial load of tile");
|
||||
}
|
||||
|
||||
@override
|
||||
@ -52,15 +43,45 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
setState(() {
|
||||
_preview = loadData();
|
||||
});
|
||||
Log.i("load of tile due to change");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> insert(int id, Uint8List pic) async {
|
||||
await Db().db().insert(
|
||||
'previews',
|
||||
{'id': id, 'thumbnail': pic},
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Uint8List> _fetchThumbnail(int id) async {
|
||||
final base64str =
|
||||
await API.query("video", "readThumbnail", {'Movieid': id});
|
||||
return base64Decode(base64str.substring(23));
|
||||
}
|
||||
|
||||
Future<Image> loadData() async {
|
||||
final data =
|
||||
await API.query("video", "readThumbnail", {'Movieid': widget.dta.id});
|
||||
Uint8List data;
|
||||
final id = widget.dta.id;
|
||||
if (kIsWeb) {
|
||||
data = await _fetchThumbnail(id);
|
||||
} else {
|
||||
final List<Map<String, dynamic>> prev =
|
||||
await Db().db().query('previews', where: "id=$id");
|
||||
|
||||
if (prev.isEmpty) {
|
||||
data = await _fetchThumbnail(id);
|
||||
insert(id, data);
|
||||
Log.d("Adding $id to db");
|
||||
} else {
|
||||
data = prev.first["thumbnail"] as Uint8List;
|
||||
Log.d("using cached preview for $id");
|
||||
}
|
||||
}
|
||||
|
||||
final img = Image.memory(
|
||||
base64Decode(data.substring(23)),
|
||||
data,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.fitWidth,
|
||||
);
|
||||
@ -87,6 +108,54 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _buildTile(Image image) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
widget.dta.title,
|
||||
style: TextStyle(fontSize: isTV() ? 8 : 10.5),
|
||||
overflow: TextOverflow.clip,
|
||||
maxLines: 1,
|
||||
),
|
||||
image
|
||||
],
|
||||
),
|
||||
color: Color(0x6a94a6ff),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onLongPress: () {
|
||||
if (widget.onLongPress != null) widget.onLongPress!(image);
|
||||
},
|
||||
onLongPressEnd: (details) {
|
||||
if (widget.onLongPressEnd != null) widget.onLongPressEnd!();
|
||||
},
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoScreen(metaData: widget.dta),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Image>(
|
||||
@ -99,54 +168,7 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
if (snapshot.hasError) {
|
||||
return Text("Error");
|
||||
} else if (snapshot.hasData) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
widget.dta.title,
|
||||
style: TextStyle(fontSize: isTV() ? 8 : 10.5),
|
||||
overflow: TextOverflow.clip,
|
||||
maxLines: 1,
|
||||
),
|
||||
snapshot.data!
|
||||
],
|
||||
),
|
||||
color: Color(0x6a94a6ff),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
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),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return _buildTile(snapshot.data!);
|
||||
} else {
|
||||
return _buildLoader();
|
||||
}
|
||||
|
32
lib/preview/tag_tile.dart
Normal file
32
lib/preview/tag_tile.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../types/tag.dart';
|
||||
|
||||
import '../navigation/video_feed.dart';
|
||||
|
||||
class TagTile extends StatelessWidget {
|
||||
const TagTile({Key? key, required this.tag}) : super(key: key);
|
||||
final Tag tag;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => Scaffold(
|
||||
appBar: AppBar(title: Text(tag.tagName)),
|
||||
body: VideoFeed(tag: tag),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(primary: Color(0x6a94a6ff)),
|
||||
child: SizedBox(
|
||||
child: Center(child: Text(tag.tagName)),
|
||||
height: 100,
|
||||
width: 100,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user