From 4b3d264e2a99ddcdcc5660f414ea08fbbd62b14b Mon Sep 17 00:00:00 2001 From: exttex Date: Thu, 16 Jul 2020 22:25:30 +0200 Subject: [PATCH] Logout option --- lib/main.dart | 15 +++++++ lib/ui/cached_image.dart | 4 +- lib/ui/home_screen.dart | 86 +++++++++++++++++++++++-------------- lib/ui/player_screen.dart | 6 +-- lib/ui/settings_screen.dart | 39 ++++++++++++++++- lib/ui/tiles.dart | 1 + 6 files changed, 113 insertions(+), 38 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f1a65f0..42e61b6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:custom_navigator/custom_navigator.dart'; import 'package:audio_service/audio_service.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:freezer/ui/library.dart'; import 'package:freezer/ui/login_screen.dart'; import 'package:freezer/ui/search.dart'; @@ -14,7 +15,9 @@ import 'api/download.dart'; import 'api/player.dart'; import 'ui/home_screen.dart'; + Function updateTheme; +Function logOut; GlobalKey mainNavigatorKey = GlobalKey(); GlobalKey navigatorKey; @@ -90,9 +93,21 @@ class _LoginMainWrapperState extends State { if (b) setState(() => settings.offlineMode = false); }); } + //Global logOut function + logOut = _logOut; + super.initState(); } + Future _logOut() async { + setState(() { + settings.arl = null; + settings.offlineMode = true; + deezerAPI = new DeezerAPI(); + }); + await settings.save(); + } + @override Widget build(BuildContext context) { if (settings.arl == null) diff --git a/lib/ui/cached_image.dart b/lib/ui/cached_image.dart index 3863325..57be016 100644 --- a/lib/ui/cached_image.dart +++ b/lib/ui/cached_image.dart @@ -141,6 +141,8 @@ class _CachedImageState extends State { //Load image and fade void _load() async { + if (_prevUrl == widget.url) return; + ImageProvider image = await _getImage(); if (_disposed) return; setState(() { @@ -164,7 +166,6 @@ class _CachedImageState extends State { @override void didUpdateWidget(CachedImage oldWidget) { - if (_prevUrl == widget.url) return; _load(); super.didUpdateWidget(oldWidget); } @@ -183,6 +184,7 @@ class _CachedImageState extends State { height: widget.height, width: widget.width, ), + AnimatedOpacity( duration: Duration(milliseconds: 250), opacity: _opacity, diff --git a/lib/ui/home_screen.dart b/lib/ui/home_screen.dart index a9b3e33..61fa8f5 100644 --- a/lib/ui/home_screen.dart +++ b/lib/ui/home_screen.dart @@ -11,14 +11,31 @@ import '../settings.dart'; class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { + //TODO: SingleChildScrollView vs ListView speed/perf + return SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: FreezerTitle(), + ), + Flexible(child: HomePageScreen(),) + ], + ), + ); + /* return ListView( children: [ - Container(height: 16.0,), - FreezerTitle(), - Container(height: 16.0,), + Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: FreezerTitle(), + ), HomePageScreen() ], ); + + */ } } @@ -124,38 +141,40 @@ class _HomePageScreenState extends State { return Center(child: CircularProgressIndicator(),); if (_error) return ErrorScreen(); - return SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: List.generate(_homePage.sections.length, (i) { - HomePageSection section = _homePage.sections[i]; - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - child: Text( - section.title, - textAlign: TextAlign.left, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle(fontSize: 24.0), - ), - padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0) + return ListView.builder( + shrinkWrap: true, + addAutomaticKeepAlives: true, + physics: NeverScrollableScrollPhysics(), + itemCount: _homePage.sections.length, + itemBuilder: (context, i) { + HomePageSection section = _homePage.sections[i]; + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + child: Text( + section.title, + textAlign: TextAlign.left, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 24.0), ), - SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: List.generate(section.items.length, (i) { - HomePageItem item = section.items[i]; - return HomePageItemWidget(item); - }), - ), + padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0) + ), + + SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: List.generate(section.items.length, (i) { + HomePageItem item = section.items[i]; + return HomePageItemWidget(item); + }), ), - ], - ); - }), - ), + ), + ], + ); + }, ); } } @@ -168,6 +187,7 @@ class HomePageItemWidget extends StatelessWidget { @override Widget build(BuildContext context) { + switch (item.type) { case HomePageItemType.SMARTTRACKLIST: return SmartTrackListTile( diff --git a/lib/ui/player_screen.dart b/lib/ui/player_screen.dart index 59f095e..a31d3fe 100644 --- a/lib/ui/player_screen.dart +++ b/lib/ui/player_screen.dart @@ -169,11 +169,11 @@ class _PlayerScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( - padding: EdgeInsets.fromLTRB(28, 16, 28, 0), + padding: EdgeInsets.fromLTRB(28, 12, 28, 4), child: PlayerScreenTopRow() ), Padding( - padding: EdgeInsets.fromLTRB(16, 8, 16, 8), + padding: EdgeInsets.fromLTRB(16, 0, 16, 0), child: Container( height: 360, child: Stack( @@ -229,7 +229,7 @@ class _PlayerScreenState extends State { ), //Container(height: 8.0,), Padding( - padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0), + padding: EdgeInsets.symmetric(vertical: 0, horizontal: 16.0), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, diff --git a/lib/ui/settings_screen.dart b/lib/ui/settings_screen.dart index 21aac76..f72d62d 100644 --- a/lib/ui/settings_screen.dart +++ b/lib/ui/settings_screen.dart @@ -1,13 +1,14 @@ +import 'package:audio_service/audio_service.dart'; import 'package:country_pickers/country.dart'; import 'package:country_pickers/country_picker_dialog.dart'; import 'package:filesize/filesize.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_material_color_picker/flutter_material_color_picker.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:freezer/api/deezer.dart'; import 'package:freezer/ui/error.dart'; -import 'package:freezer/ui/player_bar.dart'; import 'package:language_pickers/language_pickers.dart'; import 'package:language_pickers/languages.dart'; import 'package:package_info/package_info.dart'; @@ -501,6 +502,42 @@ class _GeneralSettingsState extends State { settings.save(); }, ), + ), + ListTile( + title: Text('Log out', style: TextStyle(color: Colors.red),), + leading: Icon(Icons.exit_to_app), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('Log out'), + content: Text('Due to plugin incompatibility, login using browser is unavailable without restart.'), + actions: [ + FlatButton( + child: Text('Cancel'), + onPressed: () => Navigator.of(context).pop(), + ), + FlatButton( + child: Text('(ARL ONLY) Continue'), + onPressed: () { + logOut(); + Navigator.of(context).pop(); + }, + ), + FlatButton( + child: Text('Log out & Exit'), + onPressed: () async { + try {AudioService.stop();} catch (e) {} + await logOut(); + SystemNavigator.pop(); + }, + ) + ], + ); + } + ); + } ) ], ), diff --git a/lib/ui/tiles.dart b/lib/ui/tiles.dart index 5248d2a..c511f4c 100644 --- a/lib/ui/tiles.dart +++ b/lib/ui/tiles.dart @@ -239,6 +239,7 @@ class PlaylistCardTile extends StatelessWidget { } } + class SmartTrackListTile extends StatelessWidget { final SmartTrackList smartTrackList;