import 'package:audio_service/audio_service.dart'; import 'package:freezer/api/deezer.dart'; import 'package:freezer/api/definitions.dart'; import 'package:freezer/api/player.dart'; import 'package:freezer/translations.i18n.dart'; class AndroidAuto { //Prefix for "playable" MediaItem static const prefix = '_aa_'; //Get media items for parent id Future> getScreen(String parentId) async { print(parentId); //Homescreen if (parentId == 'root' || parentId == null) return homeScreen(); //Playlists screen if (parentId == 'playlists') { //Fetch List playlists = await deezerAPI.getPlaylists(); List out = playlists.map((p) => MediaItem( id: '${prefix}playlist${p.id}', displayTitle: p.title, displaySubtitle: p.trackCount.toString() + ' ' + 'Tracks'.i18n, playable: true, artUri: p.image.thumb )).toList(); return out; } //Albums screen if (parentId == 'albums') { List albums = await deezerAPI.getAlbums(); List out = albums.map((a) => MediaItem( id: '${prefix}album${a.id}', displayTitle: a.title, displaySubtitle: a.artistString, playable: true, artUri: a.art.thumb, )).toList(); return out; } //Artists screen if (parentId == 'artists') { List artists = await deezerAPI.getArtists(); List out = artists.map((a) => MediaItem( id: 'albums${a.id}', displayTitle: a.name, playable: false, artUri: a.picture.thumb )).toList(); return out; } //Artist screen (albums, etc) if (parentId.startsWith('albums')) { List albums = await deezerAPI.discographyPage(parentId.replaceFirst('albums', '')); List out = albums.map((a) => MediaItem( id: '${prefix}album${a.id}', displayTitle: a.title, displaySubtitle: a.artistString, playable: true, artUri: a.art.thumb )).toList(); return out; } //Homescreen if (parentId == 'homescreen') { HomePage hp = await deezerAPI.homePage(); List out = []; for (HomePageSection section in hp.sections) { for (int i=0; i homeScreen() { return [ MediaItem( id: '${prefix}flow', displayTitle: 'Flow'.i18n, playable: true ), MediaItem( id: 'homescreen', displayTitle: 'Home'.i18n, playable: false, ), MediaItem( id: '${prefix}tracks', displayTitle: 'Loved tracks'.i18n, playable: true, ), MediaItem( id: 'playlists', displayTitle: 'Playlists'.i18n, playable: false, ), MediaItem( id: 'albums', displayTitle: 'Albums'.i18n, playable: false, ), MediaItem( id: 'artists', displayTitle: 'Artists'.i18n, playable: false, ), ]; } }