make all possible fields private
update dependencies try to infer the prefix of the server url display display size dependent amount on shuffle page
This commit is contained in:
@ -17,18 +17,14 @@ class DrawerPage extends StatefulWidget {
|
||||
enum Section { HOME, SHUFFLE, LOGOUT }
|
||||
|
||||
class _DrawerPageState extends State<DrawerPage> {
|
||||
Section sec = Section.HOME;
|
||||
Section _sec = Section.HOME;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget body;
|
||||
String title;
|
||||
|
||||
/// You can easily control the section for example inside the initState where you check
|
||||
/// if the user logged in, or other related logic
|
||||
switch (sec) {
|
||||
|
||||
/// Display the home section, simply by
|
||||
switch (_sec) {
|
||||
case Section.HOME:
|
||||
body = const VideoFeed();
|
||||
title = widget.title;
|
||||
@ -45,13 +41,13 @@ class _DrawerPageState extends State<DrawerPage> {
|
||||
break;
|
||||
}
|
||||
|
||||
var loginctx = LoginContext.of(context);
|
||||
final loginCtx = LoginContext.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title), actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
loginctx.onLoggin(false);
|
||||
loginCtx.onLoggin(false);
|
||||
Token.getInstance().setToken("", "");
|
||||
},
|
||||
icon: const Icon(Icons.logout))
|
||||
@ -64,7 +60,7 @@ class _DrawerPageState extends State<DrawerPage> {
|
||||
leading: const Icon(Icons.home),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
sec = Section.HOME;
|
||||
_sec = Section.HOME;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
@ -74,7 +70,7 @@ class _DrawerPageState extends State<DrawerPage> {
|
||||
leading: const Icon(Icons.update),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
sec = Section.SHUFFLE;
|
||||
_sec = Section.SHUFFLE;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
@ -84,7 +80,7 @@ class _DrawerPageState extends State<DrawerPage> {
|
||||
leading: const Icon(Icons.settings),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
sec = Section.LOGOUT;
|
||||
_sec = Section.LOGOUT;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
14
lib/app.dart
14
lib/app.dart
@ -3,26 +3,18 @@ import 'package:openmediacentermobile/log/log.dart';
|
||||
import 'package:openmediacentermobile/login/login_screen.dart';
|
||||
|
||||
import 'DrawerPage.dart';
|
||||
import 'api/token.dart';
|
||||
import 'login/logincontext.dart';
|
||||
import 'video_feed.dart';
|
||||
|
||||
// class App extends StatefulWidget {
|
||||
// const App({Key? key}) : super(key: key);
|
||||
// @override
|
||||
// State<StatefulWidget> createState() => AppState();
|
||||
// }
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var loginctx = LoginContext.of(context);
|
||||
var loginCtx = LoginContext.of(context);
|
||||
|
||||
Log.d("We are logged in: ${loginctx.LoggedIn}");
|
||||
Log.d("We are logged in: ${loginCtx.loggedIn}");
|
||||
|
||||
if (!loginctx.LoggedIn) {
|
||||
if (!loginCtx.loggedIn) {
|
||||
return const MaterialApp(home: LoginScreen());
|
||||
} else {
|
||||
return const MaterialApp(
|
||||
|
@ -18,22 +18,28 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
final TextEditingController _domainTextController = TextEditingController();
|
||||
final TextEditingController _passwordTextController = TextEditingController();
|
||||
String error = "";
|
||||
bool _loginActive = false;
|
||||
|
||||
Future<String> login(String password, String domain) async {
|
||||
Log.i("logging in...");
|
||||
// final compl = Completer<String>();
|
||||
final resp = await http.post(
|
||||
Uri.parse(domain + '/api/login/login'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'Password': password,
|
||||
}),
|
||||
);
|
||||
|
||||
http.Response resp;
|
||||
try {
|
||||
resp = await http.post(
|
||||
Uri.parse(domain + '/api/login/login'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'Password': password,
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
return "error" + e.toString();
|
||||
}
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
return resp.body;
|
||||
return "error" + resp.body;
|
||||
|
||||
// compl.complete(resp.body);
|
||||
} else {
|
||||
@ -44,13 +50,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
LoginContext.of(context).onLoggin(true);
|
||||
|
||||
return "";
|
||||
|
||||
// compl.complete("");
|
||||
}
|
||||
|
||||
// LoginContext.of(context).onLoggin(true);
|
||||
|
||||
// return compl.future;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -130,16 +130,26 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
backgroundColor: const Color(0xff4c505b),
|
||||
child: IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
Log.d("clickkked");
|
||||
final pwd = _passwordTextController.value.text;
|
||||
final domain = _domainTextController.value.text;
|
||||
login(pwd, domain).then((value) {
|
||||
if (value != "") {
|
||||
setState(() {
|
||||
error = value;
|
||||
});
|
||||
}
|
||||
|
||||
var err = "";
|
||||
if (domain.startsWith("https://") || domain.startsWith("http://")) {
|
||||
err = await login(pwd, domain);
|
||||
if (err.isEmpty) return;
|
||||
} else {
|
||||
// try to auto infering domain prefix
|
||||
err = await login(pwd, "https://" + domain);
|
||||
if (err.isEmpty) return;
|
||||
err = await login(pwd, "http://" + domain);
|
||||
if (err.isEmpty) return;
|
||||
}
|
||||
|
||||
Log.i(err);
|
||||
setState(() {
|
||||
error = err;
|
||||
});
|
||||
},
|
||||
icon: const Icon(
|
||||
|
@ -12,8 +12,8 @@ class LoginContainer extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LoginContainerState extends State<LoginContainer> {
|
||||
bool loggedIn = false;
|
||||
bool loading = true;
|
||||
bool _loggedIn = false;
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -24,13 +24,13 @@ class _LoginContainerState extends State<LoginContainer> {
|
||||
Log.i("The token value is $value");
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
loggedIn = true;
|
||||
loading = false;
|
||||
_loggedIn = true;
|
||||
_loading = false;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
loggedIn = false;
|
||||
loading = false;
|
||||
_loggedIn = false;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -39,8 +39,8 @@ class _LoginContainerState extends State<LoginContainer> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LoginContext(
|
||||
LoggedIn: loggedIn,
|
||||
child: loading
|
||||
loggedIn: _loggedIn,
|
||||
child: _loading
|
||||
? MaterialApp(
|
||||
home: Container(
|
||||
color: Colors.white,
|
||||
@ -49,9 +49,9 @@ class _LoginContainerState extends State<LoginContainer> {
|
||||
)
|
||||
: widget.child,
|
||||
onLoggin: (bool login) {
|
||||
if (loggedIn != login) {
|
||||
if (_loggedIn != login) {
|
||||
setState(() {
|
||||
loggedIn = login;
|
||||
_loggedIn = login;
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -63,11 +63,11 @@ class LoginContext extends InheritedWidget {
|
||||
const LoginContext(
|
||||
{Key? key,
|
||||
required Widget child,
|
||||
required this.LoggedIn,
|
||||
required this.loggedIn,
|
||||
required this.onLoggin})
|
||||
: super(key: key, child: child);
|
||||
|
||||
final bool LoggedIn;
|
||||
final bool loggedIn;
|
||||
final void Function(bool) onLoggin;
|
||||
|
||||
static LoginContext of(BuildContext context) {
|
||||
@ -79,6 +79,6 @@ class LoginContext extends InheritedWidget {
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(LoginContext old) {
|
||||
return LoggedIn != old.LoggedIn;
|
||||
return loggedIn != old.loggedIn;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import 'log/log.dart';
|
||||
import 'login/logincontext.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
// main app entry point
|
||||
void main() async {
|
||||
Log.i("App init!");
|
||||
DartVLC.initialize();
|
||||
|
@ -16,10 +16,8 @@ class PreviewGrid extends StatefulWidget {
|
||||
|
||||
class _PreviewGridState extends State<PreviewGrid> {
|
||||
late Future<List<VideoT>> _data;
|
||||
|
||||
Image? _previewImage;
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -28,7 +26,7 @@ class _PreviewGridState extends State<PreviewGrid> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
final double width = MediaQuery.of(context).size.width;
|
||||
|
||||
return FutureBuilder<List<VideoT>>(
|
||||
future: _data, // a previously-obtained Future<String> or null
|
||||
|
@ -12,9 +12,9 @@ import 'platform.dart';
|
||||
class VideoT {
|
||||
int id;
|
||||
String title;
|
||||
double Ratio;
|
||||
double ratio;
|
||||
|
||||
VideoT(this.title, this.id, this.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());
|
||||
@ -109,7 +109,7 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoScreen(MetaData: widget.dta),
|
||||
builder: (context) => VideoScreen(metaData: widget.dta),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
@ -3,7 +3,7 @@ import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:openmediacentermobile/preview_tile.dart';
|
||||
import 'preview_tile.dart';
|
||||
|
||||
import 'api/api.dart';
|
||||
import 'platform.dart';
|
||||
@ -18,8 +18,8 @@ class ShuffleScreen extends StatefulWidget {
|
||||
class _ShuffleScreenState extends State<ShuffleScreen> {
|
||||
late Future<List<VideoT>> _data;
|
||||
|
||||
Future<List<VideoT>> loadData() async {
|
||||
final data = await API.query("video", "getRandomMovies", {'Number': 4, 'Seed': Random().nextInt(0x7fffffff)});
|
||||
Future<List<VideoT>> loadData(int nr) async {
|
||||
final data = await API.query("video", "getRandomMovies", {'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
|
||||
|
||||
final d = jsonDecode(data);
|
||||
|
||||
@ -32,7 +32,11 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_data = loadData();
|
||||
_data = Future.delayed(Duration.zero).then((_) {
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
return loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
@ -52,7 +56,7 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
|
||||
mainAxisSpacing: 4,
|
||||
crossAxisSpacing: 4,
|
||||
padding: EdgeInsets.all(5),
|
||||
itemCount: 4,
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return PreviewTile(dta: snapshot.data![index]);
|
||||
},
|
||||
@ -63,7 +67,7 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_data = loadData();
|
||||
_data = loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2);
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.update),
|
||||
|
@ -14,19 +14,19 @@ import 'log/log.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
class VideoScreen extends StatefulWidget {
|
||||
const VideoScreen({Key? key, required this.MetaData}) : super(key: key);
|
||||
final VideoT MetaData;
|
||||
const VideoScreen({Key? key, required this.metaData}) : super(key: key);
|
||||
final VideoT metaData;
|
||||
|
||||
@override
|
||||
State<VideoScreen> createState() => _VideoScreenState();
|
||||
}
|
||||
|
||||
class _VideoScreenState extends State<VideoScreen> {
|
||||
Player? player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
|
||||
Player? _player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
|
||||
ChewieController? _chewieController;
|
||||
|
||||
void loadData() async {
|
||||
final data = await API.query("video", "loadVideo", {'MovieId': widget.MetaData.id});
|
||||
final data = await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
|
||||
|
||||
final d = jsonDecode(data);
|
||||
|
||||
@ -41,7 +41,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
if (isDesktop()) {
|
||||
final media2 = Media.network(path);
|
||||
|
||||
player?.open(
|
||||
_player?.open(
|
||||
media2,
|
||||
autoStart: true, // default
|
||||
);
|
||||
@ -70,9 +70,9 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
if(isDesktop()){
|
||||
RawKeyboard.instance.addListener((value) {
|
||||
if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
|
||||
player?.seek(player!.position.position! + const Duration(seconds: 5));
|
||||
_player?.seek(_player!.position.position! + const Duration(seconds: 5));
|
||||
} else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) {
|
||||
player?.seek(player!.position.position! + const Duration(seconds: -5));
|
||||
_player?.seek(_player!.position.position! + const Duration(seconds: -5));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -87,7 +87,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
if (isDesktop()) {
|
||||
player?.dispose();
|
||||
_player?.dispose();
|
||||
} else {
|
||||
_chewieController?.videoPlayerController.dispose();
|
||||
_chewieController?.dispose();
|
||||
@ -98,7 +98,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.MetaData.title),
|
||||
title: Text(widget.metaData.title),
|
||||
),
|
||||
body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()),
|
||||
);
|
||||
@ -106,10 +106,9 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
|
||||
Widget videoDesktop() {
|
||||
return Video(
|
||||
player: player,
|
||||
player: _player,
|
||||
scale: 1.0, // default
|
||||
showControls: true,
|
||||
playlistLength: 1, // default
|
||||
showControls: true
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user