OSM message notifications in theory

This commit is contained in:
stopflock
2025-12-02 12:10:09 -06:00
parent f3a5238f50
commit bc03dcbe89
16 changed files with 607 additions and 92 deletions
-64
View File
@@ -101,75 +101,11 @@ class AboutScreen extends StatelessWidget {
_buildLinkText(context, 'Source Code', 'https://github.com/FoggedLens/deflock-app'),
const SizedBox(height: 8),
_buildLinkText(context, 'Contact', 'https://deflock.me/contact'),
const SizedBox(height: 24),
// Divider for account management section
Divider(
color: Theme.of(context).dividerColor.withOpacity(0.3),
),
const SizedBox(height: 16),
// Account deletion link (less prominent)
_buildAccountDeletionLink(context),
],
);
}
Widget _buildAccountDeletionLink(BuildContext context) {
final locService = LocalizationService.instance;
return GestureDetector(
onTap: () => _showDeleteAccountDialog(context, locService),
child: Text(
locService.t('auth.deleteAccount'),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.error.withOpacity(0.7),
decoration: TextDecoration.underline,
),
textAlign: TextAlign.center,
),
);
}
void _showDeleteAccountDialog(BuildContext context, LocalizationService locService) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(locService.t('auth.deleteAccount')),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(locService.t('auth.deleteAccountExplanation')),
const SizedBox(height: 12),
Text(
locService.t('auth.deleteAccountWarning'),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.error,
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(locService.t('actions.cancel')),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
_launchUrl('https://www.openstreetmap.org/account/deletion', context);
},
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
),
child: Text(locService.t('auth.goToOSM')),
),
],
),
);
}
Widget _buildLinkText(BuildContext context, String text, String url) {
return GestureDetector(
+25 -5
View File
@@ -713,11 +713,31 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
),
AnimatedBuilder(
animation: LocalizationService.instance,
builder: (context, child) => IconButton(
tooltip: LocalizationService.instance.settings,
icon: const Icon(Icons.settings),
onPressed: () => Navigator.pushNamed(context, '/settings'),
),
builder: (context, child) {
final appState = context.watch<AppState>();
return IconButton(
tooltip: LocalizationService.instance.settings,
icon: Stack(
children: [
const Icon(Icons.settings),
if (appState.hasUnreadMessages && appState.uploadMode != UploadMode.simulate)
Positioned(
right: 0,
top: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.error,
shape: BoxShape.circle,
),
),
),
],
),
onPressed: () => Navigator.pushNamed(context, '/settings'),
);
},
),
],
),
+249 -7
View File
@@ -4,12 +4,28 @@ import 'package:url_launcher/url_launcher.dart';
import '../app_state.dart';
import '../services/localization_service.dart';
import '../dev_config.dart';
import '../state/settings_state.dart';
import '../screens/settings/sections/upload_mode_section.dart';
class OSMAccountScreen extends StatelessWidget {
class OSMAccountScreen extends StatefulWidget {
const OSMAccountScreen({super.key});
@override
State<OSMAccountScreen> createState() => _OSMAccountScreenState();
}
class _OSMAccountScreenState extends State<OSMAccountScreen> {
@override
void initState() {
super.initState();
// Check for messages when screen loads
WidgetsBinding.instance.addPostFrameCallback((_) {
final appState = context.read<AppState>();
if (appState.isLoggedIn) {
appState.checkMessages();
}
});
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
@@ -90,14 +106,68 @@ class OSMAccountScreen extends StatelessWidget {
},
),
const Divider(),
// Only show OSM website buttons when not in simulate mode
if (appState.uploadMode != UploadMode.simulate) ...[
const Divider(),
ListTile(
leading: const Icon(Icons.history),
title: Text(locService.t('auth.viewMyEdits')),
subtitle: Text(locService.t('auth.viewMyEditsSubtitle')),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
final url = Uri.parse('https://openstreetmap.org/user/${Uri.encodeComponent(appState.username)}/history');
if (await canLaunchUrl(url)) {
await launchUrl(url, mode: LaunchMode.externalApplication);
} else {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(locService.t('advancedEdit.couldNotOpenOSMWebsite'))),
);
}
}
},
),
// Messages button - only show when not in simulate mode
const Divider(),
ListTile(
leading: const Icon(Icons.history),
title: Text(locService.t('auth.viewMyEdits')),
subtitle: Text(locService.t('auth.viewMyEditsSubtitle')),
leading: Stack(
children: [
const Icon(Icons.message),
if (appState.hasUnreadMessages)
Positioned(
right: 0,
top: 0,
child: Container(
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.error,
shape: BoxShape.circle,
),
constraints: const BoxConstraints(
minWidth: 12,
minHeight: 12,
),
child: Text(
'${appState.unreadMessageCount}',
style: TextStyle(
color: Theme.of(context).colorScheme.onError,
fontSize: 10,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
),
],
),
title: Text(locService.t('auth.viewMessages')),
subtitle: Text(appState.hasUnreadMessages
? locService.t('auth.unreadMessagesCount', params: [appState.unreadMessageCount.toString()])
: locService.t('auth.noUnreadMessages')),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
final url = Uri.parse('https://openstreetmap.org/user/${Uri.encodeComponent(appState.username)}/history');
final url = Uri.parse(appState.getMessagesUrl());
if (await canLaunchUrl(url)) {
await launchUrl(url, mode: LaunchMode.externalApplication);
} else {
@@ -109,6 +179,7 @@ class OSMAccountScreen extends StatelessWidget {
}
},
),
],
],
],
),
@@ -167,10 +238,181 @@ class OSMAccountScreen extends StatelessWidget {
),
),
),
// Account deletion section - only show when logged in
if (appState.isLoggedIn) ...[
const SizedBox(height: 16),
_buildAccountDeletionSection(context, appState),
],
],
),
);
},
);
}
Widget _buildAccountDeletionSection(BuildContext context, AppState appState) {
final locService = LocalizationService.instance;
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
locService.t('auth.accountManagement'),
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
Text(
locService.t('auth.accountManagementDescription'),
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 16),
// Show current upload destination
Container(
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.5),
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
children: [
Icon(
Icons.info_outline,
size: 16,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 8),
Expanded(
child: Text(
_getCurrentDestinationText(locService, appState.uploadMode),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
],
),
),
const SizedBox(height: 16),
// Delete account button
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () => _showDeleteAccountDialog(context, locService, appState.uploadMode),
icon: const Icon(Icons.delete_outline),
label: Text(locService.t('auth.deleteAccount')),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
side: BorderSide(color: Theme.of(context).colorScheme.error.withOpacity(0.5)),
),
),
),
],
),
),
);
}
String _getCurrentDestinationText(LocalizationService locService, UploadMode uploadMode) {
switch (uploadMode) {
case UploadMode.production:
return locService.t('auth.currentDestinationProduction');
case UploadMode.sandbox:
return locService.t('auth.currentDestinationSandbox');
case UploadMode.simulate:
return locService.t('auth.currentDestinationSimulate');
}
}
void _showDeleteAccountDialog(BuildContext context, LocalizationService locService, UploadMode uploadMode) {
final deleteUrl = _getDeleteAccountUrl(uploadMode);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(locService.t('auth.deleteAccount')),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(locService.t('auth.deleteAccountExplanation')),
const SizedBox(height: 12),
Text(
locService.t('auth.deleteAccountWarning'),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.error,
),
),
const SizedBox(height: 12),
// Show which account will be deleted
Container(
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.errorContainer.withOpacity(0.1),
borderRadius: BorderRadius.circular(8.0),
border: Border.all(
color: Theme.of(context).colorScheme.error.withOpacity(0.3),
),
),
child: Text(
_getCurrentDestinationText(locService, uploadMode),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.error,
),
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(locService.t('actions.cancel')),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
_launchDeleteAccountUrl(deleteUrl, context, locService);
},
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
),
child: Text(locService.t('auth.goToOSM')),
),
],
),
);
}
String _getDeleteAccountUrl(UploadMode uploadMode) {
switch (uploadMode) {
case UploadMode.production:
return 'https://www.openstreetmap.org/account/deletion';
case UploadMode.sandbox:
return 'https://master.apis.dev.openstreetmap.org/account/deletion';
case UploadMode.simulate:
// For simulate mode, just go to production since it's not a real account
return 'https://www.openstreetmap.org/account/deletion';
}
}
Future<void> _launchDeleteAccountUrl(String url, BuildContext context, LocalizationService locService) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(locService.t('advancedEdit.couldNotOpenOSMWebsite')),
),
);
}
}
}
}
+32 -7
View File
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../app_state.dart';
import '../services/localization_service.dart';
import '../services/version_service.dart';
import '../dev_config.dart';
@@ -23,13 +25,7 @@ class SettingsScreen extends StatelessWidget {
),
children: [
// OpenStreetMap Account
_buildNavigationTile(
context,
icon: Icons.account_circle,
title: locService.t('auth.osmAccountTitle'),
subtitle: locService.t('auth.osmAccountSubtitle'),
onTap: () => Navigator.pushNamed(context, '/settings/osm-account'),
),
_buildOSMAccountTile(context, locService),
const Divider(),
// Upload Queue
@@ -117,6 +113,35 @@ class SettingsScreen extends StatelessWidget {
);
}
Widget _buildOSMAccountTile(BuildContext context, LocalizationService locService) {
final appState = context.watch<AppState>();
return ListTile(
leading: Stack(
children: [
const Icon(Icons.account_circle),
if (appState.hasUnreadMessages && appState.uploadMode != UploadMode.simulate)
Positioned(
right: 0,
top: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.error,
shape: BoxShape.circle,
),
),
),
],
),
title: Text(locService.t('auth.osmAccountTitle')),
subtitle: Text(locService.t('auth.osmAccountSubtitle')),
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
onTap: () => Navigator.pushNamed(context, '/settings/osm-account'),
);
}
Widget _buildNavigationTile(
BuildContext context, {
required IconData icon,