clean up settings, hopefully fix delay between submit and upload

This commit is contained in:
stopflock
2025-07-19 22:01:19 -05:00
parent f8d71d0c75
commit 978223f7bd
3 changed files with 43 additions and 37 deletions

View File

@@ -1,5 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Internet permission for map tiles and API calls -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Location permissions for bluedot positioning -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
@@ -69,4 +72,3 @@
</intent>
</queries>
</manifest>

View File

@@ -141,6 +141,16 @@ class AppState extends ChangeNotifier {
notifyListeners();
}
// Validate current token/credentials
Future<bool> validateToken() async {
try {
return await _auth.isLoggedIn();
} catch (e) {
print('AppState: Token validation error: $e');
return false;
}
}
// ---------- Profiles ----------
List<CameraProfile> get profiles => List.unmodifiable(_profiles);
bool isEnabled(CameraProfile p) => _enabled.contains(p);
@@ -216,6 +226,10 @@ class AppState extends ChangeNotifier {
);
_saveQueue();
_session = null;
// Restart uploader when new items are added
_startUploader();
notifyListeners();
}
@@ -305,4 +319,3 @@ class AppState extends ChangeNotifier {
notifyListeners();
}
}

View File

@@ -18,6 +18,7 @@ class SettingsScreen extends StatelessWidget {
body: ListView(
padding: const EdgeInsets.all(16),
children: [
// Authentication section
ListTile(
leading: Icon(
appState.isLoggedIn ? Icons.person : Icons.login,
@@ -28,57 +29,48 @@ class SettingsScreen extends StatelessWidget {
: 'Log in to OpenStreetMap'),
subtitle: appState.isLoggedIn
? const Text('Tap to logout')
: const Text('Tap to login'),
: const Text('Required to submit camera data'),
onTap: () async {
if (appState.isLoggedIn) {
await appState.logout();
} else {
await appState.login();
await appState.forceLogin(); // Use force login as the primary method
}
},
),
ListTile(
leading: const Icon(Icons.refresh),
title: const Text('Refresh Login Status'),
subtitle: const Text('Check if you\'re already logged in'),
onTap: () async {
await appState.refreshAuthState();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(appState.isLoggedIn
? 'Logged in as ${appState.username}'
: 'Not logged in'),
),
);
}
},
),
ListTile(
leading: const Icon(Icons.login_outlined),
title: const Text('Force Fresh Login'),
subtitle: const Text('Clear stored tokens and login again'),
onTap: () async {
await appState.forceLogin();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(appState.isLoggedIn
? 'Fresh login successful: ${appState.username}'
: 'Fresh login failed'),
backgroundColor: appState.isLoggedIn ? Colors.green : Colors.red,
: 'Logged out'),
backgroundColor: appState.isLoggedIn ? Colors.green : Colors.grey,
),
);
}
},
),
// Test connection (only when logged in)
if (appState.isLoggedIn)
ListTile(
leading: const Icon(Icons.cloud_upload),
title: const Text('Test upload'),
onTap: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Upload will run soon...')),
),
leading: const Icon(Icons.wifi_protected_setup),
title: const Text('Test Connection'),
subtitle: const Text('Verify OSM credentials are working'),
onTap: () async {
final isValid = await appState.validateToken();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(isValid
? 'Connection OK - credentials are valid'
: 'Connection failed - please re-login'),
backgroundColor: isValid ? Colors.green : Colors.red,
),
);
}
if (!isValid) {
// Auto-logout if token is invalid
await appState.logout();
}
},
),
const Divider(),
Row(
@@ -289,4 +281,3 @@ class SettingsScreen extends StatelessWidget {
);
}
}