You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.4 KiB
72 lines
2.4 KiB
import '../model/music.dart';
|
|
import '../model/spot.dart';
|
|
import '../persistence/database_loader.dart';
|
|
import '../persistence/database_saver.dart';
|
|
import '../persistence/database_searcher.dart';
|
|
import '../persistence/loader.dart';
|
|
|
|
import '../persistence/saver.dart';
|
|
import '../model/user.dart';
|
|
import '../persistence/searcher.dart';
|
|
|
|
class Controller {
|
|
static Controller? _this;
|
|
|
|
static Saver saver = DatabaseSaver();
|
|
static Loader loader = DatabaseLoader();
|
|
static Searcher _searcher = DatabaseSearcher();
|
|
|
|
User currentUser = User("", "");
|
|
|
|
factory Controller() {
|
|
if (_this == null) _this = Controller._();
|
|
return _this!;
|
|
}
|
|
|
|
Controller._();
|
|
|
|
void save(User userToSave) {
|
|
saver.save(userToSave);
|
|
}
|
|
|
|
Future<void> load(String username, String password) async {
|
|
changeCurrentUser(await loader.load(username, password));
|
|
}
|
|
|
|
User createUser(String username, String password) {
|
|
return User(username, password);
|
|
}
|
|
|
|
void changeCurrentUser(User user) {
|
|
this.currentUser = user;
|
|
}
|
|
|
|
void changeUsernameCourant(String newName) {
|
|
if (newName != null) {
|
|
this.currentUser.usernameDafl = newName;
|
|
}
|
|
}
|
|
|
|
void changePasswordCourant(String newPass) {
|
|
if (newPass != null) {
|
|
this.currentUser.passwDafl = newPass;
|
|
}
|
|
}
|
|
|
|
Future<bool> searchByUsername(String username) async {
|
|
return await _searcher.searchByUsername(username);
|
|
}
|
|
|
|
void chargeExample(){
|
|
currentUser.spots = [
|
|
Spot( User('Félix','1234'), Music('Couleurs','Khali','https://khaligidilit.com/assets/images/cover-LAI%CC%88LA-Khali.jpeg')),
|
|
Spot( User('Audric','1234'), Music("J'suis PNL",'PNL','https://m.media-amazon.com/images/I/61aUOMzwS8L._SL1440_.jpg')),
|
|
Spot( User('Dorian','1234'), Music('Sundance','Nepal','https://pbs.twimg.com/media/ExJ-My-XMAE3Ko2.jpg')),
|
|
Spot( User('Lucas','1234'), Music('Eternelle 2','So La Lune','https://cdns-images.dzcdn.net/images/cover/2818a661c6d533155ce6dffc256b1f51/500x500.jpg')),
|
|
Spot( User('David','1234'), Music('M.I.L.S 3','Ninho','https://cdns-images.dzcdn.net/images/cover/b351f0e935c9c3901f8d893b92ab952a/500x500.jpg')),
|
|
Spot( User('Hugo','1234'), Music('Deux frères','PNL','https://cdns-images.dzcdn.net/images/cover/65147b581f2ace9e0f0723ee76e70fda/500x500.jpg')),
|
|
Spot( User('Alban','1234'), Music('Paradis','Sopico','https://cdns-images.dzcdn.net/images/cover/17a9747927ac3e5ea56f92f635d9180c/500x500.jpg')),
|
|
].reversed.toList();
|
|
}
|
|
}
|