Skip to content

Commit

Permalink
Changed track view layout
Browse files Browse the repository at this point in the history
Also fixed Spotify content linking, made calendar page start at bottom, and removed unneeded padding on daily tracks from calendar view
  • Loading branch information
aceeedev committed Aug 1, 2023
1 parent 21f6808 commit 2881a2a
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 78 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<package android:name="com.spotify.music"/>
</queries>
</manifest>
3 changes: 2 additions & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
</array>
<key>CFBundleURLSchemes</key>
<array>
<string>com.example.daily-spotify</string>
<string>com.example.daily-spotify</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>spotify</string>
</array>
</dict>
</plist>
17 changes: 15 additions & 2 deletions lib/pages/calendar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,25 @@ class _CalendarPageState extends State<CalendarPage> {
}
}

// flip daily tracks and months since ListView starts at bottom
// and is reversed
dailyTracksByMonth = dailyTracksByMonth.reversed.toList();
monthsBetweenFirstDailyTrackAndNow =
monthsBetweenFirstDailyTrackAndNow.reversed.toList();

return ListView.builder(
reverse: true,
itemCount: monthsBetweenFirstDailyTrackAndNow.length,
itemBuilder: (context, index) => Column(
children: [
Padding(
padding:
EdgeInsets.only(top: index != 0 ? 12.0 : 0),
padding: EdgeInsets.only(
top: index !=
monthsBetweenFirstDailyTrackAndNow
.length -
1
? 16.0
: 0.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
Expand Down Expand Up @@ -172,6 +184,7 @@ class _MonthCalendarState extends State<MonthCalendar> {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CustomScaffold(
body: Frame(
customPadding: const EdgeInsets.all(0.0),
showLogo: false,
child: TrackView(
header: Row(
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
static const double iconSize = 30.0;

@override
Widget build(BuildContext context) {
return CustomScaffold(
body: Frame(
customPadding: const EdgeInsets.only(top: 10.0, bottom: 10.0),
customPadding: const EdgeInsets.all(0.0),
showLogo: false,
child: FutureBuilder(
builder: (context, snapshot) {
Expand All @@ -45,8 +47,8 @@ class _HomePageState extends State<HomePage> {

return TrackView(
header: Padding(
padding:
const EdgeInsets.only(right: 10.0, left: 10.0),
padding: const EdgeInsets.only(
right: 10.0, left: 10.0, top: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand All @@ -58,6 +60,7 @@ class _HomePageState extends State<HomePage> {
icon: Icon(
Icons.calendar_month,
color: Styles().mainColor,
size: iconSize,
),
),
const BrandText(),
Expand All @@ -69,6 +72,7 @@ class _HomePageState extends State<HomePage> {
icon: Icon(
Icons.settings,
color: Styles().mainColor,
size: iconSize,
),
),
],
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class _SettingsPageState extends State<SettingsPage> {
'Settings',
style: Styles().largeText,
),
actions: [
// TODO: Add donations through in-app purchases <3
/*actions: [
TextButton.icon(
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const DonationPage())),
label: const Text('Donate'),
icon: const Icon(Icons.favorite_border))
],
],*/
backgroundColor: Styles().backgroundColor,
leading: BackButton(color: Styles().mainColor),
),
Expand Down
165 changes: 95 additions & 70 deletions lib/widgets/track_view_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:appcheck/appcheck.dart';
import 'package:share_plus/share_plus.dart';
import 'package:daily_spotify/styles.dart';
import 'package:daily_spotify/backend/spotify_api/spotify_api.dart';
Expand All @@ -20,6 +22,8 @@ class TrackView extends StatelessWidget {
final Track track;
final Color averageColorOfImage;

static const List<int> flexValues = [4, 50, 20, 10];

@override
Widget build(BuildContext context) {
return Center(
Expand All @@ -32,7 +36,7 @@ class TrackView extends StatelessWidget {
0.0,
0.3,
0.4,
0.8,
0.75,
],
colors: [
Styles().backgroundColor,
Expand All @@ -46,81 +50,101 @@ class TrackView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
header,
Padding(
padding: const EdgeInsets.only(bottom: 75.0),
child: Text(
'Your song of ${DateFormat('MMM d').format(dailyTrack.date)}',
style: Styles().largeText)),
Image.network(
track.images.first.url,
width: track.images.first.width.toDouble() / 2,
height: track.images.first.height.toDouble() / 2,
Expanded(
flex: flexValues[0],
child: Text(
'Your song of ${DateFormat('MMM d').format(dailyTrack.date)}',
style: Styles().largeText),
),
Text(
track.name,
style: Styles().titleText,
textAlign: TextAlign.center,
Expanded(
flex: flexValues[1],
child: Image.network(
track.images.first.url,
width: track.images.first.width.toDouble() / 2,
height: track.images.first.height.toDouble() / 2,
),
),
Text(
track.getArtists(),
style: Styles().subtitleText,
textAlign: TextAlign.center,
Expanded(
flex: flexValues[2],
child: Column(
children: [
Text(
track.name,
style: Styles().titleText,
textAlign: TextAlign.center,
),
Text(
track.getArtists(),
style: Styles().subtitleText,
textAlign: TextAlign.center,
),
],
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
flex: flexValues[3],
child: ElevatedButton(
onPressed: () async {
try {
String spotiftyAppUri = '';
if (Platform.isAndroid) {
spotiftyAppUri = 'com.spotify.music';
} else if (Platform.isIOS) {
spotiftyAppUri = 'spotify://';
}

// see if Spotifty is installed
await AppCheck.checkAvailability(spotiftyAppUri);

await openSong(track.uri);
} catch (e) {
await openSong(track.spotifyHref);
}
},
style: Styles().unselectedElevatedButtonStyle.copyWith(
fixedSize:
MaterialStateProperty.all<Size>(const Size(150, 25))),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () async => await openSong(track.spotifyHref),
style: Styles().unselectedElevatedButtonStyle,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Open in ',
style: Styles().subtitleText,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(left: 6.0),
child: Image.asset(
'assets/Spotify_Icon_RGB_Green.png',
width: 32,
height: 32),
),
],
),
Text(
'Open in ',
style: Styles().subtitleText,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(left: 6.0),
child: Image.asset('assets/Spotify_Icon_RGB_Green.png',
width: 32, height: 32),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 72.0),
child: IconButton(
onPressed: () async {
ShareResult result = await Share.shareWithResult(
'My pitch of ${DateFormat('MMM d').format(dailyTrack.date)}\n${track.spotifyHref}');
],
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 75.0),
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 72.0),
child: IconButton(
onPressed: () async {
ShareResult result = await Share.shareWithResult(
'My pitch of ${DateFormat('MMM d').format(dailyTrack.date)}\n${track.spotifyHref}');

if (result.status ==
ShareResultStatus.dismissed) {
final snackBar = SnackBar(
content: const Text(
'Don\'t be shy, share the love, share the music'),
backgroundColor: averageColorOfImage,
);
if (result.status == ShareResultStatus.dismissed) {
final snackBar = SnackBar(
content: const Text(
'Don\'t be shy, share the love, share the music'),
backgroundColor: averageColorOfImage,
);

ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
}
},
icon: Icon(Icons.share,
color: Styles().mainColor, size: 24.0)),
),
)
],
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
},
icon: Icon(Icons.share,
color: Styles().mainColor, size: 24.0)),
),
),
)
Expand All @@ -130,8 +154,9 @@ class TrackView extends StatelessWidget {
);
}

Future openSong(String spotifyHref) async {
Uri url = Uri.parse(spotifyHref);
Future openSong(String uri) async {
print(uri);
Uri url = Uri.parse(uri);

if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.2.0"
appcheck:
dependency: "direct main"
description:
name: appcheck
sha256: a9e5852e8c9d14342cfa3569fc464a1d49a49eac41e3d006f5825ce54663678f
url: "https://pub.dev"
source: hosted
version: "1.0.6"
archive:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
flutter_secure_storage: ^8.0.0
in_app_purchase: ^3.1.5
connectivity_plus: ^4.0.1
appcheck: ^1.0.6

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 2881a2a

Please sign in to comment.