Skip to content
Snippets Groups Projects
Commit f09c06f8 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '53-show-last-discovered-artists-and-tracks' into 'master'

Resolve "Show last discovered artists and tracks"

Closes #53

See merge request !50
parents 5d22b55c a58945e9
No related branches found
No related tags found
1 merge request!50Resolve "Show last discovered artists and tracks"
Pipeline #4747 passed
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:scrobbles/cubit/data_new_tracks_cubit.dart';
import 'package:scrobbles/cubit/settings_cubit.dart';
import 'package:scrobbles/models/new_tracks.dart';
import 'package:scrobbles/network/scrobbles.dart';
import 'package:scrobbles/ui/widgets/card_content.dart';
import 'package:scrobbles/ui/widgets/error.dart';
class CardNewTracks extends StatelessWidget {
const CardNewTracks({super.key});
@override
Widget build(BuildContext context) {
SettingsCubit settings = BlocProvider.of<SettingsCubit>(context);
final int count = settings.getNewTracksCount();
return BlocBuilder<DataNewTracksCubit, DataNewTracksState>(
builder: (BuildContext context, DataNewTracksState state) {
return CardContent(
color: Theme.of(context).colorScheme.surface,
title: 'new_tracks_title'.tr(),
loader: update(count),
content: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: state.newTracks?.data
.map((newTrack) => Text((newTrack.track?.artist.name ?? '') +
' - ' +
(newTrack.track?.name ?? '')))
.toList() ??
[],
),
);
},
);
}
Widget update(int count) {
final Widget loading = const Text('⏳');
final Widget done = const Text('');
late Future<NewTracksData> future = ScrobblesApi.fetchNewTracks(count);
return BlocBuilder<DataNewTracksCubit, DataNewTracksState>(
builder: (BuildContext context, DataNewTracksState state) {
return FutureBuilder<NewTracksData>(
future: future,
builder: (context, snapshot) {
if (snapshot.hasError) {
return ShowErrorWidget(message: '${snapshot.error}');
}
BlocProvider.of<DataNewTracksCubit>(context).update(snapshot.data);
return !snapshot.hasData ? loading : done;
},
);
},
);
}
}
...@@ -23,12 +23,16 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -23,12 +23,16 @@ class _SettingsFormState extends State<SettingsForm> {
int statisticsRecentDaysCount = DefaultSettings.defaultStatisticsRecentDaysCount; int statisticsRecentDaysCount = DefaultSettings.defaultStatisticsRecentDaysCount;
int timelineDaysCount = DefaultSettings.defaultTimelineDaysCount; int timelineDaysCount = DefaultSettings.defaultTimelineDaysCount;
int topArtistsDaysCount = DefaultSettings.defaultTopArtistsDaysCount; int topArtistsDaysCount = DefaultSettings.defaultTopArtistsDaysCount;
int newArtistsCount = DefaultSettings.defaultNewArtistsCount;
int newTracksCount = DefaultSettings.defaultNewTracksCount;
List<bool> _selectedDiscoveriesDaysCount = []; List<bool> _selectedDiscoveriesDaysCount = [];
List<bool> _selectedDistributionDaysCount = []; List<bool> _selectedDistributionDaysCount = [];
List<bool> _selectedStatisticsRecentDaysCount = []; List<bool> _selectedStatisticsRecentDaysCount = [];
List<bool> _selectedTimelineDaysCount = []; List<bool> _selectedTimelineDaysCount = [];
List<bool> _selectedTopArtistsDaysCount = []; List<bool> _selectedTopArtistsDaysCount = [];
List<bool> _selectedNewArtistsCount = [];
List<bool> _selectedNewTracksCount = [];
@override @override
void didChangeDependencies() { void didChangeDependencies() {
...@@ -42,17 +46,26 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -42,17 +46,26 @@ class _SettingsFormState extends State<SettingsForm> {
statisticsRecentDaysCount = settings.getStatisticsRecentDaysCount(); statisticsRecentDaysCount = settings.getStatisticsRecentDaysCount();
timelineDaysCount = settings.getTimelineDaysCount(); timelineDaysCount = settings.getTimelineDaysCount();
topArtistsDaysCount = settings.getTopArtistsDaysCount(); topArtistsDaysCount = settings.getTopArtistsDaysCount();
newArtistsCount = settings.getNewArtistsCount();
newTracksCount = settings.getNewTracksCount();
_selectedDiscoveriesDaysCount = _selectedDiscoveriesDaysCount = DefaultSettings.allowedDaysCountValues
DefaultSettings.allowedValues.map((e) => (e == discoveriesDaysCount)).toList(); .map((e) => (e == discoveriesDaysCount))
_selectedDistributionDaysCount = .toList();
DefaultSettings.allowedValues.map((e) => (e == distributionDaysCount)).toList(); _selectedDistributionDaysCount = DefaultSettings.allowedDaysCountValues
_selectedStatisticsRecentDaysCount = .map((e) => (e == distributionDaysCount))
DefaultSettings.allowedValues.map((e) => (e == statisticsRecentDaysCount)).toList(); .toList();
_selectedStatisticsRecentDaysCount = DefaultSettings.allowedDaysCountValues
.map((e) => (e == statisticsRecentDaysCount))
.toList();
_selectedTimelineDaysCount = _selectedTimelineDaysCount =
DefaultSettings.allowedValues.map((e) => (e == timelineDaysCount)).toList(); DefaultSettings.allowedDaysCountValues.map((e) => (e == timelineDaysCount)).toList();
_selectedTopArtistsDaysCount = _selectedTopArtistsDaysCount =
DefaultSettings.allowedValues.map((e) => (e == topArtistsDaysCount)).toList(); DefaultSettings.allowedDaysCountValues.map((e) => (e == topArtistsDaysCount)).toList();
_selectedNewArtistsCount =
DefaultSettings.allowedCountValues.map((e) => (e == newArtistsCount)).toList();
_selectedNewTracksCount =
DefaultSettings.allowedCountValues.map((e) => (e == newTracksCount)).toList();
super.didChangeDependencies(); super.didChangeDependencies();
} }
...@@ -75,6 +88,8 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -75,6 +88,8 @@ class _SettingsFormState extends State<SettingsForm> {
statisticsRecentDaysCount: statisticsRecentDaysCount, statisticsRecentDaysCount: statisticsRecentDaysCount,
timelineDaysCount: timelineDaysCount, timelineDaysCount: timelineDaysCount,
topArtistsDaysCount: topArtistsDaysCount, topArtistsDaysCount: topArtistsDaysCount,
newArtistsCount: newArtistsCount,
newTracksCount: newTracksCount,
); );
} }
...@@ -118,7 +133,7 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -118,7 +133,7 @@ class _SettingsFormState extends State<SettingsForm> {
ToggleButtons( ToggleButtons(
onPressed: (int index) { onPressed: (int index) {
setState(() { setState(() {
statisticsRecentDaysCount = DefaultSettings.allowedValues[index]; statisticsRecentDaysCount = DefaultSettings.allowedDaysCountValues[index];
for (int i = 0; i < _selectedStatisticsRecentDaysCount.length; i++) { for (int i = 0; i < _selectedStatisticsRecentDaysCount.length; i++) {
_selectedStatisticsRecentDaysCount[i] = i == index; _selectedStatisticsRecentDaysCount[i] = i == index;
} }
...@@ -128,7 +143,9 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -128,7 +143,9 @@ class _SettingsFormState extends State<SettingsForm> {
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0), constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedStatisticsRecentDaysCount, isSelected: _selectedStatisticsRecentDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(), children: DefaultSettings.allowedDaysCountValues
.map((e) => Text(e.toString()))
.toList(),
), ),
], ],
), ),
...@@ -142,7 +159,7 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -142,7 +159,7 @@ class _SettingsFormState extends State<SettingsForm> {
ToggleButtons( ToggleButtons(
onPressed: (int index) { onPressed: (int index) {
setState(() { setState(() {
timelineDaysCount = DefaultSettings.allowedValues[index]; timelineDaysCount = DefaultSettings.allowedDaysCountValues[index];
for (int i = 0; i < _selectedTimelineDaysCount.length; i++) { for (int i = 0; i < _selectedTimelineDaysCount.length; i++) {
_selectedTimelineDaysCount[i] = i == index; _selectedTimelineDaysCount[i] = i == index;
} }
...@@ -152,7 +169,9 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -152,7 +169,9 @@ class _SettingsFormState extends State<SettingsForm> {
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0), constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedTimelineDaysCount, isSelected: _selectedTimelineDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(), children: DefaultSettings.allowedDaysCountValues
.map((e) => Text(e.toString()))
.toList(),
), ),
], ],
), ),
...@@ -166,7 +185,7 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -166,7 +185,7 @@ class _SettingsFormState extends State<SettingsForm> {
ToggleButtons( ToggleButtons(
onPressed: (int index) { onPressed: (int index) {
setState(() { setState(() {
topArtistsDaysCount = DefaultSettings.allowedValues[index]; topArtistsDaysCount = DefaultSettings.allowedDaysCountValues[index];
for (int i = 0; i < _selectedTopArtistsDaysCount.length; i++) { for (int i = 0; i < _selectedTopArtistsDaysCount.length; i++) {
_selectedTopArtistsDaysCount[i] = i == index; _selectedTopArtistsDaysCount[i] = i == index;
} }
...@@ -176,7 +195,9 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -176,7 +195,9 @@ class _SettingsFormState extends State<SettingsForm> {
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0), constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedTopArtistsDaysCount, isSelected: _selectedTopArtistsDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(), children: DefaultSettings.allowedDaysCountValues
.map((e) => Text(e.toString()))
.toList(),
), ),
], ],
), ),
...@@ -190,7 +211,7 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -190,7 +211,7 @@ class _SettingsFormState extends State<SettingsForm> {
ToggleButtons( ToggleButtons(
onPressed: (int index) { onPressed: (int index) {
setState(() { setState(() {
discoveriesDaysCount = DefaultSettings.allowedValues[index]; discoveriesDaysCount = DefaultSettings.allowedDaysCountValues[index];
for (int i = 0; i < _selectedDiscoveriesDaysCount.length; i++) { for (int i = 0; i < _selectedDiscoveriesDaysCount.length; i++) {
_selectedDiscoveriesDaysCount[i] = i == index; _selectedDiscoveriesDaysCount[i] = i == index;
} }
...@@ -200,7 +221,9 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -200,7 +221,9 @@ class _SettingsFormState extends State<SettingsForm> {
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0), constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedDiscoveriesDaysCount, isSelected: _selectedDiscoveriesDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(), children: DefaultSettings.allowedDaysCountValues
.map((e) => Text(e.toString()))
.toList(),
), ),
], ],
), ),
...@@ -214,7 +237,7 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -214,7 +237,7 @@ class _SettingsFormState extends State<SettingsForm> {
ToggleButtons( ToggleButtons(
onPressed: (int index) { onPressed: (int index) {
setState(() { setState(() {
distributionDaysCount = DefaultSettings.allowedValues[index]; distributionDaysCount = DefaultSettings.allowedDaysCountValues[index];
for (int i = 0; i < _selectedDistributionDaysCount.length; i++) { for (int i = 0; i < _selectedDistributionDaysCount.length; i++) {
_selectedDistributionDaysCount[i] = i == index; _selectedDistributionDaysCount[i] = i == index;
} }
...@@ -224,7 +247,62 @@ class _SettingsFormState extends State<SettingsForm> { ...@@ -224,7 +247,62 @@ class _SettingsFormState extends State<SettingsForm> {
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0), constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedDistributionDaysCount, isSelected: _selectedDistributionDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(), children: DefaultSettings.allowedDaysCountValues
.map((e) => Text(e.toString()))
.toList(),
),
],
),
SizedBox(height: 8),
AppTitle2(text: tr('settings_title_counts')),
// New artists count
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_new_artists_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
newArtistsCount = DefaultSettings.allowedCountValues[index];
for (int i = 0; i < _selectedNewArtistsCount.length; i++) {
_selectedNewArtistsCount[i] = i == index;
}
});
saveSettings();
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedNewArtistsCount,
children:
DefaultSettings.allowedCountValues.map((e) => Text(e.toString())).toList(),
),
],
),
// New tracks count
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_new_tracks_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
newTracksCount = DefaultSettings.allowedCountValues[index];
for (int i = 0; i < _selectedNewTracksCount.length; i++) {
_selectedNewTracksCount[i] = i == index;
}
});
saveSettings();
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedNewTracksCount,
children:
DefaultSettings.allowedCountValues.map((e) => Text(e.toString())).toList(),
), ),
], ],
), ),
......
...@@ -3,7 +3,7 @@ description: Display scrobbles data and charts ...@@ -3,7 +3,7 @@ description: Display scrobbles data and charts
publish_to: 'none' publish_to: 'none'
version: 0.0.48+48 version: 0.0.49+49
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment