diff --git a/lib/DrawerPage.dart b/lib/DrawerPage.dart deleted file mode 100644 index 1fc50f6..0000000 --- a/lib/DrawerPage.dart +++ /dev/null @@ -1,142 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:openmediacentermobile/navigation/settings_screen.dart'; -import 'navigation/actor_screen.dart'; -import 'navigation/categorie_screen.dart'; -import 'navigation/shufflescreen.dart'; -import 'navigation/video_feed.dart'; - -class DrawerPage extends StatefulWidget { - const DrawerPage({Key? key, required this.title}) : super(key: key); - - final String title; - - @override - _DrawerPageState createState() => _DrawerPageState(); -} - -enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR } - -class _DrawerPageState extends State { - Section _sec = Section.HOME; - - @override - Widget build(BuildContext context) { - Widget body; - String title; - - switch (_sec) { - case Section.HOME: - body = const VideoFeed(); - title = widget.title; - break; - - case Section.SHUFFLE: - body = const ShuffleScreen(); - title = "Shuffle"; - break; - - case Section.SETTING: - body = SettingsScreen(); - title = "Settings"; - break; - - case Section.CATEGORIE: - body = CategorieScreen(); - title = "Categories"; - break; - - case Section.ACTOR: - body = ActorScreen(); - title = "Actors"; - break; - } - - return DrawerContext( - child: body, - onChangePage: (newPage) { - setState(() { - _sec = newPage; - }); - }, - routeName: title, - ); - } -} - -class MyDrawer extends StatelessWidget { - const MyDrawer({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - final ctx = DrawerContext.of(context); - - return Drawer( - 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); - }, - ), - ListTile( - title: const Text('Settings'), - leading: const Icon(Icons.settings), - onTap: () { - ctx.onChangePage(Section.SETTING); - Navigator.pop(context); - }, - ), - ]), - ); - } -} - -class DrawerContext extends InheritedWidget { - const DrawerContext({ - Key? key, - required Widget child, - required this.onChangePage, - required this.routeName, - }) : super(key: key, child: child); - - final void Function(Section) onChangePage; - final String routeName; - - static DrawerContext of(BuildContext context) { - final DrawerContext? result = - context.dependOnInheritedWidgetOfExactType(); - assert(result != null, 'No DrawerContext found in context'); - return result!; - } - - @override - bool updateShouldNotify(covariant InheritedWidget oldWidget) { - return false; - } -} diff --git a/lib/app.dart b/lib/app.dart index 205b2da..9988eb3 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:openmediacentermobile/log/log.dart'; import 'package:openmediacentermobile/login/login_screen.dart'; -import 'DrawerPage.dart'; +import 'drawer/drawer_page.dart'; import 'login/logincontext.dart'; class AppScrollBehavior extends MaterialScrollBehavior { diff --git a/lib/drawer/drawer_context.dart b/lib/drawer/drawer_context.dart new file mode 100644 index 0000000..48e5658 --- /dev/null +++ b/lib/drawer/drawer_context.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; + +import 'drawer_page.dart'; + +class DrawerContext extends InheritedWidget { + const DrawerContext({ + Key? key, + required Widget child, + required this.onChangePage, + required this.routeName, + }) : super(key: key, child: child); + + final void Function(Section) onChangePage; + final String routeName; + + static DrawerContext of(BuildContext context) { + final DrawerContext? result = + context.dependOnInheritedWidgetOfExactType(); + assert(result != null, 'No DrawerContext found in context'); + return result!; + } + + @override + bool updateShouldNotify(covariant InheritedWidget oldWidget) { + return false; + } +} diff --git a/lib/drawer/drawer_page.dart b/lib/drawer/drawer_page.dart new file mode 100644 index 0000000..97b9706 --- /dev/null +++ b/lib/drawer/drawer_page.dart @@ -0,0 +1,65 @@ +import 'package:flutter/material.dart'; +import 'package:openmediacentermobile/navigation/settings_screen.dart'; +import '../navigation/actor_screen.dart'; +import '../navigation/categorie_screen.dart'; +import '../navigation/shufflescreen.dart'; +import '../navigation/video_feed.dart'; +import 'drawer_context.dart'; + +class DrawerPage extends StatefulWidget { + const DrawerPage({Key? key, required this.title}) : super(key: key); + + final String title; + + @override + _DrawerPageState createState() => _DrawerPageState(); +} + +enum Section { HOME, SHUFFLE, SETTING, CATEGORIE, ACTOR } + +class _DrawerPageState extends State { + Section _sec = Section.HOME; + + @override + Widget build(BuildContext context) { + Widget body; + String title; + + switch (_sec) { + case Section.HOME: + body = const VideoFeed(); + title = widget.title; + break; + + case Section.SHUFFLE: + body = const ShuffleScreen(); + title = "Shuffle"; + break; + + case Section.SETTING: + body = SettingsScreen(); + title = "Settings"; + break; + + case Section.CATEGORIE: + body = CategorieScreen(); + title = "Categories"; + break; + + case Section.ACTOR: + body = ActorScreen(); + title = "Actors"; + break; + } + + return DrawerContext( + child: body, + onChangePage: (newPage) { + setState(() { + _sec = newPage; + }); + }, + routeName: title, + ); + } +} diff --git a/lib/drawer/my_drawer.dart b/lib/drawer/my_drawer.dart new file mode 100644 index 0000000..1544d13 --- /dev/null +++ b/lib/drawer/my_drawer.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; + +import 'drawer_context.dart'; +import 'drawer_page.dart'; + +class MyDrawer extends StatelessWidget { + const MyDrawer({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final ctx = DrawerContext.of(context); + + return Drawer( + 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); + }, + ), + ListTile( + title: const Text('Settings'), + leading: const Icon(Icons.settings), + onTap: () { + ctx.onChangePage(Section.SETTING); + Navigator.pop(context); + }, + ), + ]), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index d1d2bfc..8ec9872 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,7 +6,7 @@ import 'app.dart'; import 'db/database.dart'; import 'log/log.dart'; import 'login/logincontext.dart'; -import 'platform.dart'; +import 'utils/platform.dart'; void main() async { Log.i("App init!"); diff --git a/lib/navigation/actor_screen.dart b/lib/navigation/actor_screen.dart index f1aadd2..87b386d 100644 --- a/lib/navigation/actor_screen.dart +++ b/lib/navigation/actor_screen.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:openmediacentermobile/types/actor.dart'; import 'package:openmediacentermobile/preview/actor_tile.dart'; -import '../DrawerPage.dart'; import '../api/actor_api.dart'; +import '../drawer/my_drawer.dart'; import '../screen_loading.dart'; class ActorScreen extends StatefulWidget { diff --git a/lib/navigation/categorie_screen.dart b/lib/navigation/categorie_screen.dart index 7a34e55..603e519 100644 --- a/lib/navigation/categorie_screen.dart +++ b/lib/navigation/categorie_screen.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:openmediacentermobile/preview/tag_tile.dart'; -import '../DrawerPage.dart'; +import '../drawer/my_drawer.dart'; import '../screen_loading.dart'; import '../api/api.dart'; diff --git a/lib/navigation/settings_screen.dart b/lib/navigation/settings_screen.dart index b9a9000..8d7e6e3 100644 --- a/lib/navigation/settings_screen.dart +++ b/lib/navigation/settings_screen.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:openmediacentermobile/utils/FileFormatter.dart'; -import '../DrawerPage.dart'; import '../api/token.dart'; import '../db/database.dart'; +import '../drawer/my_drawer.dart'; import '../login/logincontext.dart'; class SettingsScreen extends StatefulWidget { diff --git a/lib/navigation/shufflescreen.dart b/lib/navigation/shufflescreen.dart index 663505e..45b9df2 100644 --- a/lib/navigation/shufflescreen.dart +++ b/lib/navigation/shufflescreen.dart @@ -2,10 +2,10 @@ import 'dart:convert'; import 'dart:math'; import 'package:flutter/material.dart'; -import '../DrawerPage.dart'; +import '../drawer/my_drawer.dart'; import '../preview/preview_grid.dart'; import '../api/api.dart'; -import '../platform.dart'; +import '../utils/platform.dart'; import '../types/video.dart'; class ShuffleScreen extends StatefulWidget { diff --git a/lib/navigation/video_feed.dart b/lib/navigation/video_feed.dart index 3c522f6..8e3266d 100644 --- a/lib/navigation/video_feed.dart +++ b/lib/navigation/video_feed.dart @@ -1,9 +1,9 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:openmediacentermobile/DrawerPage.dart'; import '../api/api.dart'; +import '../drawer/my_drawer.dart'; import '../preview/preview_grid.dart'; import '../types/tag.dart'; import '../types/video.dart'; diff --git a/lib/preview/actor_tile.dart b/lib/preview/actor_tile.dart index 5cd0b92..4f3b06e 100644 --- a/lib/preview/actor_tile.dart +++ b/lib/preview/actor_tile.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:openmediacentermobile/preview/actor_feed.dart'; -import '../platform.dart'; +import '../utils/platform.dart'; import '../types/actor.dart'; class ActorTile extends StatefulWidget { diff --git a/lib/preview/preview_grid.dart b/lib/preview/preview_grid.dart index 87dd7b6..6246fcb 100644 --- a/lib/preview/preview_grid.dart +++ b/lib/preview/preview_grid.dart @@ -3,7 +3,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; -import '../platform.dart'; +import '../utils/platform.dart'; import '../screen_loading.dart'; import '../types/video.dart'; import 'preview_tile.dart'; diff --git a/lib/preview/preview_tile.dart b/lib/preview/preview_tile.dart index 1f3b007..d5cff11 100644 --- a/lib/preview/preview_tile.dart +++ b/lib/preview/preview_tile.dart @@ -8,7 +8,7 @@ import 'package:sqflite/sqflite.dart'; import '../api/api.dart'; import '../db/database.dart'; import '../log/log.dart'; -import '../platform.dart'; +import '../utils/platform.dart'; import '../types/video.dart'; import '../video_screen/videoscreen.dart'; diff --git a/lib/platform.dart b/lib/utils/platform.dart similarity index 100% rename from lib/platform.dart rename to lib/utils/platform.dart diff --git a/lib/video_screen/videoscreen.dart b/lib/video_screen/videoscreen.dart index 1576399..2c242ea 100644 --- a/lib/video_screen/videoscreen.dart +++ b/lib/video_screen/videoscreen.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import '../api/token.dart'; import '../api/video_api.dart'; -import '../platform.dart'; +import '../utils/platform.dart'; import '../screen_loading.dart'; import '../types/video.dart'; import '../types/video_data.dart';