From 6157b71e31a03943842781467d85a78c399e53e3 Mon Sep 17 00:00:00 2001 From: atillaturkmen Date: Sat, 2 Apr 2022 23:23:57 +0300 Subject: [PATCH 1/2] fix artist genres, do not store preview url --- lib/models/track_model.dart | 5 +---- lib/models/track_model.g.dart | 11 ++++------- lib/network/top_preferences.dart | 10 ++++++++-- lib/widgets/tracks_artists_list.dart | 14 ++++++-------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/models/track_model.dart b/lib/models/track_model.dart index 0f7ab08..45d7971 100644 --- a/lib/models/track_model.dart +++ b/lib/models/track_model.dart @@ -11,17 +11,14 @@ class Track { @HiveField(2) String spotifyUrl; @HiveField(3) - String? previewUrl; - @HiveField(4) String? albumName; - @HiveField(5) + @HiveField(4) String? artist; Track( {required this.name, required this.imageUrl, required this.spotifyUrl, - this.previewUrl, this.albumName, this.artist}); diff --git a/lib/models/track_model.g.dart b/lib/models/track_model.g.dart index c702034..ed8ee4f 100644 --- a/lib/models/track_model.g.dart +++ b/lib/models/track_model.g.dart @@ -20,16 +20,15 @@ class TrackAdapter extends TypeAdapter { name: fields[0] as String, imageUrl: fields[1] as String, spotifyUrl: fields[2] as String, - previewUrl: fields[3] as String?, - albumName: fields[4] as String?, - artist: fields[5] as String?, + albumName: fields[3] as String?, + artist: fields[4] as String?, ); } @override void write(BinaryWriter writer, Track obj) { writer - ..writeByte(6) + ..writeByte(5) ..writeByte(0) ..write(obj.name) ..writeByte(1) @@ -37,10 +36,8 @@ class TrackAdapter extends TypeAdapter { ..writeByte(2) ..write(obj.spotifyUrl) ..writeByte(3) - ..write(obj.previewUrl) - ..writeByte(4) ..write(obj.albumName) - ..writeByte(5) + ..writeByte(4) ..write(obj.artist); } diff --git a/lib/network/top_preferences.dart b/lib/network/top_preferences.dart index 69516c6..7177764 100644 --- a/lib/network/top_preferences.dart +++ b/lib/network/top_preferences.dart @@ -45,6 +45,9 @@ Future topPreferencesCall( List otherUserTracks = otherUser[0]; List otherUserArtists = otherUser[1]; + print(otherUserArtists); + print(otherUserTracks); + List> tracks = [thisUserTracks, otherUserTracks]; List commonTracks = tracks .fold>( @@ -62,6 +65,10 @@ Future topPreferencesCall( List otherArtists = otherUserArtists.toSet().difference(commonArtists.toSet()).toList(); + print(commonArtists); + print(otherTracks); + print(otherArtists); + // save to hive await storeTracksAndArtists(userId, otherId, commonTracks, otherTracks, commonArtists, otherArtists); @@ -82,7 +89,6 @@ List separateArtistAndTrack(l) { name: name, imageUrl: data["album"]["images"][2]["url"], spotifyUrl: data["external_urls"]["spotify"], - previewUrl: data["preview_url"], albumName: data["album"]["name"], artist: data["album"]["artists"][0]["name"], ); @@ -92,7 +98,7 @@ List separateArtistAndTrack(l) { name: name, imageUrl: data["images"][2]["url"], spotifyUrl: data["external_urls"]["spotify"], - genre: data["genres"], + genre: data["genres"].join(', '), ); artists.add(cur); } diff --git a/lib/widgets/tracks_artists_list.dart b/lib/widgets/tracks_artists_list.dart index 8ebc2f2..993a27d 100644 --- a/lib/widgets/tracks_artists_list.dart +++ b/lib/widgets/tracks_artists_list.dart @@ -2,8 +2,6 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:jam/config/box_names.dart'; -import 'package:jam/models/artist_model.dart'; -import 'package:jam/models/track_model.dart'; import 'package:jam/util/util_functions.dart'; _noTrackOrArtist(String text, Icon icon) { @@ -20,7 +18,7 @@ _noTrackOrArtist(String text, Icon icon) { ); } -_trackList(List list) { +_trackList(List list) { return ListView.separated( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), @@ -54,7 +52,7 @@ _trackList(List list) { ); } -_artistList(List list) { +_artistList(List list) { return ListView.separated( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), @@ -98,10 +96,10 @@ tracksArtistsList(String userId, String otherUserId, context) { return ValueListenableBuilder( valueListenable: Hive.box(commonTracksBoxName).listenable(), builder: (context, Box box, widget) { - List? commonTracks = box.get("commonTracks"); - List? commonArtists = box.get("commonArtists"); - List? otherTracks = box.get("otherTracks"); - List? otherArtists = box.get("otherArtists"); + List? commonTracks = box.get("commonTracks"); + List? commonArtists = box.get("commonArtists"); + List? otherTracks = box.get("otherTracks"); + List? otherArtists = box.get("otherArtists"); return Column( children: [ From d8a18f9a3955309a8dd9be169ef6e45db201f1aa Mon Sep 17 00:00:00 2001 From: atillaturkmen Date: Sat, 2 Apr 2022 23:58:38 +0300 Subject: [PATCH 2/2] fix big font issues (close #109) --- lib/pages/chat_language.dart | 82 +++++++++++--------- lib/pages/homepage.dart | 14 ++-- lib/pages/profile.dart | 112 ++++++++++++++------------- lib/widgets/tracks_artists_list.dart | 40 +++++----- 4 files changed, 132 insertions(+), 116 deletions(-) diff --git a/lib/pages/chat_language.dart b/lib/pages/chat_language.dart index 033fe7a..e334a39 100644 --- a/lib/pages/chat_language.dart +++ b/lib/pages/chat_language.dart @@ -136,38 +136,40 @@ class _ChatLanguageState extends State { body: Stack(children: [ Padding( padding: const EdgeInsets.all(20.0), - child: Column( - children: [ - const Text( - "Your Languages:", - style: TextStyle(fontSize: 20), - ), - SizedBox(height: 20), - languages == null || languages.length == 0 - ? Column( - children: [ - Icon( - Icons.warning, - color: Colors.pinkAccent, + child: SingleChildScrollView( + child: Column( + children: [ + const Text( + "Your Languages:", + style: TextStyle(fontSize: 20), + ), + SizedBox(height: 20), + languages == null || languages.length == 0 + ? Column( + children: [ + Icon( + Icons.warning, + color: Colors.pinkAccent, + ), + SizedBox(height: 10), + const Text("You don't have any language preference." + "You have to select at least one language in order to match with other people."), + ], + ) + : Container( + margin: EdgeInsets.only(bottom: okVisible ? 80 : 40), + child: ListView.builder( + physics: BouncingScrollPhysics(), + shrinkWrap: true, + itemCount: languages.length, + itemBuilder: (context, index) { + return _circleListItem(languages[index]); + }, ), - SizedBox(height: 10), - const Text("You don't have any language preference." - "You have to select at least one language in order to match with other people."), - ], - ) - : Container( - height: okVisible ? 450 : 500, - child: ListView.builder( - physics: BouncingScrollPhysics(), - shrinkWrap: true, - itemCount: languages.length, - itemBuilder: (context, index) { - return _circleListItem(languages[index]); - }, ), - ), - SizedBox(height: 20), - ], + SizedBox(height: 20), + ], + ), ), ), Padding( @@ -178,14 +180,24 @@ class _ChatLanguageState extends State { mainAxisSize: MainAxisSize.min, children: [ Visibility( - child: longButtons( - "OK", - () => Navigator.pushReplacementNamed(context, homepage), - color: Colors.green, + child: Column( + children: [ + longButtons( + "OK", + () => Navigator.pushReplacementNamed(context, homepage), + color: Colors.green, + ), + SizedBox( + height: 10, + width: double.infinity, + child: DecoratedBox( + decoration: BoxDecoration(color: Colors.white), + ), + ), + ], ), visible: okVisible, ), - SizedBox(height: 10), longButtons( "Add a language", _openLanguagePickerDialog, diff --git a/lib/pages/homepage.dart b/lib/pages/homepage.dart index 461f9fe..53b9575 100644 --- a/lib/pages/homepage.dart +++ b/lib/pages/homepage.dart @@ -86,14 +86,18 @@ class _HomepageState extends State { RefreshIndicator( onRefresh: _refreshTimer, child: SingleChildScrollView( - physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: const BouncingScrollPhysics( + parent: AlwaysScrollableScrollPhysics()), child: Column( children: [ SizedBox(height: 30), Center( - child: Text(user.username == null - ? "" - : "${greetingsText()} ${user.username!}"), + child: Text( + user.username == null + ? "" + : "${greetingsText()} ${user.username!}", + textAlign: TextAlign.center, + ), ), SizedBox(height: 20), Center( @@ -104,7 +108,7 @@ class _HomepageState extends State { child: new LinearPercentIndicator( width: MediaQuery.of(context).size.width - 50, animation: true, - lineHeight: 20.0, + lineHeight: 25.0, animationDuration: 1000, percent: percent, center: Text(timerText), diff --git a/lib/pages/profile.dart b/lib/pages/profile.dart index 6e254ee..ff2eb51 100644 --- a/lib/pages/profile.dart +++ b/lib/pages/profile.dart @@ -27,67 +27,69 @@ class _ProfileState extends State { title: const Text("Your Profile"), elevation: 0.1, ), - body: Column( - children: [ - SizedBox(height: 30), - Container( - height: 200, - width: 200, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.contain, - image: AssetImage('assets/avatar.png'), + body: SingleChildScrollView( + child: Column( + children: [ + SizedBox(height: 30), + Container( + height: 200, + width: 200, + decoration: BoxDecoration( + image: DecorationImage( + fit: BoxFit.contain, + image: AssetImage('assets/avatar.png'), + ), ), ), - ), - SizedBox(height: 30), - Divider(color: Colors.grey), - Padding( - padding: const EdgeInsets.only(left: 10.0, right: 10.0), - child: Column( - children: [ - ListTile( - leading: Icon( - Icons.language, - color: Colors.black, + SizedBox(height: 30), + Divider(color: Colors.grey), + Padding( + padding: const EdgeInsets.only(left: 10.0, right: 10.0), + child: Column( + children: [ + ListTile( + leading: Icon( + Icons.language, + color: Colors.black, + ), + title: const Text('Your languages'), + onTap: () { + Navigator.pushNamed(context, chatLanguages); + }, ), - title: const Text('Your languages'), - onTap: () { - Navigator.pushNamed(context, chatLanguages); - }, - ), - Divider(color: Colors.grey), - ListTile( - leading: Icon( - Icons.block, - color: Colors.red, + Divider(color: Colors.grey), + ListTile( + leading: Icon( + Icons.block, + color: Colors.red, + ), + title: const Text('Blocked users'), + onTap: () { + Navigator.pushNamed(context, blockedUsers); + }, ), - title: const Text('Blocked users'), - onTap: () { - Navigator.pushNamed(context, blockedUsers); - }, - ), - Divider(color: Colors.grey), - ListTile( - leading: Icon( - Icons.logout, - color: Colors.red, + Divider(color: Colors.grey), + ListTile( + leading: Icon( + Icons.logout, + color: Colors.red, + ), + title: const Text('Logout'), + onTap: () { + showDialog( + context: context, + builder: (BuildContext context) { + return alertDialog; + }, + ); + }, ), - title: const Text('Logout'), - onTap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return alertDialog; - }, - ); - }, - ), - ], + ], + ), ), - ), - Divider(color: Colors.grey), - ], + Divider(color: Colors.grey), + ], + ), ), ); } diff --git a/lib/widgets/tracks_artists_list.dart b/lib/widgets/tracks_artists_list.dart index 993a27d..f92c9b4 100644 --- a/lib/widgets/tracks_artists_list.dart +++ b/lib/widgets/tracks_artists_list.dart @@ -4,6 +4,21 @@ import 'package:hive_flutter/hive_flutter.dart'; import 'package:jam/config/box_names.dart'; import 'package:jam/util/util_functions.dart'; +_headerText(String text) { + TextStyle headerStyle = TextStyle( + fontWeight: FontWeight.bold, + fontSize: 15, + ); + return Padding( + padding: const EdgeInsets.only(right: 15, left: 15), + child: Text( + text, + style: headerStyle, + textAlign: TextAlign.center, + ), + ); +} + _noTrackOrArtist(String text, Icon icon) { return Center( child: Column( @@ -88,11 +103,6 @@ _artistList(List list) { tracksArtistsList(String userId, String otherUserId, context) { String commonTracksBoxName = tracksArtistsBoxName(userId, otherUserId); - TextStyle headerStyle = TextStyle( - fontWeight: FontWeight.bold, - fontSize: 15, - ); - return ValueListenableBuilder( valueListenable: Hive.box(commonTracksBoxName).listenable(), builder: (context, Box box, widget) { @@ -104,20 +114,14 @@ tracksArtistsList(String userId, String otherUserId, context) { return Column( children: [ SizedBox(height: 20), - Text( - "Common Tracks:", - style: headerStyle, - ), + _headerText("Common Tracks:"), SizedBox(height: 20), commonTracks == null || commonTracks.length == 0 ? _noTrackOrArtist("No Common Tracks", Icon(Icons.music_note)) : _trackList(commonTracks), Divider(color: Colors.black), SizedBox(height: 20), - Text( - "Common Artists:", - style: headerStyle, - ), + _headerText("Common Artists:"), SizedBox(height: 20), commonArtists == null || commonArtists.length == 0 ? _noTrackOrArtist( @@ -125,20 +129,14 @@ tracksArtistsList(String userId, String otherUserId, context) { : _artistList(commonArtists), Divider(color: Colors.black), SizedBox(height: 20), - Text( - "Other Tracks This User Listened To:", - style: headerStyle, - ), + _headerText("Other Tracks This User Listened To:"), SizedBox(height: 20), otherTracks == null || otherTracks.length == 0 ? _noTrackOrArtist("No Other Tracks", Icon(Icons.music_note)) : _trackList(otherTracks), Divider(color: Colors.black), SizedBox(height: 20), - Text( - "Other Artists This User Listened To:", - style: headerStyle, - ), + _headerText("Other Artists This User Listened To:"), SizedBox(height: 20), otherArtists == null || otherArtists.length == 0 ? _noTrackOrArtist("No Other Artists", Icon(Icons.assignment_ind))