openRoom property
Used to init all the adapters, and open the necessary room.
Important:
- Avoid opening multiple room's at the same time.
Return:
- openRoom will ALWAYS return a
bool
:true
if the room/path is openedfalse
if something wrong happend.
Implementation
Future<bool> get openRoom async {
//
Hive.registerAdapter(FavoritesEntityAdapter());
Hive.registerAdapter(LastPlayedEntityAdapter());
Hive.registerAdapter(MostPlayedEntityAdapter());
Hive.registerAdapter(PlaylistEntityAdapter());
Hive.registerAdapter(SongEntityAdapter());
switch (this) {
//
case RoomType.FAVORITES:
return await Hive.openBox<FavoritesEntity>(
"on_favorites_room",
).then(
(value) => value.isOpen,
);
//
case RoomType.LAST_PLAYED:
return await Hive.openBox<LastPlayedEntity>(
"on_last_played_room",
).then(
(value) => value.isOpen,
);
//
case RoomType.MOST_PLAYED:
return await Hive.openBox<MostPlayedEntity>(
"on_most_played_room",
).then(
(value) => value.isOpen,
);
//
case RoomType.PLAYLIST:
return await Hive.openBox<PlaylistEntity>(
"on_playlists_room",
).then(
(value) => value.isOpen,
);
//
default:
throw "[initOnAudioRoom] - Room don't exist!";
}
}