mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-05-15 21:48:18 +02:00
cleanup round
This commit is contained in:
@@ -55,7 +55,6 @@ class AuthService {
|
||||
enablePKCE: true,
|
||||
// tokenStorageKey: _tokenKey, // not supported by this package version
|
||||
);
|
||||
print('AuthService: Initialized for $mode with $authBase, clientId $clientId [manual token storage as needed]');
|
||||
}
|
||||
|
||||
Future<bool> isLoggedIn() async {
|
||||
@@ -80,17 +79,14 @@ class AuthService {
|
||||
|
||||
Future<String?> login() async {
|
||||
if (_mode == UploadMode.simulate) {
|
||||
print('AuthService: Simulate login (no OAuth)');
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_displayName = 'Demo User';
|
||||
await prefs.setBool('sim_user_logged_in', true);
|
||||
return _displayName;
|
||||
}
|
||||
try {
|
||||
print('AuthService: Starting OAuth login...');
|
||||
final token = await _helper.getToken();
|
||||
if (token?.accessToken == null) {
|
||||
print('AuthService: OAuth error - token null or missing accessToken');
|
||||
log('OAuth error: token null or missing accessToken');
|
||||
return null;
|
||||
}
|
||||
@@ -101,13 +97,7 @@ class AuthService {
|
||||
final tokenJson = jsonEncode(tokenMap);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_tokenKey, tokenJson); // Save token for current mode
|
||||
print('AuthService: Got access token, fetching username...');
|
||||
_displayName = await _fetchUsername(token!.accessToken!);
|
||||
if (_displayName != null) {
|
||||
print('AuthService: Successfully fetched username: $_displayName');
|
||||
} else {
|
||||
print('AuthService: Failed to fetch username from OSM API');
|
||||
}
|
||||
return _displayName;
|
||||
} catch (e) {
|
||||
print('AuthService: OAuth login failed: $e');
|
||||
@@ -131,7 +121,6 @@ class AuthService {
|
||||
|
||||
// Force a fresh login by clearing stored tokens
|
||||
Future<String?> forceLogin() async {
|
||||
print('AuthService: Forcing fresh login by clearing stored tokens...');
|
||||
await _helper.removeAllTokens();
|
||||
_displayName = null;
|
||||
return await login();
|
||||
@@ -162,37 +151,17 @@ class AuthService {
|
||||
|
||||
Future<String?> _fetchUsername(String accessToken) async {
|
||||
try {
|
||||
print('AuthService: Fetching username from OSM API ($_apiHost) ...');
|
||||
print('AuthService: Access token (first 20 chars): ${accessToken.substring(0, math.min(20, accessToken.length))}...');
|
||||
|
||||
final resp = await http.get(
|
||||
Uri.parse('$_apiHost/api/0.6/user/details.json'),
|
||||
headers: {'Authorization': 'Bearer $accessToken'},
|
||||
);
|
||||
print('AuthService: OSM API response status: ${resp.statusCode}');
|
||||
print('AuthService: Response headers: ${resp.headers}');
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
print('AuthService: fetchUsername failed with ${resp.statusCode}: ${resp.body}');
|
||||
log('fetchUsername response ${resp.statusCode}: ${resp.body}');
|
||||
|
||||
// Try to get more info about the token by checking permissions endpoint
|
||||
try {
|
||||
print('AuthService: Checking token permissions...');
|
||||
final permResp = await http.get(
|
||||
Uri.parse('$_apiHost/api/0.6/permissions.json'),
|
||||
headers: {'Authorization': 'Bearer $accessToken'},
|
||||
);
|
||||
print('AuthService: Permissions response ${permResp.statusCode}: ${permResp.body}');
|
||||
} catch (e) {
|
||||
print('AuthService: Error checking permissions: $e');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
final userData = jsonDecode(resp.body);
|
||||
final displayName = userData['user']?['display_name'];
|
||||
print('AuthService: Extracted display name: $displayName');
|
||||
return displayName;
|
||||
} catch (e) {
|
||||
print('AuthService: Error fetching username: $e');
|
||||
|
||||
@@ -57,14 +57,12 @@ class UploadQueueState extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void clearQueue() {
|
||||
print("UploadQueueState: Clearing upload queue (${_queue.length} items)");
|
||||
_queue.clear();
|
||||
_saveQueue();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeFromQueue(PendingUpload upload) {
|
||||
print("UploadQueueState: Removing upload from queue: ${upload.coord}");
|
||||
_queue.remove(upload);
|
||||
_saveQueue();
|
||||
notifyListeners();
|
||||
@@ -105,10 +103,8 @@ class UploadQueueState extends ChangeNotifier {
|
||||
bool ok;
|
||||
if (uploadMode == UploadMode.simulate) {
|
||||
// Simulate successful upload without calling real API
|
||||
print("UploadQueueState: UploadMode.simulate - simulating upload for ${item.coord}");
|
||||
await Future.delayed(const Duration(seconds: 1)); // Simulate network delay
|
||||
ok = true;
|
||||
print('UploadQueueState: Simulated upload successful');
|
||||
} else {
|
||||
// Real upload -- pass uploadMode so uploader can switch between prod and sandbox
|
||||
final up = Uploader(access, () {
|
||||
|
||||
@@ -70,8 +70,7 @@ class CameraMarkersBuilder {
|
||||
final markers = <Marker>[
|
||||
// Camera markers
|
||||
...cameras
|
||||
.where((n) => n.coord.latitude != 0 || n.coord.longitude != 0)
|
||||
.where((n) => n.coord.latitude.abs() <= 90 && n.coord.longitude.abs() <= 180)
|
||||
.where(_isValidCameraCoordinate)
|
||||
.map((n) => Marker(
|
||||
point: n.coord,
|
||||
width: 24,
|
||||
@@ -91,4 +90,10 @@ class CameraMarkersBuilder {
|
||||
|
||||
return markers;
|
||||
}
|
||||
|
||||
static bool _isValidCameraCoordinate(OsmCameraNode node) {
|
||||
return (node.coord.latitude != 0 || node.coord.longitude != 0) &&
|
||||
node.coord.latitude.abs() <= 90 &&
|
||||
node.coord.longitude.abs() <= 180;
|
||||
}
|
||||
}
|
||||
@@ -28,21 +28,31 @@ class DirectionConesBuilder {
|
||||
// Add cones for cameras with direction
|
||||
overlays.addAll(
|
||||
cameras
|
||||
.where((n) => n.hasDirection && n.directionDeg != null)
|
||||
.where((n) => n.coord.latitude != 0 || n.coord.longitude != 0)
|
||||
.where((n) => n.coord.latitude.abs() <= 90 && n.coord.longitude.abs() <= 180)
|
||||
.where(_isValidCameraWithDirection)
|
||||
.map((n) => _buildCone(
|
||||
n.coord,
|
||||
n.directionDeg!,
|
||||
zoom,
|
||||
isPending: n.tags.containsKey('_pending_upload') &&
|
||||
n.tags['_pending_upload'] == 'true',
|
||||
isPending: _isPendingUpload(n),
|
||||
))
|
||||
);
|
||||
|
||||
return overlays;
|
||||
}
|
||||
|
||||
static bool _isValidCameraWithDirection(OsmCameraNode node) {
|
||||
return node.hasDirection &&
|
||||
node.directionDeg != null &&
|
||||
(node.coord.latitude != 0 || node.coord.longitude != 0) &&
|
||||
node.coord.latitude.abs() <= 90 &&
|
||||
node.coord.longitude.abs() <= 180;
|
||||
}
|
||||
|
||||
static bool _isPendingUpload(OsmCameraNode node) {
|
||||
return node.tags.containsKey('_pending_upload') &&
|
||||
node.tags['_pending_upload'] == 'true';
|
||||
}
|
||||
|
||||
static Polygon _buildCone(
|
||||
LatLng origin,
|
||||
double bearingDeg,
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../app_state.dart';
|
||||
import '../services/map_data_provider.dart';
|
||||
import '../services/offline_area_service.dart';
|
||||
import '../models/osm_camera_node.dart';
|
||||
import 'debouncer.dart';
|
||||
@@ -35,7 +34,6 @@ class MapView extends StatefulWidget {
|
||||
|
||||
class _MapViewState extends State<MapView> {
|
||||
late final MapController _controller;
|
||||
final MapDataProvider _mapDataProvider = MapDataProvider();
|
||||
final Debouncer _debounce = Debouncer(kDebounceCameraRefresh);
|
||||
|
||||
StreamSubscription<Position>? _positionSub;
|
||||
|
||||
Reference in New Issue
Block a user