From 4842411dfcd316048221ce89565bfd19f4faa0cb Mon Sep 17 00:00:00 2001 From: Hemant KArya <65885023+HemantKArya@users.noreply.github.com> Date: Sun, 24 Mar 2024 20:13:52 +0530 Subject: [PATCH] auto sliding charts at home added to settings --- .../library/cubit/library_items_cubit.dart | 3 --- .../settings_cubit/cubit/settings_cubit.dart | 9 +++++++++ .../settings_cubit/cubit/settings_state.dart | 6 +++++- lib/routes_and_consts/global_str_consts.dart | 1 + .../screen/home_views/setting_view.dart | 20 +++++++++++++++++-- lib/screens/widgets/carousal_widget.dart | 15 +++++++++++++- 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/lib/blocs/library/cubit/library_items_cubit.dart b/lib/blocs/library/cubit/library_items_cubit.dart index 81b541c..2432cad 100644 --- a/lib/blocs/library/cubit/library_items_cubit.dart +++ b/lib/blocs/library/cubit/library_items_cubit.dart @@ -1,15 +1,12 @@ // ignore_for_file: public_member_api_docs, sort_constructors_first import 'dart:developer'; - import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; - import 'package:Bloomee/model/songModel.dart'; import 'package:Bloomee/screens/widgets/snackbar.dart'; import 'package:Bloomee/services/db/GlobalDB.dart'; import 'package:Bloomee/services/db/bloomee_db_service.dart'; import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart'; - part 'library_items_state.dart'; class LibraryItemsCubit extends Cubit { diff --git a/lib/blocs/settings_cubit/cubit/settings_cubit.dart b/lib/blocs/settings_cubit/cubit/settings_cubit.dart index 3b60c9f..cacc6c5 100644 --- a/lib/blocs/settings_cubit/cubit/settings_cubit.dart +++ b/lib/blocs/settings_cubit/cubit/settings_cubit.dart @@ -15,10 +15,19 @@ class SettingsCubit extends Cubit { .then((value) { emit(state.copyWith(autoUpdateNotify: value ?? false)); }); + BloomeeDBService.getSettingBool(GlobalStrConsts.autoSlideCharts) + .then((value) { + emit(state.copyWith(autoSlideCharts: value ?? true)); + }); } void updateAutoUpdateNotify(bool value) { BloomeeDBService.putSettingBool(GlobalStrConsts.autoUpdateNotify, value); emit(state.copyWith(autoUpdateNotify: value)); } + + void updateAutoSlideCharts(bool value) { + BloomeeDBService.putSettingBool(GlobalStrConsts.autoSlideCharts, value); + emit(state.copyWith(autoSlideCharts: value)); + } } diff --git a/lib/blocs/settings_cubit/cubit/settings_state.dart b/lib/blocs/settings_cubit/cubit/settings_state.dart index 53fa579..c33ce93 100644 --- a/lib/blocs/settings_cubit/cubit/settings_state.dart +++ b/lib/blocs/settings_cubit/cubit/settings_state.dart @@ -3,19 +3,23 @@ part of 'settings_cubit.dart'; class SettingsState { bool autoUpdateNotify; + bool autoSlideCharts; SettingsState({ required this.autoUpdateNotify, + required this.autoSlideCharts, }); SettingsState copyWith({ bool? autoUpdateNotify, + bool? autoSlideCharts, }) { return SettingsState( autoUpdateNotify: autoUpdateNotify ?? this.autoUpdateNotify, + autoSlideCharts: autoSlideCharts ?? this.autoSlideCharts, ); } } final class SettingsInitial extends SettingsState { - SettingsInitial() : super(autoUpdateNotify: false); + SettingsInitial() : super(autoUpdateNotify: false, autoSlideCharts: true); } diff --git a/lib/routes_and_consts/global_str_consts.dart b/lib/routes_and_consts/global_str_consts.dart index a32ba61..a6b9136 100644 --- a/lib/routes_and_consts/global_str_consts.dart +++ b/lib/routes_and_consts/global_str_consts.dart @@ -12,4 +12,5 @@ class GlobalStrConsts { static const String ChartScreen = "ChartScreen"; static const String autoUpdateNotify = "auto_update_notify"; + static const String autoSlideCharts = "auto_slide_charts"; } diff --git a/lib/screens/screen/home_views/setting_view.dart b/lib/screens/screen/home_views/setting_view.dart index d6efe60..7a135dd 100644 --- a/lib/screens/screen/home_views/setting_view.dart +++ b/lib/screens/screen/home_views/setting_view.dart @@ -1,7 +1,5 @@ // ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart'; -import 'package:Bloomee/services/db/GlobalDB.dart'; -import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart'; import 'package:flutter/material.dart'; import 'package:Bloomee/screens/screen/home_views/setting_views/check_update_view.dart'; @@ -71,6 +69,24 @@ class _SettingsViewState extends State { onChanged: (value) { context.read().updateAutoUpdateNotify(value); }), + SwitchListTile( + value: state.autoSlideCharts, + subtitle: Text( + "Slide charts automatically in home screen.", + style: TextStyle( + color: Default_Theme.primaryColor1.withOpacity(0.5), + fontSize: 14) + .merge(Default_Theme.secondoryTextStyleMedium), + ), + title: Text( + "Auto slide charts", + style: const TextStyle( + color: Default_Theme.primaryColor1, fontSize: 20) + .merge(Default_Theme.secondoryTextStyleMedium), + ), + onChanged: (value) { + context.read().updateAutoSlideCharts(value); + }), ], ); }, diff --git a/lib/screens/widgets/carousal_widget.dart b/lib/screens/widgets/carousal_widget.dart index b12aa3c..96d97f0 100644 --- a/lib/screens/widgets/carousal_widget.dart +++ b/lib/screens/widgets/carousal_widget.dart @@ -1,4 +1,6 @@ +import 'dart:developer'; import 'package:Bloomee/blocs/explore/cubit/explore_cubits.dart'; +import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart'; import 'package:Bloomee/screens/screen/chart/chart_widget.dart'; import 'package:Bloomee/screens/screen/chart/show_charts.dart'; import 'package:carousel_slider/carousel_slider.dart'; @@ -24,6 +26,7 @@ class _CaraouselWidgetState extends State { bool _visibility = true; final FetchChartCubit fetchChartCubit = FetchChartCubit(); List chartCubitList = List.empty(growable: true); + bool autoSlideCharts = true; @override void initState() { @@ -31,6 +34,16 @@ class _CaraouselWidgetState extends State { chartCubitList.add(ChartCubit(i, fetchChartCubit)); } super.initState(); + context.read().stream.listen((event) { + if (autoSlideCharts != event.autoSlideCharts) { + autoSlideCharts = event.autoSlideCharts; + if (autoSlideCharts) { + log("Auto Slide Charts Enabled"); + } else { + log("Auto Slide Charts Disabled"); + } + } + }); } @override @@ -74,7 +87,7 @@ class _CaraouselWidgetState extends State { }, height: 320.0, viewportFraction: 0.7, - // autoPlay: true, + autoPlay: autoSlideCharts, autoPlayInterval: const Duration(milliseconds: 2500), // aspectRatio: 15 / 16, // enableInfiniteScroll: true,