aboutsummaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/app_provider.dart
blob: 64c0e4768b075577d5bd9be58c982986235399bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import 'package:flutter_ics_homescreen/data/data_providers/hybrid_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/signal_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/time_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/units_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/users_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/vehicle_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/audio_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/radio_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/mediaplayer_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/mediaplayer_position_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/playlist_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/playlist_art_notifier.dart';
import 'package:flutter_ics_homescreen/data/data_providers/val_client.dart';
import 'package:flutter_ics_homescreen/data/data_providers/app_launcher.dart';
import 'package:flutter_ics_homescreen/data/data_providers/radio_client.dart';
import 'package:flutter_ics_homescreen/data/data_providers/storage_client.dart';
import 'package:flutter_ics_homescreen/data/data_providers/mpd_client.dart';
import 'package:flutter_ics_homescreen/data/data_providers/play_controller.dart';
import 'package:flutter_ics_homescreen/data/data_providers/voice_agent_client.dart';
import 'package:flutter_ics_homescreen/data/data_providers/voice_assistant_notifier.dart';
import 'package:flutter_ics_homescreen/export.dart';

import 'package:flutter_ics_homescreen/data/models/users.dart';

import '../models/voice_assistant_state.dart';

enum AppState {
  home,
  dashboard,
  hvac,
  apps,
  media,
  settings,
  splash,
  dateTime,
  bluetooth,
  wifi,
  wired,
  audioSettings,
  profiles,
  newProfile,
  units,
  versionInfo,
  weather,
  distanceUnit,
  tempUnit,
  pressureUnit,
  clock,
  date,
  time,
  year,
  voiceAssistant,
  sttModel,
}

class AppStateNotifier extends Notifier<AppState> {
  AppState previous = AppState.home;

  @override
  AppState build() {
    return AppState.splash;
  }

  void update(AppState newState) {
    previous = state;
    state = newState;
  }

  void back() {
    state = previous;
  }
}

final appProvider =
    NotifierProvider<AppStateNotifier, AppState>(AppStateNotifier.new);

final valClientProvider = Provider((ref) {
  KuksaConfig config = ref.watch(appConfigProvider).kuksaConfig;
  return ValClient(config: config, ref: ref);
});

final voiceAgentClientProvider = Provider((ref){
  VoiceAgentConfig config = ref.watch(appConfigProvider).voiceAgentConfig;
  return VoiceAgentClient(config: config, ref: ref);
});

final appLauncherProvider = Provider((ref) {
  return AppLauncher(ref: ref);
});

final appLauncherListProvider =
    NotifierProvider<AppLauncherList, List<AppLauncherInfo>>(
        AppLauncherList.new);

final radioClientProvider = Provider((ref) {
  RadioConfig config = ref.watch(appConfigProvider).radioConfig;
  return RadioClient(config: config, ref: ref);
});


final storageClientProvider = Provider((ref) {
  StorageConfig config = ref.watch(appConfigProvider).storageConfig;
  return StorageClient(config: config, ref: ref);
});


final mpdClientProvider = Provider((ref) {
  MpdConfig config = ref.watch(appConfigProvider).mpdConfig;
  return MpdClient(config: config, ref: ref);
});

final vehicleProvider =
    NotifierProvider<VehicleNotifier, Vehicle>(VehicleNotifier.new);

final signalsProvider = StateNotifierProvider<SignalNotifier, Signals>((ref) {
  return SignalNotifier(const Signals.initial());
});

final unitStateProvider =
    NotifierProvider<UnitsNotifier, Units>(UnitsNotifier.new);

final audioStateProvider =
    NotifierProvider<AudioStateNotifier, AudioState>(AudioStateNotifier.new);

final radioStateProvider =
    NotifierProvider<RadioStateNotifier, RadioState>(RadioStateNotifier.new);

final mediaPlayerStateProvider =
    NotifierProvider<MediaPlayerStateNotifier, MediaPlayerState>(
        MediaPlayerStateNotifier.new);

final mediaPlayerPositionProvider =
    NotifierProvider<MediaPlayerPositionNotifier, Duration>(
        MediaPlayerPositionNotifier.new);

final playlistProvider =
    NotifierProvider<PlaylistNotifier, List<PlaylistEntry>>(
        PlaylistNotifier.new);

final playlistArtProvider =
    NotifierProvider<PlaylistArtNotifier, Map<int, Uint8List>>(
        PlaylistArtNotifier.new);

final playStateProvider = StateProvider<bool>((ref) {
  final mediaPlayState = ref.watch(
      mediaPlayerStateProvider.select((mediaplayer) => mediaplayer.playState));
  final radioPlaying =
      ref.watch(radioStateProvider.select((radio) => radio.playing));
  return (mediaPlayState == PlayState.playing || radioPlaying);
});

final playControllerProvider = Provider((ref) {
  return PlayController(ref: ref);
});

final usersProvider =
    NotifierProvider<UsersNotifier, Users>(UsersNotifier.new);

final hybridStateProvider =
    StateNotifierProvider<HybridNotifier, Hybrid>((ref) {
  return HybridNotifier(const Hybrid.initial());
});

final currentTimeProvider =
    StateNotifierProvider<CurrentTimeNotifier, DateTime>((ref) {
  return CurrentTimeNotifier();
});


final voiceAssistantStateProvider =
    NotifierProvider<VoiceAssistantStateNotifier, VoiceAssistantState>(VoiceAssistantStateNotifier.new);