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 431 additions and 39 deletions
class Settings {
static const int countsByDayDaysCount = 21;
static const int countsByHourDaysCount = 21;
static const int discoveriesDaysCount = 14;
static const int statisticsRecentDaysCount = 21;
static const int timelineDaysCount = 14;
static const int topArtistsDaysCount = 14;
}
......@@ -3,18 +3,25 @@ import 'package:hydrated_bloc/hydrated_bloc.dart';
class BottomNavCubit extends HydratedCubit<int> {
BottomNavCubit() : super(0);
void updateIndex(int index) => emit(index);
int pagesCount = 3;
void movePrevious() => emit((state > 0) ? state - 1 : state);
void moveNext() => emit((state < 2) ? state + 1 : state);
void updateIndex(int index) {
if (isIndexAllowed(index)) {
emit(index);
} else {
goToHomePage();
}
}
bool isIndexAllowed(int index) {
return (index >= 0) && (index < pagesCount);
}
void getHomePage() => emit(0);
void getDiscoveriesPage() => emit(1);
void getStatisticsPage() => emit(2);
void goToHomePage() => emit(0);
@override
int? fromJson(Map<String, dynamic> json) {
return json['pageIndex'] as int?;
return 0;
}
@override
......
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/counts_by_day.dart';
part 'data_counts_by_day_state.dart';
class DataCountsByDayCubit extends HydratedCubit<DataCountsByDayState> {
DataCountsByDayCubit() : super(const DataCountsByDayState());
void getData(DataCountsByDayState state) {
emit(state);
}
CountsByDayData? getValue() {
return state.countsByDay;
}
void setValue(CountsByDayData? countsByDay) {
emit(DataCountsByDayState(
countsByDay: countsByDay,
));
}
@override
DataCountsByDayState? fromJson(Map<String, dynamic> json) {
return DataCountsByDayState(
countsByDay: CountsByDayData.fromJson(json['countsByDay']),
);
}
@override
Map<String, Object?>? toJson(DataCountsByDayState state) {
return <String, Object?>{
'countsByDay': state.countsByDay?.toJson(),
};
}
}
part of 'data_counts_by_day_cubit.dart';
@immutable
class DataCountsByDayState extends Equatable {
const DataCountsByDayState({
this.countsByDay,
});
final CountsByDayData? countsByDay;
@override
List<Object?> get props => <Object?>[
countsByDay,
];
}
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:scrobbles/models/counts_by_hour.dart';
part 'data_counts_by_hour_state.dart';
class DataCountsByHourCubit extends HydratedCubit<DataCountsByHourState> {
DataCountsByHourCubit() : super(const DataCountsByHourState());
void getData(DataCountsByHourState state) {
emit(state);
}
CountsByHourData? getValue() {
return state.countsByHour;
}
void setValue(CountsByHourData? countsByHour) {
emit(DataCountsByHourState(
countsByHour: countsByHour,
));
}
@override
DataCountsByHourState? fromJson(Map<String, dynamic> json) {
return DataCountsByHourState(
countsByHour: CountsByHourData.fromJson(json['countsByHour']),
);
}
@override
Map<String, Object?>? toJson(DataCountsByHourState state) {
return <String, Object?>{
'countsByHour': state.countsByHour?.toJson(),
};
}
}
part of 'data_counts_by_hour_cubit.dart';
@immutable
class DataCountsByHourState extends Equatable {
const DataCountsByHourState({
this.countsByHour,
});
final CountsByHourData? countsByHour;
@override
List<Object?> get props => <Object?>[
countsByHour,
];
}
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 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 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 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 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 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,
];
}
......@@ -6,9 +6,8 @@ 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/ui/skeleton.dart';
void main() async {
/// Initialize packages
......
......@@ -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());
}
}
......@@ -6,10 +6,10 @@ class DiscoveriesDataValue {
const DiscoveriesDataValue({required this.newArtistsCount, required this.newTracksCount});
factory DiscoveriesDataValue.fromJson(Map<String, dynamic> json) {
factory DiscoveriesDataValue.fromJson(Map<String, dynamic>? json) {
return DiscoveriesDataValue(
newArtistsCount: json['new-artists'] as int,
newTracksCount: json['new-tracks'] as int,
newArtistsCount: json?['new-artists'] as int,
newTracksCount: json?['new-tracks'] as int,
);
}
}
......@@ -21,10 +21,10 @@ class DiscoveriesData {
required this.data,
});
factory DiscoveriesData.fromJson(Map<String, dynamic> json) {
factory DiscoveriesData.fromJson(Map<String, dynamic>? json) {
Map<String, DiscoveriesDataValue> data = {};
json.keys.forEach((date) {
json?.keys.forEach((date) {
DiscoveriesDataValue value = DiscoveriesDataValue(
newArtistsCount: json[date]['new-artists'] as int,
newTracksCount: json[date]['new-tracks'] as int,
......@@ -36,11 +36,7 @@ class DiscoveriesData {
return DiscoveriesData(data: data);
}
factory DiscoveriesData.createEmpty() {
return DiscoveriesData.fromJson({});
}
String toString() {
Map<String, Object?>? toJson() {
Map<String, Map<String, int>> map = {};
this.data.keys.forEach((element) {
......@@ -51,6 +47,10 @@ class DiscoveriesData {
};
});
return jsonEncode(map);
return map;
}
String toString() {
return jsonEncode(this.toJson());
}
}