Merge upstream freezer source

This commit is contained in:
Pato05 2021-04-07 10:57:17 +02:00
commit 4031148faf
6 changed files with 142 additions and 37 deletions

View file

@ -1,5 +1,6 @@
import 'package:freezer/api/deezer.dart'; import 'package:freezer/api/deezer.dart';
import 'package:freezer/api/importer.dart'; import 'package:freezer/api/importer.dart';
import 'package:freezer/settings.dart';
import 'package:html/parser.dart'; import 'package:html/parser.dart';
import 'package:html/dom.dart' as dom; import 'package:html/dom.dart' as dom;
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
@ -141,6 +142,24 @@ class SpotifyAPIWrapper {
SpotifyApi spotify; SpotifyApi spotify;
User me; User me;
//Try authorize with saved credentials
Future<bool> trySaved() async {
print(settings.spotifyCredentials);
if (settings.spotifyClientId == null || settings.spotifyClientSecret == null || settings.spotifyCredentials == null) return false;
final credentials = SpotifyApiCredentials(
settings.spotifyClientId,
settings.spotifyClientSecret,
accessToken: settings.spotifyCredentials.accessToken,
refreshToken: settings.spotifyCredentials.refreshToken,
scopes: settings.spotifyCredentials.scopes,
expiration: settings.spotifyCredentials.expiration
);
spotify = SpotifyApi(credentials);
me = await spotify.me.get();
await _save();
return true;
}
Future authorize(String clientId, String clientSecret) async { Future authorize(String clientId, String clientSecret) async {
//Spotify //Spotify
SpotifyApiCredentials credentials = SpotifyApiCredentials(clientId, clientSecret); SpotifyApiCredentials credentials = SpotifyApiCredentials(clientId, clientSecret);
@ -171,6 +190,24 @@ class SpotifyAPIWrapper {
//Create spotify //Create spotify
spotify = SpotifyApi.fromAuthCodeGrant(grant, responseUri); spotify = SpotifyApi.fromAuthCodeGrant(grant, responseUri);
me = await spotify.me.get(); me = await spotify.me.get();
//Save
await _save();
}
Future _save() async {
//Save credentials
final spotifyCredentials = await spotify.getCredentials();
final saveCredentials = SpotifyCredentialsSave(
accessToken: spotifyCredentials.accessToken,
refreshToken: spotifyCredentials.refreshToken,
scopes: spotifyCredentials.scopes,
expiration: spotifyCredentials.expiration
);
settings.spotifyClientSecret = spotifyCredentials.clientId;
settings.spotifyClientSecret = spotifyCredentials.clientSecret;
settings.spotifyCredentials = saveCredentials;
await settings.save();
} }
//Cancel authorization //Cancel authorization

View file

@ -358,42 +358,47 @@ class _MainScreenState extends State<MainScreen>
focusNode: FocusNode(), focusNode: FocusNode(),
onKey: _handleKey(navigationBarFocusNode, screenFocusNode), onKey: _handleKey(navigationBarFocusNode, screenFocusNode),
child: Scaffold( child: Scaffold(
bottomNavigationBar: FocusScope( bottomNavigationBar:
node: navigationBarFocusNode, FocusScope(
child: Column( node: navigationBarFocusNode,
mainAxisSize: MainAxisSize.min, child: Column(
children: <Widget>[ mainAxisSize: MainAxisSize.min,
PlayerBar(), children: <Widget>[
BottomNavigationBar( PlayerBar(),
backgroundColor: Theme.of(context).bottomAppBarColor, BottomNavigationBar(
currentIndex: _selected, backgroundColor: Theme.of(context).bottomAppBarColor,
onTap: (int s) async { currentIndex: _selected,
//Pop all routes until home screen onTap: (int s) async {
while (navigatorKey.currentState.canPop()) { //Pop all routes until home screen
await navigatorKey.currentState.maybePop(); while (navigatorKey.currentState.canPop()) {
} await navigatorKey.currentState.maybePop();
}
await navigatorKey.currentState.maybePop(); await navigatorKey.currentState.maybePop();
setState(() { setState(() {
_selected = s; _selected = s;
}); });
//Fix statusbar //Fix statusbar
SystemChrome.setSystemUIOverlayStyle( SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
SystemUiOverlayStyle( statusBarColor: Colors.transparent,
statusBarColor: Colors.transparent)); ));
}, },
selectedItemColor: Theme.of(context).primaryColor, selectedItemColor: Theme.of(context).primaryColor,
items: <BottomNavigationBarItem>[ items: <BottomNavigationBarItem>[
BottomNavigationBarItem( BottomNavigationBarItem(
icon: Icon(Icons.home), label: 'Home'.i18n), icon: Icon(Icons.home),
BottomNavigationBarItem( label: 'Home'.i18n),
icon: Icon(Icons.search), BottomNavigationBarItem(
label: 'Search'.i18n, icon: Icon(Icons.search),
), label: 'Search'.i18n,
BottomNavigationBarItem( ),
icon: Icon(Icons.library_music), BottomNavigationBarItem(
label: 'Library'.i18n) icon: Icon(Icons.library_music),
label: 'Library'.i18n
)
],
)
], ],
) )
], ],

View file

@ -144,6 +144,8 @@ class Settings {
String spotifyClientId; String spotifyClientId;
@JsonKey(defaultValue: null) @JsonKey(defaultValue: null)
String spotifyClientSecret; String spotifyClientSecret;
@JsonKey(defaultValue: null)
SpotifyCredentialsSave spotifyCredentials;
Settings({this.downloadPath, this.arl}); Settings({this.downloadPath, this.arl});
@ -344,4 +346,27 @@ class Settings {
enum AudioQuality { MP3_128, MP3_320, FLAC, ASK } enum AudioQuality { MP3_128, MP3_320, FLAC, ASK }
<<<<<<< HEAD
enum Themes { Light, Dark, Deezer, Black } enum Themes { Light, Dark, Deezer, Black }
=======
enum Themes {
Light,
Dark,
Deezer,
Black
}
@JsonSerializable()
class SpotifyCredentialsSave {
String accessToken;
String refreshToken;
List<String> scopes;
DateTime expiration;
SpotifyCredentialsSave({this.accessToken, this.refreshToken, this.scopes, this.expiration});
//JSON
factory SpotifyCredentialsSave.fromJson(Map<String, dynamic> json) => _$SpotifyCredentialsSaveFromJson(json);
Map<String, dynamic> toJson() => _$SpotifyCredentialsSaveToJson(this);
}
>>>>>>> main/master

View file

@ -78,7 +78,11 @@ Settings _$SettingsFromJson(Map<String, dynamic> json) {
..lastFMUsername = json['lastFMUsername'] as String ..lastFMUsername = json['lastFMUsername'] as String
..lastFMPassword = json['lastFMPassword'] as String ..lastFMPassword = json['lastFMPassword'] as String
..spotifyClientId = json['spotifyClientId'] as String ..spotifyClientId = json['spotifyClientId'] as String
..spotifyClientSecret = json['spotifyClientSecret'] as String; ..spotifyClientSecret = json['spotifyClientSecret'] as String
..spotifyCredentials = json['spotifyCredentials'] == null
? null
: SpotifyCredentialsSave.fromJson(
json['spotifyCredentials'] as Map<String, dynamic>);
} }
Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{ Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
@ -123,6 +127,7 @@ Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
'lastFMPassword': instance.lastFMPassword, 'lastFMPassword': instance.lastFMPassword,
'spotifyClientId': instance.spotifyClientId, 'spotifyClientId': instance.spotifyClientId,
'spotifyClientSecret': instance.spotifyClientSecret, 'spotifyClientSecret': instance.spotifyClientSecret,
'spotifyCredentials': instance.spotifyCredentials,
}; };
T _$enumDecode<T>( T _$enumDecode<T>(
@ -170,3 +175,24 @@ const _$ThemesEnumMap = {
Themes.Deezer: 'Deezer', Themes.Deezer: 'Deezer',
Themes.Black: 'Black', Themes.Black: 'Black',
}; };
SpotifyCredentialsSave _$SpotifyCredentialsSaveFromJson(
Map<String, dynamic> json) {
return SpotifyCredentialsSave(
accessToken: json['accessToken'] as String,
refreshToken: json['refreshToken'] as String,
scopes: (json['scopes'] as List)?.map((e) => e as String)?.toList(),
expiration: json['expiration'] == null
? null
: DateTime.parse(json['expiration'] as String),
);
}
Map<String, dynamic> _$SpotifyCredentialsSaveToJson(
SpotifyCredentialsSave instance) =>
<String, dynamic>{
'accessToken': instance.accessToken,
'refreshToken': instance.refreshToken,
'scopes': instance.scopes,
'expiration': instance.expiration?.toIso8601String(),
};

View file

@ -326,6 +326,18 @@ class _SpotifyImporterV2State extends State<SpotifyImporterV2> {
void initState() { void initState() {
_clientId = settings.spotifyClientId; _clientId = settings.spotifyClientId;
_clientSecret = settings.spotifyClientSecret; _clientSecret = settings.spotifyClientSecret;
//Try saved
spotify = SpotifyAPIWrapper();
spotify.trySaved().then((r) {
if (r) {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => SpotifyImporterV2Main(spotify)
));
}
});
super.initState(); super.initState();
} }

View file

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.6.10+1 version: 0.6.11+1
environment: environment:
sdk: ">=2.8.0 <3.0.0" sdk: ">=2.8.0 <3.0.0"