add a video page and disply tiles correctly
This commit is contained in:
@ -10,7 +10,6 @@ class API {
|
||||
String apinode, String action, Object payload) async {
|
||||
final Completer<String> cmpl = Completer();
|
||||
final t = await Token.getInstance().getToken();
|
||||
Log.d(t);
|
||||
if (t != null) {
|
||||
final resp = await http.post(
|
||||
Uri.parse(t.domain + '/api/$apinode/$action'),
|
||||
|
@ -31,8 +31,11 @@ class Token {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final token = await _storage.read(key: 'jwt');
|
||||
final domain = await _storage.read(key: 'domain');
|
||||
|
||||
// check if value is defined in phone store
|
||||
if (token != null && domain != null) {
|
||||
_tokenval = token;
|
||||
_domain = domain;
|
||||
completer.complete(TokenT(token, domain));
|
||||
} else {
|
||||
Log.d("no token defined");
|
||||
|
@ -60,8 +60,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('assets/images/login.png'), fit: BoxFit.cover),
|
||||
image: DecorationImage(image: AssetImage('assets/images/login.png'), fit: BoxFit.cover),
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
@ -76,8 +75,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).size.height * 0.5),
|
||||
padding: EdgeInsets.only(top: MediaQuery.of(context).size.height * 0.5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -88,6 +86,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
TextField(
|
||||
controller: _domainTextController,
|
||||
style: const TextStyle(color: Colors.black),
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.grey.shade100,
|
||||
filled: true,
|
||||
@ -103,6 +102,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
controller: _passwordTextController,
|
||||
style: const TextStyle(),
|
||||
obscureText: true,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.grey.shade100,
|
||||
filled: true,
|
||||
@ -119,8 +119,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
children: [
|
||||
const Text(
|
||||
'Sign in',
|
||||
style: TextStyle(
|
||||
fontSize: 27, fontWeight: FontWeight.w700),
|
||||
style: TextStyle(fontSize: 27, fontWeight: FontWeight.w700),
|
||||
),
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
@ -128,10 +127,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
child: IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: () {
|
||||
final pwd =
|
||||
_passwordTextController.value.text;
|
||||
final domain =
|
||||
_domainTextController.value.text;
|
||||
Log.d("clickkked");
|
||||
final pwd = _passwordTextController.value.text;
|
||||
final domain = _domainTextController.value.text;
|
||||
login(pwd, domain).then((value) {
|
||||
if (value != "") {
|
||||
setState(() {
|
||||
|
@ -1,11 +1,36 @@
|
||||
import "package:dart_vlc/dart_vlc.dart";
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:openmediacentermobile/app.dart';
|
||||
|
||||
import 'log/log.dart';
|
||||
import 'login/logincontext.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
// main app entry point
|
||||
void main() {
|
||||
void main() async {
|
||||
Log.i("App init!");
|
||||
runApp(const LoginContainer(child: App()));
|
||||
if (isDesktop()) {
|
||||
DartVLC.initialize();
|
||||
} else {
|
||||
await loadDeviceInfo();
|
||||
}
|
||||
|
||||
// RawKeyboard.instance.addListener((event) {
|
||||
// if (LogicalKeyboardKey.arrowLeft == event.logicalKey) {
|
||||
// FocusManager.instance.primaryFocus?.focusInDirection(TraversalDirection.left);
|
||||
// } else if (LogicalKeyboardKey.arrowRight == event.logicalKey) {
|
||||
// FocusManager.instance.primaryFocus?.focusInDirection(TraversalDirection.right);
|
||||
// } else if (LogicalKeyboardKey.arrowDown == event.logicalKey) {
|
||||
// FocusManager.instance.primaryFocus?.focusInDirection(TraversalDirection.down);
|
||||
// } else if (LogicalKeyboardKey.arrowUp == event.logicalKey) {
|
||||
// FocusManager.instance.primaryFocus?.focusInDirection(TraversalDirection.up);
|
||||
// }
|
||||
// });
|
||||
|
||||
runApp(Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.select): ActivateIntent(),
|
||||
}, child: const LoginContainer(child: App())));
|
||||
|
||||
// runApp(const LoginContainer(child: App()));
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/videoscreen.dart';
|
||||
|
||||
import 'api/api.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
class VideoT {
|
||||
int id;
|
||||
@ -12,8 +14,7 @@ class VideoT {
|
||||
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());
|
||||
return VideoT(json['MovieName'] as String, json['MovieId'] as int, (json['Ratio'] as num).toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,31 +27,82 @@ class PreviewTile extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PreviewTileState extends State<PreviewTile> {
|
||||
String prev = "";
|
||||
late Future<Image> _preview;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
API.query("video", "readThumbnail", {'Movieid': widget.dta.id}).then(
|
||||
(value) {
|
||||
setState(() {
|
||||
prev = value.substring(23);
|
||||
});
|
||||
});
|
||||
_preview = loadData();
|
||||
}
|
||||
|
||||
Future<Image> loadData() async {
|
||||
final data = await API.query("video", "readThumbnail", {'Movieid': widget.dta.id});
|
||||
|
||||
final img = Image.memory(
|
||||
base64Decode(data.substring(23)),
|
||||
width: double.infinity,
|
||||
fit: BoxFit.fitWidth,
|
||||
);
|
||||
|
||||
// precache image to avoid loading time to render image
|
||||
await precacheImage(img.image, context);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(widget.dta.title),
|
||||
prev != ""
|
||||
? Image.memory(base64Decode(prev))
|
||||
: const CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
return FutureBuilder<Image>(
|
||||
future: _preview, // a previously-obtained Future<String> or null
|
||||
builder: (BuildContext context, AsyncSnapshot<Image> snapshot) {
|
||||
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 : 12)), snapshot.data!],
|
||||
),
|
||||
color: Colors.green,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoScreen(videoID: widget.dta.id),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Column(children: const <Widget>[
|
||||
SizedBox(height: 100),
|
||||
SizedBox(
|
||||
width: 60,
|
||||
height: 60,
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 16),
|
||||
child: Text('Awaiting result...'),
|
||||
),
|
||||
SizedBox(height: 100),
|
||||
]);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/api/api.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);
|
||||
@ -16,36 +18,59 @@ class VideoFeed extends StatefulWidget {
|
||||
}
|
||||
|
||||
class VideoFeedState extends State<VideoFeed> {
|
||||
List<VideoT> _vids = [];
|
||||
late Future<List<VideoT>> _data;
|
||||
|
||||
Future<List<VideoT>> loadData() async {
|
||||
final data = await API.query("video", "getMovies", {'Tag': 1, 'Sort': 0});
|
||||
|
||||
final d = jsonDecode(data);
|
||||
|
||||
List<VideoT> dta = (d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
||||
|
||||
return dta;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
API.query("video", "getMovies", {'Tag': 1, 'Sort': 0}).then((value) {
|
||||
final d = jsonDecode(value);
|
||||
|
||||
List<VideoT> dta =
|
||||
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
||||
|
||||
setState(() {
|
||||
_vids = dta;
|
||||
});
|
||||
});
|
||||
_data = loadData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: MediaQuery.of(context).size.width /
|
||||
MediaQuery.of(context).size.height,
|
||||
crossAxisSpacing: 10),
|
||||
itemCount: _vids.length,
|
||||
itemBuilder: (context, index) {
|
||||
Log.d("item $index built!");
|
||||
return PreviewTile(dta: _vids[index]);
|
||||
});
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
Log.d(width);
|
||||
|
||||
return FutureBuilder<List<VideoT>>(
|
||||
future: _data, // a previously-obtained Future<String> or null
|
||||
builder: (BuildContext context, AsyncSnapshot<List<VideoT>> 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 <Widget>[
|
||||
SizedBox(
|
||||
width: 60,
|
||||
height: 60,
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 16),
|
||||
child: Text('Awaiting result...'),
|
||||
)
|
||||
]);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user