/
NavigationManager.cs
299 lines (268 loc) · 13.1 KB
/
NavigationManager.cs
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using MPfm.Library.UpdateLibrary;
using MPfm.MVP.Bootstrap;
using TinyIoC;
using MPfm.MVP.Views;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.Library.Objects;
using MPfm.Sound.AudioFiles;
namespace MPfm.MVP.Navigation
{
/// <summary>
/// Manager class for managing view and presenter instances.
/// </summary>
public abstract class NavigationManager
{
ISplashView _splashView;
ISplashPresenter _splashPresenter;
IMainView _mainView;
IMainPresenter _mainPresenter;
IPlayerPresenter _playerPresenter;
ILibraryBrowserPresenter _libraryBrowserPresenter;
ISongBrowserPresenter _songBrowserPresenter;
IMarkersPresenter _markersPresenter;
ILoopsPresenter _loopsPresenter;
ITimeShiftingPresenter _timeShiftingPresenter;
IPitchShiftingPresenter _pitchShiftingPresenter;
IDesktopPreferencesView _preferencesView;
IAudioPreferencesPresenter _audioPreferencesPresenter;
IGeneralPreferencesPresenter _generalPreferencesPresenter;
ILibraryPreferencesPresenter _libraryPreferencesPresenter;
IPlaylistView _playlistView;
IPlaylistPresenter _playlistPresenter;
IUpdateLibraryView _updateLibraryView;
IUpdateLibraryPresenter _updateLibraryPresenter;
IDesktopEffectsView _effectsView;
IEqualizerPresetsPresenter _equalizerPresetsPresenter;
IEqualizerPresetDetailsPresenter _equalizerPresetDetailsPresenter;
ISyncView _syncView;
ISyncPresenter _syncPresenter;
ISyncMenuView _syncMenuView;
ISyncMenuPresenter _syncMenuPresenter;
ISyncDownloadView _syncDownloadView;
ISyncDownloadPresenter _syncDownloadPresenter;
public virtual ISplashView CreateSplashView()
{
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action onInitDone = () =>
{
Console.WriteLine("SplashInitDone");
CreateMainView();
};
Action<IBaseView> onViewReady = (view) =>
{
_splashPresenter = Bootstrapper.GetContainer().Resolve<ISplashPresenter>();
_splashPresenter.BindView((ISplashView)view);
_splashPresenter.Initialize(onInitDone); // TODO: Should the presenter call NavMgr instead of using an action?
};
_splashView = Bootstrapper.GetContainer().Resolve<ISplashView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_splashView.OnViewDestroy = (view) =>
{
_splashView = null;
_splashPresenter = null;
};
return _splashView;
}
public virtual IMainView CreateMainView()
{
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) => {
_mainPresenter = Bootstrapper.GetContainer().Resolve<IMainPresenter>();
_mainPresenter.BindView((IMainView)view);
_playerPresenter = Bootstrapper.GetContainer().Resolve<IPlayerPresenter>();
_playerPresenter.BindView((IPlayerView)view);
_libraryBrowserPresenter = Bootstrapper.GetContainer().Resolve<ILibraryBrowserPresenter>();
_libraryBrowserPresenter.BindView((ILibraryBrowserView)view);
_songBrowserPresenter = Bootstrapper.GetContainer().Resolve<ISongBrowserPresenter>();
_songBrowserPresenter.BindView((ISongBrowserView)view);
_markersPresenter = Bootstrapper.GetContainer().Resolve<IMarkersPresenter>();
_markersPresenter.BindView((IMarkersView)view);
_loopsPresenter = Bootstrapper.GetContainer().Resolve<ILoopsPresenter>();
_loopsPresenter.BindView((ILoopsView)view);
_timeShiftingPresenter = Bootstrapper.GetContainer().Resolve<ITimeShiftingPresenter>();
_timeShiftingPresenter.BindView((ITimeShiftingView)view);
_pitchShiftingPresenter = Bootstrapper.GetContainer().Resolve<IPitchShiftingPresenter>();
_pitchShiftingPresenter.BindView((IPitchShiftingView)view);
};
_mainView = Bootstrapper.GetContainer().Resolve<IMainView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_mainView.OnViewDestroy = (view) => {
_mainView = null;
_mainPresenter = null;
_playerPresenter.Dispose(); // Dispose unmanaged stuff (i.e. BASS)
_playerPresenter = null;
_libraryBrowserPresenter = null;
_songBrowserPresenter = null;
_markersPresenter = null;
_loopsPresenter = null;
_timeShiftingPresenter = null;
_pitchShiftingPresenter = null;
};
return _mainView;
}
public virtual IDesktopPreferencesView CreatePreferencesView()
{
if(_preferencesView != null)
{
_preferencesView.ShowView(true);
return _preferencesView;
}
Action<IBaseView> onViewReady = (view) => {
_audioPreferencesPresenter = Bootstrapper.GetContainer().Resolve<IAudioPreferencesPresenter>();
_audioPreferencesPresenter.BindView((IAudioPreferencesView)view);
_generalPreferencesPresenter = Bootstrapper.GetContainer().Resolve<IGeneralPreferencesPresenter>();
_generalPreferencesPresenter.BindView((IGeneralPreferencesView)view);
_libraryPreferencesPresenter = Bootstrapper.GetContainer().Resolve<ILibraryPreferencesPresenter>();
_libraryPreferencesPresenter.BindView((ILibraryPreferencesView)view);
};
_preferencesView = Bootstrapper.GetContainer().Resolve<IDesktopPreferencesView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_preferencesView.OnViewDestroy = (view) => {
_preferencesView = null;
_audioPreferencesPresenter = null;
_generalPreferencesPresenter = null;
_libraryPreferencesPresenter = null;
};
return _preferencesView;
}
public virtual IDesktopEffectsView CreateEffectsView()
{
if(_effectsView != null)
{
_effectsView.ShowView(true);
return _effectsView;
}
Action<IBaseView> onViewReady = (view) => {
_equalizerPresetsPresenter = Bootstrapper.GetContainer().Resolve<IEqualizerPresetsPresenter>();
_equalizerPresetsPresenter.BindView((IEqualizerPresetsView)view);
_equalizerPresetDetailsPresenter = Bootstrapper.GetContainer().Resolve<IEqualizerPresetDetailsPresenter>();
_equalizerPresetDetailsPresenter.BindView((IEqualizerPresetDetailsView)view);
};
_effectsView = Bootstrapper.GetContainer().Resolve<IDesktopEffectsView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_effectsView.OnViewDestroy = (view) => {
_effectsView = null;
_equalizerPresetsPresenter = null;
_equalizerPresetDetailsPresenter = null;
};
return _effectsView;
}
public virtual ISyncView CreateSyncView()
{
// If the view is still visible, just make it the top level window
if(_syncView != null)
{
_syncView.ShowView(true);
return _syncView;
}
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) =>
{
_syncPresenter = Bootstrapper.GetContainer().Resolve<ISyncPresenter>();
_syncPresenter.BindView((ISyncView)view);
};
// Create view and manage view destruction
_syncView = Bootstrapper.GetContainer().Resolve<ISyncView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_syncView.OnViewDestroy = (view) => {
_syncView = null;
_syncPresenter = null;
};
return _syncView;
}
public virtual ISyncMenuView CreateSyncMenuView(SyncDevice device)
{
if(_syncMenuView != null)
{
_syncMenuView.ShowView(true);
return _syncMenuView;
}
Action<IBaseView> onViewReady = (view) =>
{
_syncMenuPresenter = Bootstrapper.GetContainer().Resolve<ISyncMenuPresenter>();
_syncMenuPresenter.BindView((ISyncMenuView)view);
_syncMenuPresenter.SetSyncDevice(device);
};
_syncMenuView = Bootstrapper.GetContainer().Resolve<ISyncMenuView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_syncMenuView.OnViewDestroy = (view) => {
_syncMenuView = null;
_syncMenuPresenter = null;
};
return _syncMenuView;
}
public virtual ISyncDownloadView CreateSyncDownloadView(SyncDevice device, IEnumerable<AudioFile> audioFiles)
{
if(_syncDownloadView != null)
{
_syncDownloadView.ShowView(true);
return _syncDownloadView;
}
Action<IBaseView> onViewReady = (view) =>
{
_syncDownloadPresenter = Bootstrapper.GetContainer().Resolve<ISyncDownloadPresenter>();
_syncDownloadPresenter.BindView((ISyncDownloadView)view);
_syncDownloadPresenter.StartSync(device, audioFiles);
};
_syncDownloadView = Bootstrapper.GetContainer().Resolve<ISyncDownloadView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_syncDownloadView.OnViewDestroy = (view) => {
_syncDownloadView = null;
_syncDownloadPresenter = null;
};
return _syncDownloadView;
}
public virtual IPlaylistView CreatePlaylistView()
{
if(_playlistView != null)
{
_playlistView.ShowView(true);
return _playlistView;
}
Action<IBaseView> onViewReady = (view) =>
{
_playlistPresenter = Bootstrapper.GetContainer().Resolve<IPlaylistPresenter>();
_playlistPresenter.BindView((IPlaylistView)view);
};
// Create view and manage view destruction
_playlistView = Bootstrapper.GetContainer().Resolve<IPlaylistView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_playlistView.OnViewDestroy = (view) => {
_playlistView = null;
_playlistPresenter = null;
};
return _playlistView;
}
public virtual IUpdateLibraryView CreateUpdateLibraryView(UpdateLibraryMode mode, List<string> filePaths, string folderPath)
{
if (_updateLibraryView != null)
{
_updateLibraryView.ShowView(true);
return _updateLibraryView;
}
Action<IBaseView> onViewReady = (view) =>
{
_updateLibraryPresenter = Bootstrapper.GetContainer().Resolve<IUpdateLibraryPresenter>();
_updateLibraryPresenter.BindView((IUpdateLibraryView)view);
_updateLibraryPresenter.UpdateLibrary(mode, filePaths, folderPath);
};
_updateLibraryView = Bootstrapper.GetContainer().Resolve<IUpdateLibraryView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_updateLibraryView.OnViewDestroy = (view) =>
{
_updateLibraryView = null;
_updateLibraryPresenter = null;
};
return _updateLibraryView;
}
}
}