|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
@ -60,6 +61,8 @@ class AppSettingsScreen extends StatelessWidget {
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
_buildMapSettingsCard(context, settingsService),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
_buildCyr2LatCard(context, settingsService),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
_buildDebugCard(context, settingsService),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
@ -1260,6 +1263,298 @@ class AppSettingsScreen extends StatelessWidget {
|
|
|
|
|
return '${sizeMb.toStringAsFixed(1)} MB • $source';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildCyr2LatCard(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
AppSettingsService settingsService,
|
|
|
|
|
) {
|
|
|
|
|
final selectedProfile = settingsService.getSelectedCyr2LatProfile();
|
|
|
|
|
return Card(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
|
|
|
child: Text(
|
|
|
|
|
context.l10n.channels_cyr2latSettingsHeading,
|
|
|
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
|
initialValue: settingsService.settings.selectedCyr2latProfileId,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: context.l10n.channels_cyr2latSettingsSubheading,
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
items: settingsService.settings.cyr2latProfiles.map((profile) {
|
|
|
|
|
return DropdownMenuItem(
|
|
|
|
|
value: profile.id,
|
|
|
|
|
child: Text(profile.name),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
if (value != null) {
|
|
|
|
|
settingsService.setSelectedCyr2LatProfile(value);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
_showAddCyr2LatProfileDialog(context, settingsService),
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
label: Text(context.l10n.common_add),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: () => _showEditCyr2LatProfileDialog(
|
|
|
|
|
context,
|
|
|
|
|
settingsService,
|
|
|
|
|
selectedProfile,
|
|
|
|
|
),
|
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
|
label: Text(context.l10n.common_edit),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed:
|
|
|
|
|
settingsService.settings.cyr2latProfiles.length > 1
|
|
|
|
|
? () => _showDeleteCyr2LatProfileDialog(
|
|
|
|
|
context,
|
|
|
|
|
settingsService,
|
|
|
|
|
selectedProfile,
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
icon: const Icon(Icons.delete),
|
|
|
|
|
label: Text(context.l10n.common_delete),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showAddCyr2LatProfileDialog(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
AppSettingsService settingsService,
|
|
|
|
|
) {
|
|
|
|
|
final nameController = TextEditingController();
|
|
|
|
|
final jsonController = TextEditingController(
|
|
|
|
|
text: const JsonEncoder.withIndent(' ').convert(defaultCyr2LatCharMap),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
|
title: Text(context.l10n.settings_cyr2latProfileAdd),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
TextField(
|
|
|
|
|
controller: nameController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: context.l10n.settings_cyr2latProfileName,
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
TextField(
|
|
|
|
|
controller: jsonController,
|
|
|
|
|
maxLines: 15,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: context.l10n.channels_cyr2latSettingsDialogHint,
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
hintText: context.l10n.channels_cyr2latSettingsDscr,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: Text(context.l10n.common_cancel),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (nameController.text.isEmpty) {
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(context.l10n.settings_cyr2latProfileNameEmpty),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
final json =
|
|
|
|
|
jsonDecode(jsonController.text) as Map<String, dynamic>;
|
|
|
|
|
final map = json.map(
|
|
|
|
|
(key, value) => MapEntry(key, value.toString()),
|
|
|
|
|
);
|
|
|
|
|
final profile = Cyr2LatProfile(
|
|
|
|
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
|
|
|
|
name: nameController.text,
|
|
|
|
|
charMap: map,
|
|
|
|
|
);
|
|
|
|
|
await settingsService.addCyr2LatProfile(profile);
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(context.l10n.settings_cyr2latProfileAdded),
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(
|
|
|
|
|
context.l10n.channels_cyr2latSettingsDialogWrongJSON(
|
|
|
|
|
e.toString(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Text(context.l10n.common_save),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showEditCyr2LatProfileDialog(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
AppSettingsService settingsService,
|
|
|
|
|
Cyr2LatProfile profile,
|
|
|
|
|
) {
|
|
|
|
|
final nameController = TextEditingController(text: profile.name);
|
|
|
|
|
final jsonController = TextEditingController(
|
|
|
|
|
text: const JsonEncoder.withIndent(' ').convert(profile.charMap),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
|
title: Text(context.l10n.settings_cyr2latProfileEdit),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
TextField(
|
|
|
|
|
controller: nameController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: context.l10n.settings_cyr2latProfileName,
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
TextField(
|
|
|
|
|
controller: jsonController,
|
|
|
|
|
maxLines: 15,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: context.l10n.channels_cyr2latSettingsDialogHint,
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
hintText: context.l10n.channels_cyr2latSettingsDscr,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: Text(context.l10n.common_cancel),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (nameController.text.isEmpty) {
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(context.l10n.settings_cyr2latProfileNameEmpty),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
final json =
|
|
|
|
|
jsonDecode(jsonController.text) as Map<String, dynamic>;
|
|
|
|
|
final map = json.map(
|
|
|
|
|
(key, value) => MapEntry(key, value.toString()),
|
|
|
|
|
);
|
|
|
|
|
final updatedProfile = profile.copyWith(
|
|
|
|
|
name: nameController.text,
|
|
|
|
|
charMap: map,
|
|
|
|
|
);
|
|
|
|
|
await settingsService.updateCyr2LatProfile(updatedProfile);
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(context.l10n.settings_cyr2latProfileUpdated),
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(
|
|
|
|
|
context.l10n.channels_cyr2latSettingsDialogWrongJSON(
|
|
|
|
|
e.toString(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Text(context.l10n.common_save),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showDeleteCyr2LatProfileDialog(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
AppSettingsService settingsService,
|
|
|
|
|
Cyr2LatProfile profile,
|
|
|
|
|
) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
|
title: Text(context.l10n.settings_cyr2latProfileDelete),
|
|
|
|
|
content: Text(
|
|
|
|
|
context.l10n.settings_cyr2latProfileDeleteDscr(profile.name),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: Text(context.l10n.common_cancel),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
await settingsService.removeCyr2LatProfile(profile.id);
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
showDismissibleSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
content: Text(context.l10n.settings_cyr2latProfileDeleted),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text(context.l10n.common_delete),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildDebugCard(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
AppSettingsService settingsService,
|
|
|
|
|
|