Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • android/org.benoitharrault.scrobbles
1 result
Show changes
......@@ -4,8 +4,8 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:scrobbles/config/settings.dart';
import 'package:scrobbles/cubit/data_timeline_cubit.dart';
import 'package:scrobbles/cubit/settings_cubit.dart';
import 'package:scrobbles/models/timeline.dart';
import 'package:scrobbles/network/scrobbles.dart';
import 'package:scrobbles/ui/widgets/card_content.dart';
......@@ -18,7 +18,9 @@ class CardTimeline extends StatelessWidget {
@override
Widget build(BuildContext context) {
final int daysCount = Settings.timelineDaysCount;
SettingsCubit settings = BlocProvider.of<SettingsCubit>(context);
final int daysCount = settings.getTimelineDaysCount();
return BlocBuilder<DataTimelineCubit, DataTimelineState>(
builder: (BuildContext context, DataTimelineState state) {
......@@ -29,7 +31,7 @@ class CardTimeline extends StatelessWidget {
'daysCount': daysCount.toString(),
},
),
loader: updateTimeline(Settings.timelineDaysCount),
loader: updateTimeline(daysCount),
content: Stack(
children: [
ChartTimelineCounts(
......@@ -62,7 +64,7 @@ class CardTimeline extends StatelessWidget {
return ShowErrorWidget(message: '${snapshot.error}');
}
BlocProvider.of<DataTimelineCubit>(context).update(snapshot.data);
BlocProvider.of<DataTimelineCubit>(context).update(snapshot.data);
return !snapshot.hasData ? loading : done;
},
......
......@@ -4,8 +4,8 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:scrobbles/config/settings.dart';
import 'package:scrobbles/cubit/data_top_artists_cubit.dart';
import 'package:scrobbles/cubit/settings_cubit.dart';
import 'package:scrobbles/models/topartists.dart';
import 'package:scrobbles/network/scrobbles.dart';
import 'package:scrobbles/ui/widgets/card_content.dart';
......@@ -17,7 +17,9 @@ class CardTopArtists extends StatelessWidget {
@override
Widget build(BuildContext context) {
final int daysCount = Settings.topArtistsDaysCount;
SettingsCubit settings = BlocProvider.of<SettingsCubit>(context);
final int daysCount = settings.getTopArtistsDaysCount();
return BlocBuilder<DataTopArtistsCubit, DataTopArtistsState>(
builder: (BuildContext context, DataTopArtistsState state) {
......@@ -28,7 +30,7 @@ class CardTopArtists extends StatelessWidget {
'daysCount': daysCount.toString(),
},
),
loader: updateTopArtists(Settings.topArtistsDaysCount),
loader: updateTopArtists(daysCount),
content: ChartTopArtists(
chartData: TopArtistsData.fromJson(jsonDecode(state.topArtists.toString())),
isLoading: false,
......
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unicons/unicons.dart';
import 'package:scrobbles/config/default_settings.dart';
import 'package:scrobbles/cubit/settings_cubit.dart';
class SettingsForm extends StatefulWidget {
const SettingsForm({super.key});
@override
State<SettingsForm> createState() => _SettingsFormState();
}
class _SettingsFormState extends State<SettingsForm> {
final usernameController = TextEditingController();
final securityTokenController = TextEditingController();
int countsByDayDaysCount = DefaultSettings.defaultCountsByDayDaysCount;
int countsByHourDaysCount = DefaultSettings.defaultCountsByHourDaysCount;
int discoveriesDaysCount = DefaultSettings.defaultDiscoveriesDaysCount;
int statisticsRecentDaysCount = DefaultSettings.defaultStatisticsRecentDaysCount;
int timelineDaysCount = DefaultSettings.defaultTimelineDaysCount;
int topArtistsDaysCount = DefaultSettings.defaultTopArtistsDaysCount;
List<bool> _selectedCountsByDayDaysCount = [];
List<bool> _selectedCountsByHourDaysCount = [];
List<bool> _selectedDiscoveriesDaysCount = [];
List<bool> _selectedStatisticsRecentDaysCount = [];
List<bool> _selectedTimelineDaysCount = [];
List<bool> _selectedTopArtistsDaysCount = [];
@override
void didChangeDependencies() {
SettingsCubit settings = BlocProvider.of<SettingsCubit>(context);
usernameController.text = settings.getUsername();
securityTokenController.text = settings.getSecurityToken();
countsByDayDaysCount = settings.getCountsByDayDaysCount();
countsByHourDaysCount = settings.getCountsByHourDaysCount();
discoveriesDaysCount = settings.getDiscoveriesDaysCount();
statisticsRecentDaysCount = settings.getStatisticsRecentDaysCount();
timelineDaysCount = settings.getTimelineDaysCount();
topArtistsDaysCount = settings.getTopArtistsDaysCount();
_selectedCountsByDayDaysCount =
DefaultSettings.allowedValues.map((e) => (e == countsByDayDaysCount)).toList();
_selectedCountsByHourDaysCount =
DefaultSettings.allowedValues.map((e) => (e == countsByHourDaysCount)).toList();
_selectedDiscoveriesDaysCount =
DefaultSettings.allowedValues.map((e) => (e == discoveriesDaysCount)).toList();
_selectedStatisticsRecentDaysCount =
DefaultSettings.allowedValues.map((e) => (e == statisticsRecentDaysCount)).toList();
_selectedTimelineDaysCount =
DefaultSettings.allowedValues.map((e) => (e == timelineDaysCount)).toList();
_selectedTopArtistsDaysCount =
DefaultSettings.allowedValues.map((e) => (e == topArtistsDaysCount)).toList();
super.didChangeDependencies();
}
@override
void dispose() {
usernameController.dispose();
securityTokenController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
void saveSettings() {
BlocProvider.of<SettingsCubit>(context).setValues(
username: usernameController.text,
securityToken: securityTokenController.text,
countsByDayDaysCount: countsByDayDaysCount,
countsByHourDaysCount: countsByHourDaysCount,
discoveriesDaysCount: discoveriesDaysCount,
statisticsRecentDaysCount: statisticsRecentDaysCount,
timelineDaysCount: timelineDaysCount,
topArtistsDaysCount: topArtistsDaysCount,
);
}
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// Username
// Text('settings_label_username').tr(),
// TextFormField(
// controller: usernameController,
// decoration: InputDecoration(
// border: UnderlineInputBorder(),
// ),
// ),
// SizedBox(height: 16),
// Security token
// Text('settings_label_security_token').tr(),
// TextFormField(
// controller: securityTokenController,
// decoration: InputDecoration(
// border: UnderlineInputBorder(),
// ),
// ),
// SizedBox(height: 20),
// Counts by day
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_counts_by_day_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
countsByDayDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedCountsByDayDaysCount.length; i++) {
_selectedCountsByDayDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedCountsByDayDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Counts by hour
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_counts_by_hour_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
countsByHourDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedCountsByHourDaysCount.length; i++) {
_selectedCountsByHourDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedCountsByHourDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Discoveries
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_discoveries_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
discoveriesDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedDiscoveriesDaysCount.length; i++) {
_selectedDiscoveriesDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedDiscoveriesDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Statistics (recent)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_statistics_recent_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
statisticsRecentDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedStatisticsRecentDaysCount.length; i++) {
_selectedStatisticsRecentDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedStatisticsRecentDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Timeline
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_timeline_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
timelineDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedTimelineDaysCount.length; i++) {
_selectedTimelineDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedTimelineDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Top Artists
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('settings_label_top_artists_days_count').tr(),
ToggleButtons(
onPressed: (int index) {
setState(() {
topArtistsDaysCount = DefaultSettings.allowedValues[index];
for (int i = 0; i < _selectedTopArtistsDaysCount.length; i++) {
_selectedTopArtistsDaysCount[i] = i == index;
}
});
},
borderRadius: const BorderRadius.all(Radius.circular(8)),
constraints: const BoxConstraints(minHeight: 30.0, minWidth: 30.0),
isSelected: _selectedTopArtistsDaysCount,
children: DefaultSettings.allowedValues.map((e) => Text(e.toString())).toList(),
),
],
),
// Save
ElevatedButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(UniconsLine.save),
SizedBox(width: 8),
Text('settings_button_save').tr(),
],
),
onPressed: () => saveSettings(),
),
],
);
}
}
......@@ -3,7 +3,7 @@ description: Display scrobbles data and charts
publish_to: 'none'
version: 0.0.34+34
version: 0.0.36+36
environment:
sdk: '^3.0.0'
......