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
Showing
with 578 additions and 95 deletions
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/discoveries.dart';
part 'data_discoveries_state.dart';
class DataDiscoveriesCubit extends HydratedCubit<DataDiscoveriesState> {
DataDiscoveriesCubit() : super(const DataDiscoveriesState());
void getData(DataDiscoveriesState state) {
emit(state);
}
DiscoveriesData? getValue() {
return state.discoveries;
}
void update(DiscoveriesData? discoveries) {
if (state.discoveries.toString() != discoveries.toString()) {
setValue(discoveries);
}
}
void setValue(DiscoveriesData? discoveries) {
emit(DataDiscoveriesState(
discoveries: discoveries,
));
}
@override
DataDiscoveriesState? fromJson(Map<String, dynamic> json) {
return DataDiscoveriesState(
discoveries: DiscoveriesData.fromJson(json['discoveries']),
);
}
@override
Map<String, Object?>? toJson(DataDiscoveriesState state) {
return <String, Object?>{
'discoveries': state.discoveries?.toJson(),
};
}
}
part of 'data_discoveries_cubit.dart';
@immutable
class DataDiscoveriesState extends Equatable {
const DataDiscoveriesState({
this.discoveries,
});
final DiscoveriesData? discoveries;
@override
List<Object?> get props => <Object?>[
discoveries,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/statistics_global.dart';
part 'data_statistics_global_state.dart';
class DataStatisticsGlobalCubit extends HydratedCubit<DataStatisticsGlobalState> {
DataStatisticsGlobalCubit() : super(const DataStatisticsGlobalState());
void getData(DataStatisticsGlobalState state) {
emit(state);
}
StatisticsGlobalData? getValue() {
return state.statisticsGlobal;
}
void update(StatisticsGlobalData? statisticsGlobal) {
if (state.statisticsGlobal.toString() != statisticsGlobal.toString()) {
setValue(statisticsGlobal);
}
}
void setValue(StatisticsGlobalData? statisticsGlobal) {
emit(DataStatisticsGlobalState(
statisticsGlobal: statisticsGlobal,
));
}
@override
DataStatisticsGlobalState? fromJson(Map<String, dynamic> json) {
return DataStatisticsGlobalState(
statisticsGlobal: StatisticsGlobalData.fromJson(json['statisticsGlobal']),
);
}
@override
Map<String, Object?>? toJson(DataStatisticsGlobalState state) {
return <String, Object?>{
'statisticsGlobal': state.statisticsGlobal?.toJson(),
};
}
}
part of 'data_statistics_global_cubit.dart';
@immutable
class DataStatisticsGlobalState extends Equatable {
const DataStatisticsGlobalState({
this.statisticsGlobal,
});
final StatisticsGlobalData? statisticsGlobal;
@override
List<Object?> get props => <Object?>[
statisticsGlobal,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/statistics_recent.dart';
part 'data_statistics_recent_state.dart';
class DataStatisticsRecentCubit extends HydratedCubit<DataStatisticsRecentState> {
DataStatisticsRecentCubit() : super(const DataStatisticsRecentState());
void getData(DataStatisticsRecentState state) {
emit(state);
}
StatisticsRecentData? getValue() {
return state.statisticsRecent;
}
void update(StatisticsRecentData? statisticsRecent) {
if (state.statisticsRecent.toString() != statisticsRecent.toString()) {
setValue(statisticsRecent);
}
}
void setValue(StatisticsRecentData? statisticsRecent) {
emit(DataStatisticsRecentState(
statisticsRecent: statisticsRecent,
));
}
@override
DataStatisticsRecentState? fromJson(Map<String, dynamic> json) {
return DataStatisticsRecentState(
statisticsRecent: StatisticsRecentData.fromJson(json['statisticsRecent']),
);
}
@override
Map<String, Object?>? toJson(DataStatisticsRecentState state) {
return <String, Object?>{
'statisticsRecent': state.statisticsRecent?.toJson(),
};
}
}
part of 'data_statistics_recent_cubit.dart';
@immutable
class DataStatisticsRecentState extends Equatable {
const DataStatisticsRecentState({
this.statisticsRecent,
});
final StatisticsRecentData? statisticsRecent;
@override
List<Object?> get props => <Object?>[
statisticsRecent,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/timeline.dart';
part 'data_timeline_state.dart';
class DataTimelineCubit extends HydratedCubit<DataTimelineState> {
DataTimelineCubit() : super(const DataTimelineState());
void getData(DataTimelineState state) {
emit(state);
}
TimelineData? getValue() {
return state.timeline;
}
void update(TimelineData? timeline) {
if (state.timeline.toString() != timeline.toString()) {
setValue(timeline);
}
}
void setValue(TimelineData? timeline) {
emit(DataTimelineState(
timeline: timeline,
));
}
@override
DataTimelineState? fromJson(Map<String, dynamic> json) {
return DataTimelineState(
timeline: TimelineData.fromJson(json['timeline']),
);
}
@override
Map<String, Object?>? toJson(DataTimelineState state) {
return <String, Object?>{
'timeline': state.timeline?.toJson(),
};
}
}
part of 'data_timeline_cubit.dart';
@immutable
class DataTimelineState extends Equatable {
const DataTimelineState({
this.timeline,
});
final TimelineData? timeline;
@override
List<Object?> get props => <Object?>[
timeline,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/topartists.dart';
part 'data_top_artists_state.dart';
class DataTopArtistsCubit extends HydratedCubit<DataTopArtistsState> {
DataTopArtistsCubit() : super(const DataTopArtistsState());
void getData(DataTopArtistsState state) {
emit(state);
}
TopArtistsData? getValue(key) {
return state.topArtists;
}
void update(TopArtistsData? topArtists) {
if (state.topArtists.toString() != topArtists.toString()) {
setValue(topArtists);
}
}
void setValue(TopArtistsData? topArtists) {
emit(DataTopArtistsState(
topArtists: topArtists,
));
}
@override
DataTopArtistsState? fromJson(Map<String, dynamic> json) {
return DataTopArtistsState(
topArtists: TopArtistsData.fromJson(json['topArtists']),
);
}
@override
Map<String, Object?>? toJson(DataTopArtistsState state) {
return <String, Object?>{
'topArtists': state.topArtists?.toJson(),
};
}
}
part of 'data_top_artists_cubit.dart';
@immutable
class DataTopArtistsState extends Equatable {
const DataTopArtistsState({
this.topArtists,
});
final TopArtistsData? topArtists;
@override
List<Object?> get props => <Object?>[
topArtists,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
part 'settings_state.dart';
class SettingsCubit extends HydratedCubit<SettingsState> {
SettingsCubit() : super(const SettingsState());
String getUsername() {
return state.username ?? '';
}
String getSecurityToken() {
return state.securityToken ?? '';
}
void setValues({
String? username,
String? securityToken,
}) {
emit(SettingsState(
username: username != null ? username : state.username,
securityToken: securityToken != null ? securityToken : state.securityToken,
));
}
@override
SettingsState? fromJson(Map<String, dynamic> json) {
String username = json['username'] as String;
String securityToken = json['securityToken'] as String;
return SettingsState(
username: username,
securityToken: securityToken,
);
}
@override
Map<String, String>? toJson(SettingsState state) {
return <String, String>{
'username': state.username ?? '',
'securityToken': state.securityToken ?? '',
};
}
}
part of 'settings_cubit.dart';
@immutable
class SettingsState extends Equatable {
const SettingsState({
this.username,
this.securityToken,
});
final String? username;
final String? securityToken;
@override
List<String?> get props => <String?>[
username,
securityToken,
];
Map<String, String?> get values => <String, String?>{
'username': username,
'securityToken': securityToken,
};
}
import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hive/hive.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:path_provider/path_provider.dart';
import 'config/theme.dart';
import 'ui/screens/skeleton_screen.dart';
import 'package:scrobbles/config/theme.dart';
import 'package:scrobbles/cubit/bottom_nav_cubit.dart';
import 'package:scrobbles/cubit/data_counts_by_day_cubit.dart';
import 'package:scrobbles/cubit/data_counts_by_hour_cubit.dart';
import 'package:scrobbles/cubit/data_discoveries_cubit.dart';
import 'package:scrobbles/cubit/data_statistics_global_cubit.dart';
import 'package:scrobbles/cubit/data_statistics_recent_cubit.dart';
import 'package:scrobbles/cubit/data_timeline_cubit.dart';
import 'package:scrobbles/cubit/data_top_artists_cubit.dart';
import 'package:scrobbles/cubit/settings_cubit.dart';
import 'package:scrobbles/ui/skeleton.dart';
void main() async {
/// Initialize packages
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
final Directory tmpDir = await getTemporaryDirectory();
Hive.init(tmpDir.toString());
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: tmpDir,
);
runApp(
EasyLocalization(
......@@ -27,16 +48,31 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Scrobbles',
theme: appTheme,
home: const SkeletonScreen(),
return MultiBlocProvider(
providers: [
BlocProvider<SettingsCubit>(create: (context) => SettingsCubit()),
BlocProvider<BottomNavCubit>(create: (context) => BottomNavCubit()),
BlocProvider<DataCountsByDayCubit>(create: (context) => DataCountsByDayCubit()),
BlocProvider<DataCountsByHourCubit>(create: (context) => DataCountsByHourCubit()),
BlocProvider<DataDiscoveriesCubit>(create: (context) => DataDiscoveriesCubit()),
BlocProvider<DataStatisticsGlobalCubit>(
create: (context) => DataStatisticsGlobalCubit()),
BlocProvider<DataStatisticsRecentCubit>(
create: (context) => DataStatisticsRecentCubit()),
BlocProvider<DataTimelineCubit>(create: (context) => DataTimelineCubit()),
BlocProvider<DataTopArtistsCubit>(create: (context) => DataTopArtistsCubit()),
],
child: MaterialApp(
title: 'Scrobbles',
theme: appTheme,
home: const SkeletonScreen(),
// Localization stuff
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
// Localization stuff
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
),
);
}
}
......@@ -7,11 +7,11 @@ class CountsByDayData {
required this.data,
});
factory CountsByDayData.fromJson(Map<String, dynamic> json) {
factory CountsByDayData.fromJson(Map<String, dynamic>? json) {
Map<int, double> data = {};
if (json['counts-by-day'] != null) {
json['counts-by-day'].keys.forEach((day) {
if (json?['counts-by-day'] != null) {
json?['counts-by-day'].keys.forEach((day) {
data[int.parse(day)] = double.parse(json['counts-by-day'][day].toString());
});
}
......@@ -19,11 +19,7 @@ class CountsByDayData {
return CountsByDayData(data: data);
}
factory CountsByDayData.createEmpty() {
return CountsByDayData.fromJson({});
}
String toString() {
Map<String, Object?>? toJson() {
Map<String, double> map = {};
this.data.keys.forEach((day) {
......@@ -31,6 +27,10 @@ class CountsByDayData {
map[day.toString()] = value != null ? value.toDouble() : 0.0;
});
return jsonEncode({'counts-by-day': map});
return {'counts-by-day': map};
}
String toString() {
return jsonEncode(this.toJson());
}
}
......@@ -7,11 +7,11 @@ class CountsByHourData {
required this.data,
});
factory CountsByHourData.fromJson(Map<String, dynamic> json) {
factory CountsByHourData.fromJson(Map<String, dynamic>? json) {
Map<int, double> data = {};
if (json['counts-by-hour'] != null) {
json['counts-by-hour'].keys.forEach((day) {
if (json?['counts-by-hour'] != null) {
json?['counts-by-hour'].keys.forEach((day) {
if (int.parse(day) != 24) {
data[int.parse(day)] = double.parse(json['counts-by-hour'][day].toString());
}
......@@ -21,11 +21,7 @@ class CountsByHourData {
return CountsByHourData(data: data);
}
factory CountsByHourData.createEmpty() {
return CountsByHourData.fromJson({});
}
String toString() {
Map<String, Object?>? toJson() {
Map<String, double> map = {};
this.data.keys.forEach((day) {
......@@ -33,6 +29,10 @@ class CountsByHourData {
map[day.toString()] = value != null ? value.toDouble() : 0.0;
});
return jsonEncode({'counts-by-hour': map});
return {'counts-by-hour': map};
}
String toString() {
return jsonEncode(this.toJson());
}
}
import 'dart:convert';
class DiscoveriesDataValue {
final int newArtistsCount;
final int newTracksCount;
const DiscoveriesDataValue({required this.newArtistsCount, required this.newTracksCount});
factory DiscoveriesDataValue.fromJson(Map<String, dynamic>? json) {
return DiscoveriesDataValue(
newArtistsCount: json?['new-artists'] as int,
newTracksCount: json?['new-tracks'] as int,
);
}
}
class DiscoveriesData {
final Map<String, DiscoveriesDataValue> data;
const DiscoveriesData({
required this.data,
});
factory DiscoveriesData.fromJson(Map<String, dynamic>? json) {
Map<String, DiscoveriesDataValue> data = {};
json?.keys.forEach((date) {
DiscoveriesDataValue value = DiscoveriesDataValue(
newArtistsCount: json[date]['new-artists'] as int,
newTracksCount: json[date]['new-tracks'] as int,
);
data[date] = value;
});
return DiscoveriesData(data: data);
}
Map<String, Object?>? toJson() {
Map<String, Map<String, int>> map = {};
this.data.keys.forEach((element) {
DiscoveriesDataValue? item = this.data[element];
map[element] = {
'new-artists': item != null ? item.newArtistsCount : 0,
'new-tracks': item != null ? item.newTracksCount : 0,
};
});
return map;
}
String toString() {
return jsonEncode(this.toJson());
}
}
import 'dart:convert';
class StatisticsData {
final int totalCount;
final int recentCount;
final int firstPlayedArtistsCount;
final int firstPlayedTracksCount;
final int selectedPeriod;
final DateTime lastScrobble;
const StatisticsData({
required this.totalCount,
required this.recentCount,
required this.firstPlayedArtistsCount,
required this.firstPlayedTracksCount,
required this.selectedPeriod,
required this.lastScrobble,
});
factory StatisticsData.fromJson(Map<String, dynamic> json) {
return StatisticsData(
totalCount: json['totalCount'] != null ? json['totalCount'] as int : 0,
recentCount: json['recentCount'] != null ? json['recentCount'] as int : 0,
firstPlayedArtistsCount:
json['firstPlayedArtistsCount'] != null ? json['firstPlayedArtistsCount'] as int : 0,
firstPlayedTracksCount:
json['firstPlayedTracksCount'] != null ? json['firstPlayedTracksCount'] as int : 0,
selectedPeriod: json['selectedPeriod'] != null ? json['selectedPeriod'] as int : 0,
lastScrobble: (json['lastScrobble'] != null && json['lastScrobble']['date'] != null)
? DateTime.parse(
json['lastScrobble']['date'],
)
: DateTime.now(),
);
}
factory StatisticsData.createEmpty() {
return StatisticsData.fromJson({});
}
String toString() {
Map<String, dynamic> map = {
'totalCount': this.totalCount,
'recentCount': this.recentCount,
'firstPlayedArtistsCount': this.firstPlayedArtistsCount,
'firstPlayedTracksCount': this.firstPlayedTracksCount,
'selectedPeriod': this.selectedPeriod,
'lastScrobble': {
'date': this.lastScrobble.toString(),
},
};
return jsonEncode(map);
}
}
import 'dart:convert';
class StatisticsGlobalData {
final int? totalCount;
final DateTime? lastScrobble;
const StatisticsGlobalData({
required this.totalCount,
required this.lastScrobble,
});
factory StatisticsGlobalData.fromJson(Map<String, dynamic>? json) {
return StatisticsGlobalData(
totalCount: (json?['totalCount'] != null) ? (json?['totalCount'] as int) : null,
lastScrobble: (json?['lastScrobble'] != null && json?['lastScrobble']['date'] != null)
? DateTime.parse(
json?['lastScrobble']['date'],
)
: null,
);
}
Map<String, Object?>? toJson() {
return <String, Object?>{
'totalCount': this.totalCount,
'lastScrobble': {
'date': this.lastScrobble != null ? this.lastScrobble.toString() : null,
},
};
}
String toString() {
return jsonEncode(this.toJson());
}
}
import 'dart:convert';
class StatisticsRecentData {
final int? recentCount;
final int? firstPlayedArtistsCount;
final int? firstPlayedTracksCount;
final int? selectedPeriod;
const StatisticsRecentData({
required this.recentCount,
required this.firstPlayedArtistsCount,
required this.firstPlayedTracksCount,
required this.selectedPeriod,
});
factory StatisticsRecentData.fromJson(Map<String, dynamic>? json) {
return StatisticsRecentData(
recentCount: (json?['recentCount'] != null) ? (json?['recentCount'] as int) : null,
firstPlayedArtistsCount: (json?['firstPlayedArtistsCount'] != null)
? (json?['firstPlayedArtistsCount'] as int)
: null,
firstPlayedTracksCount: (json?['firstPlayedTracksCount'] != null)
? (json?['firstPlayedTracksCount'] as int)
: null,
selectedPeriod:
(json?['selectedPeriod'] != null) ? (json?['selectedPeriod'] as int) : null,
);
}
Map<String, Object?>? toJson() {
return <String, Object?>{
'recentCount': this.recentCount,
'firstPlayedArtistsCount': this.firstPlayedArtistsCount,
'firstPlayedTracksCount': this.firstPlayedTracksCount,
'selectedPeriod': this.selectedPeriod,
};
}
String toString() {
return jsonEncode(this.toJson());
}
}
......@@ -6,10 +6,10 @@ class TimelineDataValue {
const TimelineDataValue({required this.counts, required this.eclecticism});
factory TimelineDataValue.fromJson(Map<String, dynamic> json) {
factory TimelineDataValue.fromJson(Map<String, dynamic>? json) {
return TimelineDataValue(
counts: json['counts'] as int,
eclecticism: json['eclecticism'] as int,
counts: json?['counts'] as int,
eclecticism: json?['eclecticism'] as int,
);
}
}
......@@ -21,10 +21,10 @@ class TimelineData {
required this.data,
});
factory TimelineData.fromJson(Map<String, dynamic> json) {
factory TimelineData.fromJson(Map<String, dynamic>? json) {
Map<String, TimelineDataValue> data = {};
json.keys.forEach((date) {
json?.keys.forEach((date) {
TimelineDataValue value = TimelineDataValue(
counts: json[date]['counts'] as int,
eclecticism: json[date]['eclecticism'] as int,
......@@ -36,11 +36,7 @@ class TimelineData {
return TimelineData(data: data);
}
factory TimelineData.createEmpty() {
return TimelineData.fromJson({});
}
String toString() {
Map<String, Object?>? toJson() {
Map<String, Map<String, int>> map = {};
this.data.keys.forEach((element) {
......@@ -51,6 +47,10 @@ class TimelineData {
};
});
return jsonEncode(map);
return map;
}
String toString() {
return jsonEncode(this.toJson());
}
}