feat(favorites): add group persistence foundation
This commit is contained in:
@@ -18,6 +18,7 @@ class Emisora {
|
||||
final int votes;
|
||||
final int clickcount;
|
||||
final int orden;
|
||||
final String grupoFavoritosId;
|
||||
|
||||
const Emisora({
|
||||
this.id,
|
||||
@@ -34,6 +35,7 @@ class Emisora {
|
||||
this.votes = 0,
|
||||
this.clickcount = 0,
|
||||
this.orden = 0,
|
||||
this.grupoFavoritosId = 'sin_asignar',
|
||||
});
|
||||
|
||||
/// Construye una [Emisora] desde la respuesta JSON de Radio Browser API.
|
||||
@@ -71,6 +73,7 @@ class Emisora {
|
||||
votes: map['votes'] as int? ?? 0,
|
||||
clickcount: map['clickcount'] as int? ?? 0,
|
||||
orden: map['orden'] as int? ?? 0,
|
||||
grupoFavoritosId: map['grupo_id'] as String? ?? 'sin_asignar',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -90,6 +93,7 @@ class Emisora {
|
||||
'votes': votes,
|
||||
'clickcount': clickcount,
|
||||
'orden': orden,
|
||||
'grupo_id': grupoFavoritosId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -108,6 +112,7 @@ class Emisora {
|
||||
int? votes,
|
||||
int? clickcount,
|
||||
int? orden,
|
||||
String? grupoFavoritosId,
|
||||
}) {
|
||||
return Emisora(
|
||||
id: id ?? this.id,
|
||||
@@ -124,6 +129,7 @@ class Emisora {
|
||||
votes: votes ?? this.votes,
|
||||
clickcount: clickcount ?? this.clickcount,
|
||||
orden: orden ?? this.orden,
|
||||
grupoFavoritosId: grupoFavoritosId ?? this.grupoFavoritosId,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
class GrupoFavoritos {
|
||||
const GrupoFavoritos({
|
||||
required this.id,
|
||||
required this.nombre,
|
||||
required this.orden,
|
||||
this.protegido = false,
|
||||
});
|
||||
|
||||
static const sinAsignarId = 'sin_asignar';
|
||||
|
||||
final String id;
|
||||
final String nombre;
|
||||
final int orden;
|
||||
final bool protegido;
|
||||
|
||||
bool get esSinAsignar => id == sinAsignarId;
|
||||
|
||||
factory GrupoFavoritos.fromMap(Map<String, dynamic> map) {
|
||||
return GrupoFavoritos(
|
||||
id: map['id'] as String,
|
||||
nombre: map['nombre'] as String,
|
||||
orden: map['orden'] as int? ?? 0,
|
||||
protegido: (map['protegido'] as int? ?? 0) == 1,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'nombre': nombre,
|
||||
'orden': orden,
|
||||
'protegido': protegido ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
GrupoFavoritos copyWith({
|
||||
String? id,
|
||||
String? nombre,
|
||||
int? orden,
|
||||
bool? protegido,
|
||||
}) {
|
||||
return GrupoFavoritos(
|
||||
id: id ?? this.id,
|
||||
nombre: nombre ?? this.nombre,
|
||||
orden: orden ?? this.orden,
|
||||
protegido: protegido ?? this.protegido,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user