synced with last dev, added profiles for cyr2lat replacement dictionaries

This commit is contained in:
HDDen
2026-04-25 01:30:55 +03:00
parent 7a4ac9ae9b
commit f56c28a27d
45 changed files with 1547 additions and 394 deletions
+52
View File
@@ -260,4 +260,56 @@ class AppSettingsService extends ChangeNotifier {
_settings.copyWith(translationDownloadedModels: value),
);
}
Cyr2LatProfile getSelectedCyr2LatProfile() {
return _settings.cyr2latProfiles.firstWhere(
(p) => p.id == _settings.selectedCyr2latProfileId,
orElse: () => _settings.cyr2latProfiles.first,
);
}
Cyr2LatProfile? getCyr2LatProfileById(String profileId) {
return _settings.cyr2latProfiles.cast<Cyr2LatProfile?>().firstWhere(
(p) => p?.id == profileId,
orElse: () => null,
);
}
Future<void> setSelectedCyr2LatProfile(String profileId) async {
await updateSettings(
_settings.copyWith(selectedCyr2latProfileId: profileId),
);
}
Future<void> addCyr2LatProfile(Cyr2LatProfile profile) async {
final updated = List<Cyr2LatProfile>.from(_settings.cyr2latProfiles)
..add(profile);
await updateSettings(_settings.copyWith(cyr2latProfiles: updated));
}
Future<void> updateCyr2LatProfile(Cyr2LatProfile updatedProfile) async {
final updated = _settings.cyr2latProfiles
.map((p) => p.id == updatedProfile.id ? updatedProfile : p)
.toList();
await updateSettings(_settings.copyWith(cyr2latProfiles: updated));
}
Future<void> removeCyr2LatProfile(String profileId) async {
if (_settings.cyr2latProfiles.length <= 1) {
return; // Don't remove the last profile
}
final updated = _settings.cyr2latProfiles
.where((p) => p.id != profileId)
.toList();
var newSelectedId = _settings.selectedCyr2latProfileId;
if (newSelectedId == profileId) {
newSelectedId = updated.first.id;
}
await updateSettings(
_settings.copyWith(
cyr2latProfiles: updated,
selectedCyr2latProfileId: newSelectedId,
),
);
}
}