icon things
This commit is contained in:
parent
a91654df03
commit
8bc45ad6fd
50 changed files with 592 additions and 213 deletions
|
@ -15,14 +15,188 @@ class VotingPage extends StatefulWidget {
|
|||
|
||||
class _VotingPageState extends State<VotingPage> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
List<SpotifyTrack> _searchResults = [];
|
||||
bool _isLoading = false;
|
||||
String _statusMessage = '';
|
||||
|
||||
final LayerLink _layerLink = LayerLink();
|
||||
OverlayEntry? _overlayEntry;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadInitialQueue();
|
||||
_searchFocusNode.addListener(_onSearchFocusChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_hideSearchOverlay();
|
||||
_searchController.dispose();
|
||||
_searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSearchFocusChange() {
|
||||
if (_searchFocusNode.hasFocus && _searchResults.isNotEmpty) {
|
||||
_showSearchOverlay();
|
||||
} else if (!_searchFocusNode.hasFocus) {
|
||||
// Delay hiding to allow for taps on results
|
||||
Future.delayed(const Duration(milliseconds: 150), () {
|
||||
_hideSearchOverlay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _showSearchOverlay() {
|
||||
if (_overlayEntry != null) return;
|
||||
|
||||
_overlayEntry = _createOverlayEntry();
|
||||
Overlay.of(context).insert(_overlayEntry!);
|
||||
}
|
||||
|
||||
void _hideSearchOverlay() {
|
||||
_overlayEntry?.remove();
|
||||
_overlayEntry = null;
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry() {
|
||||
RenderBox renderBox = context.findRenderObject() as RenderBox;
|
||||
var size = renderBox.size;
|
||||
var offset = renderBox.localToGlobal(Offset.zero);
|
||||
|
||||
return OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
left: offset.dx + 20,
|
||||
top: offset.dy + 200, // Adjust based on search field position
|
||||
width: size.width - 40,
|
||||
child: CompositedTransformFollower(
|
||||
link: _layerLink,
|
||||
showWhenUnlinked: false,
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: const Color(0xFF1E1E1E),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxHeight: 300),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFF6366F1).withOpacity(0.3)),
|
||||
),
|
||||
child: _buildSearchResultsOverlay(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResultsOverlay() {
|
||||
if (_searchResults.isEmpty) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: const Text(
|
||||
'No results found',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: _searchResults.length,
|
||||
itemBuilder: (context, index) {
|
||||
final track = _searchResults[index];
|
||||
return _buildSearchResultItem(track, index);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResultItem(SpotifyTrack track, int index) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_addToQueue(track);
|
||||
_hideSearchOverlay();
|
||||
_searchController.clear();
|
||||
_searchFocusNode.unfocus();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
// Album Art
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
color: const Color(0xFF2A2A2A),
|
||||
),
|
||||
child: track.album.images.isNotEmpty
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Image.network(
|
||||
track.album.images.first.url,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.music_note,
|
||||
color: Colors.grey,
|
||||
size: 16,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.music_note,
|
||||
color: Colors.grey,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Track Info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
track.name,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
track.artists.map((a) => a.name).join(', '),
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 12,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Add Icon
|
||||
const Icon(
|
||||
Icons.add_circle_outline,
|
||||
color: Color(0xFF6366F1),
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _loadInitialQueue() async {
|
||||
|
@ -31,7 +205,14 @@ class _VotingPageState extends State<VotingPage> {
|
|||
}
|
||||
|
||||
Future<void> _searchSpotify(String query) async {
|
||||
if (query.isEmpty) return;
|
||||
if (query.isEmpty) {
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_statusMessage = '';
|
||||
});
|
||||
_hideSearchOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if search query is appropriate
|
||||
if (!GenreFilterService.isSearchQueryAppropriate(query)) {
|
||||
|
@ -41,6 +222,7 @@ class _VotingPageState extends State<VotingPage> {
|
|||
_statusMessage = 'Search term not suitable for the peaceful Lido atmosphere. Try: ${suggestions.join(', ')}';
|
||||
_searchResults = [];
|
||||
});
|
||||
_hideSearchOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,6 +239,7 @@ class _VotingPageState extends State<VotingPage> {
|
|||
_statusMessage = blockMessage ?? 'Please wait $cooldown seconds before searching again.';
|
||||
_searchResults = [];
|
||||
});
|
||||
_hideSearchOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,31 +252,35 @@ class _VotingPageState extends State<VotingPage> {
|
|||
final queueService = Provider.of<MusicQueueService>(context, listen: false);
|
||||
final results = await queueService.searchTracks(query);
|
||||
|
||||
// Filter results based on genre appropriateness
|
||||
final filteredResults = GenreFilterService.filterSearchResults(results);
|
||||
// No filtering on search results - let users see all tracks
|
||||
// Filtering only happens when adding to queue to maintain atmosphere
|
||||
|
||||
// Record the suggestion attempt
|
||||
spamService.recordSuggestion(userId);
|
||||
|
||||
setState(() {
|
||||
_searchResults = filteredResults;
|
||||
_searchResults = results;
|
||||
_isLoading = false;
|
||||
if (filteredResults.isEmpty && results.isNotEmpty) {
|
||||
_statusMessage = 'No tracks found that match the peaceful Lido atmosphere. Try searching for chill, ambient, or relaxing music.';
|
||||
} else if (filteredResults.isEmpty) {
|
||||
if (results.isEmpty) {
|
||||
_statusMessage = 'No tracks found for "$query"';
|
||||
} else {
|
||||
final filtered = results.length - filteredResults.length;
|
||||
_statusMessage = 'Found ${filteredResults.length} tracks' +
|
||||
(filtered > 0 ? ' ($filtered filtered for atmosphere)' : '');
|
||||
_statusMessage = 'Found ${results.length} tracks';
|
||||
}
|
||||
});
|
||||
|
||||
// Show overlay if we have results and search field is focused
|
||||
if (results.isNotEmpty && _searchFocusNode.hasFocus) {
|
||||
_showSearchOverlay();
|
||||
} else {
|
||||
_hideSearchOverlay();
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_statusMessage = 'Search failed: ${e.toString()}';
|
||||
_searchResults = [];
|
||||
});
|
||||
_hideSearchOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,34 +389,74 @@ class _VotingPageState extends State<VotingPage> {
|
|||
const SizedBox(height: 20),
|
||||
|
||||
// Search Bar
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search for songs, artists, albums...',
|
||||
hintStyle: const TextStyle(color: Colors.grey),
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.grey),
|
||||
suffixIcon: _isLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFF6366F1)),
|
||||
CompositedTransformTarget(
|
||||
link: _layerLink,
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocusNode,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search for songs, artists, albums...',
|
||||
hintStyle: const TextStyle(color: Colors.grey),
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.grey),
|
||||
suffixIcon: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_isLoading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFF6366F1)),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
filled: true,
|
||||
fillColor: const Color(0xFF1E1E1E),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
if (_searchController.text.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear, color: Colors.grey),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
_hideSearchOverlay();
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_statusMessage = '';
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFF1E1E1E),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF6366F1), width: 2),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
// Search as user types (with debounce)
|
||||
if (value.length >= 3) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (_searchController.text == value) {
|
||||
_searchSpotify(value);
|
||||
}
|
||||
});
|
||||
} else if (value.isEmpty) {
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_statusMessage = '';
|
||||
});
|
||||
_hideSearchOverlay();
|
||||
}
|
||||
},
|
||||
onSubmitted: _searchSpotify,
|
||||
),
|
||||
onSubmitted: _searchSpotify,
|
||||
),
|
||||
|
||||
// Atmosphere Info
|
||||
|
@ -323,33 +550,51 @@ class _VotingPageState extends State<VotingPage> {
|
|||
),
|
||||
),
|
||||
|
||||
// Search Results and Queue
|
||||
// Queue Section
|
||||
Expanded(
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
const TabBar(
|
||||
labelColor: Color(0xFF6366F1),
|
||||
unselectedLabelColor: Colors.grey,
|
||||
indicatorColor: Color(0xFF6366F1),
|
||||
tabs: [
|
||||
Tab(text: 'Search Results'),
|
||||
Tab(text: 'Queue'),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Music Queue',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF6366F1).withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF6366F1),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'${queueService.queue.length} songs',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6366F1),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: [
|
||||
// Search Results Tab
|
||||
_buildSearchResults(),
|
||||
// Queue Tab
|
||||
_buildQueueView(queueService),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: _buildQueueView(queueService),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -360,40 +605,6 @@ class _VotingPageState extends State<VotingPage> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults() {
|
||||
if (_searchResults.isEmpty && !_isLoading) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search,
|
||||
size: 80,
|
||||
color: Colors.grey,
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
'Search for songs to add to the queue',
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(20),
|
||||
itemCount: _searchResults.length,
|
||||
itemBuilder: (context, index) {
|
||||
final track = _searchResults[index];
|
||||
return _buildTrackCard(track);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQueueView(MusicQueueService queueService) {
|
||||
final queue = queueService.queue;
|
||||
|
||||
|
@ -439,97 +650,6 @@ class _VotingPageState extends State<VotingPage> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildTrackCard(SpotifyTrack track) {
|
||||
return Card(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
children: [
|
||||
// Album Art
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: const Color(0xFF2A2A2A),
|
||||
),
|
||||
child: track.album.images.isNotEmpty
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.network(
|
||||
track.album.images.first.url,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.music_note,
|
||||
color: Colors.grey,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.music_note,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Track Info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
track.name,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
track.artists.map((a) => a.name).join(', '),
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 14,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
track.album.name,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 12,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Add Button
|
||||
IconButton(
|
||||
onPressed: () => _addToQueue(track),
|
||||
icon: const Icon(
|
||||
Icons.add_circle,
|
||||
color: Color(0xFF6366F1),
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQueueItemCard(QueueItem queueItem, int index, MusicQueueService queueService) {
|
||||
return Card(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue