Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6941225e6d | |||
fc96c5c7d2 | |||
7f039396aa | |||
96b8d172ff | |||
a7756da713 | |||
02e73eed1b |
26
.metadata
26
.metadata
@ -1,10 +1,30 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: 37de8a2a9ad217ec9d731f8af0bd7c83e8f4980c
|
||||
channel: master
|
||||
revision: f92f44110e87bad5ff168335c36da6f6053036e6
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: f92f44110e87bad5ff168335c36da6f6053036e6
|
||||
base_revision: f92f44110e87bad5ff168335c36da6f6053036e6
|
||||
- platform: web
|
||||
create_revision: f92f44110e87bad5ff168335c36da6f6053036e6
|
||||
base_revision: f92f44110e87bad5ff168335c36da6f6053036e6
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'token.dart';
|
||||
|
||||
class TokenException implements Exception {
|
||||
@ -11,7 +12,7 @@ class TokenException implements Exception {
|
||||
class API {
|
||||
static Future<String> query(
|
||||
String apinode, String action, Object payload) async {
|
||||
final t = await Token.getInstance().getToken();
|
||||
final t = await getToken();
|
||||
if (t != null) {
|
||||
final resp = await http.post(
|
||||
Uri.parse(t.domain + '/api/$apinode/$action'),
|
||||
|
@ -1,66 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import '../log/log.dart';
|
||||
import 'package:openmediacentermobile/db/settings_db.dart';
|
||||
|
||||
class TokenT {
|
||||
String token;
|
||||
String domain;
|
||||
String videoPath;
|
||||
String tvPath;
|
||||
|
||||
TokenT(this.token, this.domain, this.videoPath, this.tvPath);
|
||||
TokenT(this.token, this.domain);
|
||||
}
|
||||
|
||||
class Token {
|
||||
static final Token _token = Token._();
|
||||
final _storage = const FlutterSecureStorage();
|
||||
|
||||
String _tokenval = "";
|
||||
String _domain = "";
|
||||
String _vPath = "";
|
||||
String _tvPath = "";
|
||||
|
||||
static Token getInstance() {
|
||||
return _token;
|
||||
}
|
||||
|
||||
Future<TokenT?> getToken() async {
|
||||
if (_tokenval == "" || _domain == "" || _vPath == "") {
|
||||
Log.d("reading token store");
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final token = await _storage.read(key: 'jwt');
|
||||
final domain = await _storage.read(key: 'domain');
|
||||
// todo paths should be loaded on each app start
|
||||
final vPath = await _storage.read(key: 'videoPath');
|
||||
final tvPath = await _storage.read(key: 'tvPath');
|
||||
|
||||
// check if value is defined in phone store
|
||||
if (token != null && domain != null && vPath != null) {
|
||||
_tokenval = token;
|
||||
_domain = domain;
|
||||
return TokenT(token, domain, vPath, tvPath ?? "");
|
||||
} else {
|
||||
Log.d("no token defined");
|
||||
Future<TokenT?> getToken() async {
|
||||
final settings = await SettingsDB.getInstance().getSettings();
|
||||
if (settings.token == "" || settings.domain == "") {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return TokenT(_tokenval, _domain, _vPath, _tvPath);
|
||||
return TokenT(settings.token, settings.domain);
|
||||
}
|
||||
}
|
||||
|
||||
void setToken(String token, String domain, String videoPath, String tvPath) {
|
||||
_tokenval = token;
|
||||
_domain = domain;
|
||||
_vPath = videoPath;
|
||||
_tvPath = tvPath;
|
||||
_storage.write(key: 'jwt', value: token);
|
||||
_storage.write(key: 'domain', value: domain);
|
||||
_storage.write(key: 'videoPath', value: videoPath);
|
||||
_storage.write(key: 'tvPath', value: tvPath);
|
||||
}
|
||||
|
||||
Token._();
|
||||
}
|
||||
|
12
lib/app.dart
12
lib/app.dart
@ -3,7 +3,6 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/log/log.dart';
|
||||
import 'package:openmediacentermobile/login/login_screen.dart';
|
||||
import 'package:openmediacentermobile/utils/feature_context.dart';
|
||||
|
||||
import 'drawer/drawer_page.dart';
|
||||
import 'login/login_context.dart';
|
||||
@ -22,21 +21,20 @@ class App extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loginCtx = LoginContext.of(context);
|
||||
var loginCtx = LoginContext.of(context);
|
||||
|
||||
Log.d("We are logged in: ${loginCtx.loggedIn}");
|
||||
|
||||
if (!loginCtx.loggedIn) {
|
||||
return const MaterialApp(home: LoginScreen());
|
||||
} else {
|
||||
return FeatureContainer(
|
||||
child: MaterialApp(
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
appBarTheme: AppBarTheme(backgroundColor: Color(0xff0d0d0d))),
|
||||
scrollBehavior: AppScrollBehavior(),
|
||||
home: DrawerPage(
|
||||
title: 'OpenMediaCenter',
|
||||
),
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,47 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart' as nativeffi;
|
||||
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart' as webffi;
|
||||
|
||||
import '../log/log.dart';
|
||||
|
||||
class Db {
|
||||
late Database _db;
|
||||
|
||||
void init() async {
|
||||
if (kIsWeb) {
|
||||
Log.i("Database on web is not supported");
|
||||
return;
|
||||
}
|
||||
Future<void> init() async {
|
||||
String dbpath = 'previews.db';
|
||||
if (defaultTargetPlatform == TargetPlatform.android ||
|
||||
defaultTargetPlatform == TargetPlatform.iOS) {
|
||||
dbpath = join(await getDatabasesPath(), dbpath);
|
||||
} else if(kIsWeb) {
|
||||
databaseFactory = webffi.databaseFactoryFfiWeb;
|
||||
} else {
|
||||
|
||||
|
||||
// Initialize FFI
|
||||
sqfliteFfiInit();
|
||||
nativeffi.sqfliteFfiInit();
|
||||
// Change the default factory
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
databaseFactory = nativeffi.databaseFactoryFfi;
|
||||
}
|
||||
|
||||
_db = await openDatabase(
|
||||
dbpath,
|
||||
onCreate: (db, version) {
|
||||
return db.execute(
|
||||
'CREATE TABLE previews(id INTEGER PRIMARY KEY, thumbnail BLOB)',
|
||||
final batch = db.batch();
|
||||
batch.execute(
|
||||
'CREATE TABLE previews(id INTEGER PRIMARY KEY, thumbnail BLOB);',
|
||||
);
|
||||
batch.execute(
|
||||
'CREATE TABLE settings(domain TEXT, token TEXT, videopath TEXT, tilewidth INTEGER);',
|
||||
);
|
||||
batch.insert("settings",
|
||||
{"domain": "", "token": "", "videopath": "", "tilewidth": 0});
|
||||
return batch.commit();
|
||||
},
|
||||
// Set the version. This executes the onCreate function and provides a
|
||||
// path to perform database upgrades and downgrades.
|
||||
version: 1,
|
||||
version: 2,
|
||||
);
|
||||
}
|
||||
|
||||
@ -46,10 +54,16 @@ class Db {
|
||||
|
||||
/// get db size in bytes
|
||||
Future<int> getDbSize() async {
|
||||
final int cnt = (await Db().db().rawQuery("pragma page_count;"))[0]
|
||||
["page_count"] as int;
|
||||
final batch = _db.batch();
|
||||
batch.rawQuery("pragma page_count;");
|
||||
batch.rawQuery("pragma page_size;");
|
||||
final result = (await batch.commit(noResult: false));
|
||||
print(result);
|
||||
|
||||
final int cnt =
|
||||
((result[0] as List<Map<String, dynamic>>)[0]["page_count"] as int);
|
||||
final int pagesize =
|
||||
(await Db().db().rawQuery("pragma page_size;"))[0]["page_size"] as int;
|
||||
(result[1] as List<Map<String, dynamic>>)[0]["page_size"] as int;
|
||||
return cnt * pagesize;
|
||||
}
|
||||
|
||||
|
51
lib/db/settings_db.dart
Normal file
51
lib/db/settings_db.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'database.dart';
|
||||
|
||||
class SettingsT {
|
||||
String domain;
|
||||
String token;
|
||||
String videopath;
|
||||
int tilewidth;
|
||||
|
||||
SettingsT(this.domain, this.token, this.videopath, this.tilewidth);
|
||||
}
|
||||
|
||||
class SettingsDB {
|
||||
static final SettingsDB _instance = SettingsDB._();
|
||||
|
||||
SettingsT _settings = SettingsT("", "", "", 0);
|
||||
bool _initialized = false;
|
||||
|
||||
Future<SettingsT> getSettings() async {
|
||||
if (!_initialized) {
|
||||
final result = (await Db().db().query("settings",
|
||||
where: "1",
|
||||
columns: ["domain", "token", "videopath", "tilewidth"]))
|
||||
.first;
|
||||
|
||||
_settings = SettingsT(
|
||||
result["domain"] as String,
|
||||
result["token"] as String,
|
||||
result["videopath"] as String,
|
||||
result["tilewidth"] as int);
|
||||
}
|
||||
return _settings;
|
||||
}
|
||||
|
||||
Future<void> setSettings(SettingsT settings) async {
|
||||
await Db().db().update(
|
||||
"settings",
|
||||
{
|
||||
"domain": settings.domain,
|
||||
"token": settings.token,
|
||||
"videopath": settings.videopath,
|
||||
"tilewidth": settings.tilewidth
|
||||
},
|
||||
where: "1");
|
||||
}
|
||||
|
||||
static SettingsDB getInstance() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
SettingsDB._();
|
||||
}
|
@ -32,6 +32,8 @@ class _AddActorDialogState extends State<AddActorDialog> {
|
||||
return Text("Error");
|
||||
} else if (snapshot.hasData) {
|
||||
final data = snapshot.data! as List<Actor>;
|
||||
data.sort((a, b) =>
|
||||
a.name.toLowerCase().compareTo(b.name.toLowerCase()));
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: data
|
||||
|
@ -32,6 +32,10 @@ class _AddTagDialogState extends State<AddTagDialog> {
|
||||
return Text("Error");
|
||||
} else if (snapshot.hasData) {
|
||||
final data = snapshot.data! as List<Tag>;
|
||||
data.sort(
|
||||
(a, b) =>
|
||||
a.tagName.toLowerCase().compareTo(b.tagName.toLowerCase()),
|
||||
);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: data
|
||||
|
@ -3,7 +3,6 @@ import 'package:openmediacentermobile/navigation/settings_screen.dart';
|
||||
import '../navigation/actor_screen.dart';
|
||||
import '../navigation/categorie_screen.dart';
|
||||
import '../navigation/shuffle_screen.dart';
|
||||
import '../navigation/tv_show_screen.dart';
|
||||
import '../navigation/video_feed.dart';
|
||||
import 'drawer_context.dart';
|
||||
|
||||
@ -16,7 +15,7 @@ class DrawerPage extends StatefulWidget {
|
||||
_DrawerPageState createState() => _DrawerPageState();
|
||||
}
|
||||
|
||||
enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR, TVSHOW }
|
||||
enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR }
|
||||
|
||||
class _DrawerPageState extends State<DrawerPage> {
|
||||
Section _sec = Section.HOME;
|
||||
@ -51,11 +50,6 @@ class _DrawerPageState extends State<DrawerPage> {
|
||||
body = ActorScreen();
|
||||
title = "Actors";
|
||||
break;
|
||||
|
||||
case Section.TVSHOW:
|
||||
body = TVShowScreen();
|
||||
title = "TV Shows";
|
||||
break;
|
||||
}
|
||||
|
||||
return DrawerContext(
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/utils/feature_context.dart';
|
||||
|
||||
import 'drawer_context.dart';
|
||||
import 'drawer_page.dart';
|
||||
@ -8,62 +7,32 @@ class MyDrawer extends StatelessWidget {
|
||||
const MyDrawer({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ctx = DrawerContext.of(context);
|
||||
final featureCtx = FeatureContext.of(context);
|
||||
|
||||
return Drawer(
|
||||
Widget build(BuildContext context) => Drawer(
|
||||
backgroundColor: Color(0xff3f3f3f),
|
||||
child: ListView(children: [
|
||||
ListTile(
|
||||
title: const Text('Home'),
|
||||
leading: const Icon(Icons.home),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.HOME);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Shuffle'),
|
||||
leading: const Icon(Icons.update),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.SHUFFLE);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Categories'),
|
||||
leading: const Icon(Icons.category),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.CATEGORIE);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Actors'),
|
||||
leading: const Icon(Icons.people),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.ACTOR);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
if (featureCtx.tvShowEnabled)
|
||||
ListTile(
|
||||
title: const Text('TV Shows'),
|
||||
leading: const Icon(Icons.tv),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.TVSHOW);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Settings'),
|
||||
leading: const Icon(Icons.settings),
|
||||
onTap: () {
|
||||
ctx.onChangePage(Section.SETTING);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
SizedBox(
|
||||
height: 75,
|
||||
),
|
||||
_listelement('Home', Icons.home, Section.HOME, context),
|
||||
_listelement('Shuffle', Icons.update, Section.SHUFFLE, context),
|
||||
_listelement(
|
||||
'Categories', Icons.category, Section.CATEGORIE, context),
|
||||
_listelement('Actors', Icons.people, Section.ACTOR, context),
|
||||
_listelement('Settings', Icons.settings, Section.SETTING, context),
|
||||
]),
|
||||
);
|
||||
|
||||
Widget _listelement(
|
||||
String text, IconData icon, Section section, BuildContext context) {
|
||||
final ctx = DrawerContext.of(context);
|
||||
|
||||
return ListTile(
|
||||
title: Text(text, style: TextStyle(color: Color(0xffe9e9e9))),
|
||||
leading: Icon(icon, color: Color(0xffe9e9e9)),
|
||||
onTap: () {
|
||||
ctx.onChangePage(section);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class _LoginContainerState extends State<LoginContainer> {
|
||||
}
|
||||
|
||||
void _init() async {
|
||||
final token = await Token.getInstance().getToken();
|
||||
final token = await getToken();
|
||||
Log.i("The token value is $token");
|
||||
if (token != null) {
|
||||
setState(() {
|
||||
|
@ -3,8 +3,9 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../api/settings_api.dart';
|
||||
import '../api/token.dart';
|
||||
import '../db/settings_db.dart';
|
||||
import '../log/log.dart';
|
||||
import 'login_context.dart';
|
||||
|
||||
@ -44,12 +45,13 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
final json = jsonDecode(resp.body);
|
||||
final token = json["Token"];
|
||||
|
||||
// todo bit hacky
|
||||
Token.getInstance().setToken(token, domain, "temp", "temp");
|
||||
// we need to call this twice because we need for the loadInitialData an api token
|
||||
final initalData = await loadInitialData();
|
||||
Token.getInstance()
|
||||
.setToken(token, domain, initalData.videoPath, initalData.tvShowPath);
|
||||
SettingsT settings = await SettingsDB.getInstance().getSettings();
|
||||
settings.domain = domain;
|
||||
settings.token = token;
|
||||
SettingsDB.getInstance().setSettings(settings);
|
||||
// we need two steps here because we need an authenticated api call for the videopath
|
||||
settings.videopath = (await loadInitialData()).videoPath;
|
||||
SettingsDB.getInstance().setSettings(settings);
|
||||
LoginContext.of(context).onLoggin(true);
|
||||
|
||||
return "";
|
||||
|
@ -1,6 +1,7 @@
|
||||
import "package:dart_vlc/dart_vlc.dart";
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'db/database.dart';
|
||||
@ -10,12 +11,17 @@ import 'utils/platform.dart';
|
||||
|
||||
void main() async {
|
||||
Log.i("App init!");
|
||||
if (isDesktop()) {
|
||||
DartVLC.initialize();
|
||||
} else {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
if (!kIsWeb && !isDesktop()) {
|
||||
Log.i("init device info");
|
||||
await loadDeviceInfo();
|
||||
}
|
||||
Db().init();
|
||||
|
||||
Log.i("Mediakit initialized");
|
||||
|
||||
await Db().init();
|
||||
|
||||
runApp(Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.select): ActivateIntent(),
|
||||
|
@ -1,10 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../utils/file_formatter.dart';
|
||||
import 'package:openmediacentermobile/db/settings_db.dart';
|
||||
|
||||
import '../api/token.dart';
|
||||
import '../db/database.dart';
|
||||
import '../drawer/my_drawer.dart';
|
||||
import '../login/login_context.dart';
|
||||
import '../utils/file_formatter.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({Key? key}) : super(key: key);
|
||||
@ -24,7 +25,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
dbsize = v;
|
||||
}));
|
||||
|
||||
Token.getInstance().getToken().then((value) => setState(() {
|
||||
getToken().then((value) => setState(() {
|
||||
serverUrl = value?.domain ?? "unknown";
|
||||
}));
|
||||
}
|
||||
@ -53,7 +54,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
loginCtx.onLoggin(false);
|
||||
Token.getInstance().setToken("", "", "", "");
|
||||
SettingsDB.getInstance()
|
||||
.setSettings(SettingsT("", "", "", 0));
|
||||
Db().clear();
|
||||
},
|
||||
child: Text("Logout"))
|
||||
|
@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TVShowScreen extends StatefulWidget {
|
||||
const TVShowScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TVShowScreen> createState() => _TVShowScreenState();
|
||||
}
|
||||
|
||||
class _TVShowScreenState extends State<TVShowScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
@ -3,9 +3,9 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
|
||||
import '../utils/platform.dart';
|
||||
import '../screen_loading.dart';
|
||||
import '../types/video.dart';
|
||||
import '../utils/platform.dart';
|
||||
import 'preview_tile.dart';
|
||||
|
||||
class PreviewGrid extends StatefulWidget {
|
||||
@ -60,7 +60,7 @@ class _PreviewGridState extends State<PreviewGrid> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Error"),
|
||||
Text("Error" + snapshot.error.toString()),
|
||||
TextButton(
|
||||
onPressed: () => loadData(), child: Text("Reload page"))
|
||||
],
|
||||
@ -78,7 +78,9 @@ class _PreviewGridState extends State<PreviewGrid> {
|
||||
Widget _mainGrid(List<VideoT> data, double width) {
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
Container(
|
||||
color: Color(0xff999999),
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.headerBuilder != null) widget.headerBuilder!(this),
|
||||
data.length > 0
|
||||
@ -123,6 +125,7 @@ class _PreviewGridState extends State<PreviewGrid> {
|
||||
if (widget.footerBuilder != null) widget.footerBuilder!(this),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_previewImage != null) ..._buildPreviewImage(),
|
||||
],
|
||||
);
|
||||
|
@ -5,8 +5,8 @@ import 'package:sqflite/sqflite.dart';
|
||||
import '../api/video_api.dart';
|
||||
import '../db/database.dart';
|
||||
import '../log/log.dart';
|
||||
import '../utils/platform.dart';
|
||||
import '../types/video.dart';
|
||||
import '../utils/platform.dart';
|
||||
import '../video_screen/videoscreen.dart';
|
||||
|
||||
class PreviewTile extends StatefulWidget {
|
||||
@ -76,6 +76,7 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
);
|
||||
|
||||
// precache image to avoid loading time to render image
|
||||
if(context.mounted)
|
||||
await precacheImage(img.image, context);
|
||||
|
||||
return img;
|
||||
@ -103,18 +104,28 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
color: const Color(0xff3f3f3f),
|
||||
child: Column(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
child: image,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
Text(
|
||||
widget.dta.title,
|
||||
style: TextStyle(fontSize: isTV() ? 8 : 10.5),
|
||||
style: TextStyle(
|
||||
fontSize: isTV() ? 8 : 10.5, color: const Color(0xffe9e9e9)),
|
||||
overflow: TextOverflow.clip,
|
||||
maxLines: 1,
|
||||
),
|
||||
image
|
||||
const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
color: Color(0x6a94a6ff),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
@ -147,7 +158,9 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Image>(
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 200, minWidth: 200),
|
||||
child: FutureBuilder<Image>(
|
||||
future: _preview, // a previously-obtained Future<String> or null
|
||||
builder: (BuildContext context, AsyncSnapshot<Image> snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
@ -162,6 +175,7 @@ class _PreviewTileState extends State<PreviewTile> {
|
||||
return _buildLoader();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:openmediacentermobile/login/login_context.dart';
|
||||
import '../api/settings_api.dart';
|
||||
|
||||
// todo maybe instead of feature context a context for all settings?
|
||||
class FeatureContext extends InheritedWidget {
|
||||
const FeatureContext(this.tvShowEnabled, this.fullDeleteEnabled,
|
||||
{Key? key, required Widget child})
|
||||
: super(key: key, child: child);
|
||||
|
||||
final bool tvShowEnabled;
|
||||
final bool fullDeleteEnabled;
|
||||
|
||||
static FeatureContext of(BuildContext context) {
|
||||
final FeatureContext? result =
|
||||
context.dependOnInheritedWidgetOfExactType<FeatureContext>();
|
||||
assert(result != null, 'No LoginContext found in context');
|
||||
return result!;
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(FeatureContext old) {
|
||||
return tvShowEnabled != old.tvShowEnabled ||
|
||||
fullDeleteEnabled != old.fullDeleteEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
class FeatureContainer extends StatefulWidget {
|
||||
const FeatureContainer({Key? key, required this.child}) : super(key: key);
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<FeatureContainer> createState() => _FeatureContainerState();
|
||||
}
|
||||
|
||||
class _FeatureContainerState extends State<FeatureContainer> {
|
||||
bool? tvShowEnabled;
|
||||
bool? fullDeleteEnabled;
|
||||
bool fetcherror = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
loadInitialData()
|
||||
.then((value) => setState(
|
||||
() {
|
||||
fullDeleteEnabled = value.fullDeleteEnabled;
|
||||
tvShowEnabled = value.tvShowEnabled;
|
||||
},
|
||||
))
|
||||
.catchError((err) => setState(() => fetcherror = true));
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (fetcherror) {
|
||||
final loginctx = LoginContext.of(context);
|
||||
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child:
|
||||
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Text("Fetch error"),
|
||||
MaterialButton(
|
||||
onPressed: () => loginctx.onLoggin(false),
|
||||
child: Text("Logout"),
|
||||
)
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (tvShowEnabled == null || fullDeleteEnabled == null) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Container(
|
||||
color: Colors.white,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [CircularProgressIndicator(), Text("loading features")],
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return FeatureContext(tvShowEnabled!, fullDeleteEnabled!,
|
||||
child: widget.child);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/token.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:media_kit_video/media_kit_video.dart';
|
||||
import 'package:openmediacentermobile/db/settings_db.dart';
|
||||
|
||||
import '../api/video_api.dart';
|
||||
import '../utils/platform.dart';
|
||||
import '../screen_loading.dart';
|
||||
import '../types/video.dart';
|
||||
import '../types/video_data.dart';
|
||||
import '../utils/platform.dart';
|
||||
import 'info_view.dart';
|
||||
|
||||
import 'videoscreen_desktop.dart'
|
||||
if (dart.library.html) 'videoscreen_mobile.dart';
|
||||
import 'videoscreen_mobile.dart';
|
||||
|
||||
class VideoScreen extends StatefulWidget {
|
||||
const VideoScreen({Key? key, required this.metaData}) : super(key: key);
|
||||
final VideoT metaData;
|
||||
@ -28,16 +27,19 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
PageController _controller = PageController(
|
||||
initialPage: 0,
|
||||
);
|
||||
// Create a [Player] to control playback.
|
||||
late final player = Player();
|
||||
// Create a [VideoController] to handle video output from [Player].
|
||||
late final controller = VideoController(player);
|
||||
|
||||
String url = "";
|
||||
|
||||
void initPlayer() async {
|
||||
final videodata = await _videoData;
|
||||
|
||||
final token = await Token.getInstance().getToken();
|
||||
if (token == null) return;
|
||||
|
||||
final path = token.domain + token.videoPath + videodata.movieUrl;
|
||||
final settings = await SettingsDB.getInstance().getSettings();
|
||||
final path = settings.domain + settings.videopath + videodata.movieUrl;
|
||||
player.open(Media(path));
|
||||
|
||||
url = path;
|
||||
}
|
||||
@ -53,6 +55,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
player.dispose();
|
||||
_controller.dispose();
|
||||
_appBarTimer?.cancel();
|
||||
}
|
||||
@ -112,13 +115,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
controller: _controller,
|
||||
children: [
|
||||
Center(
|
||||
child: isDesktop()
|
||||
? VideoScreenDesktop(
|
||||
url: url,
|
||||
)
|
||||
: VideoScreenMobile(
|
||||
url: url,
|
||||
)),
|
||||
child: Video(controller: controller)),
|
||||
InfoView(
|
||||
videoId: widget.metaData.id,
|
||||
)
|
||||
@ -133,7 +130,10 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
leading: new IconButton(
|
||||
icon: new Icon(Icons.arrow_back_ios,
|
||||
color: Colors.grey),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
onPressed: () async {
|
||||
await player.stop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
backgroundColor:
|
||||
Theme.of(context).primaryColor.withOpacity(0.3),
|
||||
|
@ -1,52 +0,0 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:dart_vlc/dart_vlc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class VideoScreenDesktop extends StatefulWidget {
|
||||
const VideoScreenDesktop({Key? key, required this.url}) : super(key: key);
|
||||
final String url;
|
||||
|
||||
@override
|
||||
State<VideoScreenDesktop> createState() => _VideoScreenDesktopState();
|
||||
}
|
||||
|
||||
class _VideoScreenDesktopState extends State<VideoScreenDesktop> {
|
||||
Player _player = Player(id: Random().nextInt(0x7fffffff));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Video(
|
||||
player: _player,
|
||||
showFullscreenButton: true,
|
||||
scale: 1.0, // default
|
||||
showControls: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final media2 = Media.network(widget.url);
|
||||
|
||||
_player.open(
|
||||
media2,
|
||||
autoStart: true, // default
|
||||
);
|
||||
|
||||
RawKeyboard.instance.addListener((value) {
|
||||
if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
|
||||
_player.seek(_player.position.position! + const Duration(seconds: 5));
|
||||
} else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) {
|
||||
_player.seek(_player.position.position! + const Duration(seconds: -5));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_player.dispose();
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class VideoScreenMobile extends StatefulWidget {
|
||||
const VideoScreenMobile({Key? key, required this.url}) : super(key: key);
|
||||
final String url;
|
||||
|
||||
@override
|
||||
State<VideoScreenMobile> createState() => _VideoScreenMobileState();
|
||||
}
|
||||
|
||||
class _VideoScreenMobileState extends State<VideoScreenMobile> {
|
||||
ChewieController? _chewieController;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_chewieController == null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [CircularProgressIndicator(), Text("loading...")],
|
||||
);
|
||||
}
|
||||
return Chewie(
|
||||
controller: _chewieController!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_chewieController?.videoPlayerController.dispose();
|
||||
_chewieController?.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() async {
|
||||
final VideoPlayerController _controller =
|
||||
VideoPlayerController.network(widget.url);
|
||||
await _controller.initialize();
|
||||
|
||||
_chewieController = ChewieController(
|
||||
videoPlayerController: _controller,
|
||||
autoPlay: true,
|
||||
looping: true,
|
||||
allowFullScreen: true,
|
||||
allowMuting: true,
|
||||
allowPlaybackSpeedChanging: true,
|
||||
zoomAndPan: true);
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
}
|
@ -6,22 +6,14 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <dart_vlc/dart_vlc_plugin.h>
|
||||
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
||||
#include <screen_retriever/screen_retriever_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
|
||||
#include <media_kit_video/media_kit_video_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) dart_vlc_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "DartVlcPlugin");
|
||||
dart_vlc_plugin_register_with_registrar(dart_vlc_registrar);
|
||||
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
|
||||
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
|
||||
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
|
||||
g_autoptr(FlPluginRegistrar) window_manager_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
|
||||
window_manager_plugin_register_with_registrar(window_manager_registrar);
|
||||
g_autoptr(FlPluginRegistrar) media_kit_libs_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitLibsLinuxPlugin");
|
||||
media_kit_libs_linux_plugin_register_with_registrar(media_kit_libs_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) media_kit_video_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitVideoPlugin");
|
||||
media_kit_video_plugin_register_with_registrar(media_kit_video_registrar);
|
||||
}
|
||||
|
@ -3,13 +3,12 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
dart_vlc
|
||||
flutter_secure_storage_linux
|
||||
screen_retriever
|
||||
window_manager
|
||||
media_kit_libs_linux
|
||||
media_kit_video
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
media_kit_native_event_loop
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
758
pubspec.lock
758
pubspec.lock
File diff suppressed because it is too large
Load Diff
16
pubspec.yaml
16
pubspec.yaml
@ -34,17 +34,23 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
flutter_secure_storage: ^6.0.0
|
||||
logger: ^1.1.0
|
||||
http: ^0.13.4
|
||||
flutter_staggered_grid_view: ^0.6.1
|
||||
dart_vlc: ^0.3.0
|
||||
device_info_plus: ^4.0.0
|
||||
video_player: ^2.3.0
|
||||
chewie: ^1.3.2
|
||||
device_info_plus: ^8.0.0
|
||||
sqflite: ^2.0.3+1
|
||||
path: ^1.8.1
|
||||
sqflite_common_ffi: ^2.1.1+1
|
||||
sqflite_common_ffi_web: '^0.3.6'
|
||||
|
||||
media_kit: ^1.0.2 # Primary package.
|
||||
|
||||
media_kit_video: ^1.0.2 # For video rendering.
|
||||
|
||||
media_kit_native_event_loop: ^1.0.6 # Support for higher number of concurrent instances & better performance.
|
||||
|
||||
media_kit_libs_android_video: ^1.1.1 # Android package for video native libraries.
|
||||
media_kit_libs_linux: ^1.0.2 # GNU/Linux dependency package.
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user