Skip to content

Commit

Permalink
Merge pull request #12 from tlm-solutions/comply-with-osm-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
TKFRvisionOfficial authored Jan 25, 2023
2 parents 0a0135a + 32e8161 commit 1efd37a
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 168 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion getProperty('flutter.compileSdkVersion').toInteger()
ndkVersion flutter.ndkVersion

compileOptions {
Expand Down
7 changes: 7 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
<application
android:label="stasi"
android:name="${applicationName}"
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
flutter.minSdkVersion=18
flutter.compileSdkVersion=33
4 changes: 4 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@
<string>fetch</string>
<string>location</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
</dict>
</plist>
48 changes: 24 additions & 24 deletions lib/db/database_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class DatabaseDao {
Future<List<Recording>> getRecordings() async {
final db = await dbProvider.db;

final recordingDict = await db.rawQuery('''
final recordingDict = await db.rawQuery("""
SELECT rec.id, rec.line_number, rec.run_number, rec.is_uploaded,
start_cord.time AS start, end_cord.time AS end,
MIN(cords.time) AS total_start, MAX(cords.time) AS total_end
FROM recordings AS rec
LEFT JOIN cords start_cord ON start_cord.id = rec.start_cord_id
LEFT JOIN cords end_cord ON end_cord.id = rec.end_cord_id
JOIN cords ON rec.id = cords.recording_id
GROUP BY rec.id;
''');
FROM recordings AS rec
LEFT JOIN cords start_cord ON start_cord.id = rec.start_cord_id
LEFT JOIN cords end_cord ON end_cord.id = rec.end_cord_id
JOIN cords ON rec.id = cords.recording_id
GROUP BY rec.id;
""");

return recordingDict.map((entry) =>
Recording(
Expand Down Expand Up @@ -72,23 +72,23 @@ class DatabaseDao {
final db = await dbProvider.db;

return await db.rawUpdate(
'''
UPDATE recordings
SET
start_cord_id = (
SELECT cords.id
FROM cords
WHERE NOT DATETIME(?) > cords.time
ORDER BY cords.time
),
end_cord_id = (
SELECT cords.id
FROM cords
WHERE NOT DATETIME(?) < cords.time
ORDER BY cords.time DESC
)
WHERE id = ?;
''',
"""
UPDATE recordings
SET
start_cord_id = (
SELECT cords.id
FROM cords
WHERE NOT DATETIME(?) > cords.time
ORDER BY cords.time
),
end_cord_id = (
SELECT cords.id
FROM cords
WHERE NOT DATETIME(?) < cords.time
ORDER BY cords.time DESC
)
WHERE id = ?;
""",
[
startTime.toString(),
endTime.toString(),
Expand Down
12 changes: 6 additions & 6 deletions lib/db/database_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class DatabaseProvider {
final database = await openDatabase(
join(databasePath, "cords.db"),
onConfigure: (db) async {
await db.execute('PRAGMA foreign_keys = ON');
await db.execute("PRAGMA foreign_keys = ON");
},
onCreate: (db, version) async {
await db.execute('''
await db.execute("""
CREATE TABLE recordings (
id INTEGER PRIMARY KEY,
line_number INTEGER,
Expand All @@ -38,9 +38,9 @@ class DatabaseProvider {
start_cord_id INTEGER,
end_cord_id INTEGER
);
''');
""");

await db.execute('''
await db.execute("""
CREATE TABLE cords (
id INTEGER PRIMARY KEY,
time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
Expand All @@ -53,11 +53,11 @@ class DatabaseProvider {
ON UPDATE CASCADE
ON DELETE CASCADE
);
''');
""");
},
onOpen: (db) async {
// remove recordings that have less than three cords
await db.execute("""
await db.rawDelete("""
DELETE FROM recordings WHERE (
SELECT COUNT(cords.id) FROM cords WHERE cords.recording_id = recordings.id
) < 3;
Expand Down
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:stasi/db/database_bloc.dart';
import 'package:stasi/pages/running_recording.dart';
import 'package:stasi/notifiers/running_recording.dart';
import 'package:stasi/util/theme.dart';
import 'package:stasi/pages/recording_manager.dart';
import 'package:stasi/pages/vehicle_selection.dart';
Expand Down Expand Up @@ -57,6 +57,10 @@ class _MyHomePageState extends State<MyHomePage> {
RecordingManager(databaseBloc: widget.databaseBloc),
const LicensePage(
applicationName: "Stasi",
applicationLegalese: """
© TKFRvision All Rights Reserved
Can we decide on FOSS-License already? For fuck's sake!
""",
),
],
),
Expand Down
File renamed without changes.
136 changes: 5 additions & 131 deletions lib/pages/recording_editor.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:stasi/db/database_bloc.dart';

import '../model/recording.dart';
import 'package:stasi/db/database_bloc.dart';
import 'package:stasi/widgets/recording_map.dart';
import 'package:stasi/model/recording.dart';


class RecordingEditor extends StatefulWidget {
Expand All @@ -18,7 +18,7 @@ class RecordingEditor extends StatefulWidget {
final Recording recording;

@override
State<StatefulWidget> createState() => _RecordingEditorState();
State<RecordingEditor> createState() => _RecordingEditorState();
}

class _RecordingEditorState extends State<RecordingEditor> {
Expand Down Expand Up @@ -125,7 +125,7 @@ class _RecordingEditorControlState extends State<_RecordingEditorControl> {
return Column(
children: [
Expanded(
child: _RecordingEditorMap(
child: RecordingMap(
pointList: [
for (final time in widget.points.keys)
if (_startTime.compareTo(time) <= 0 && _endTime.compareTo(time) >= 0)
Expand Down Expand Up @@ -176,132 +176,6 @@ class _RecordingEditorControlState extends State<_RecordingEditorControl> {
}
}

class _RecordingEditorMap extends StatefulWidget {
const _RecordingEditorMap({
Key? key,
required this.pointList,
}) : super(key: key);

final List<LatLng> pointList;

@override
_RecordingEditorMapState createState() => _RecordingEditorMapState();
}

LatLngBounds _getBoundsFromPoints(List<LatLng> points) {
final bounds = LatLngBounds.fromPoints(points);

/*
When all the points are the same the southWest and northEast
become the same too. This leads to an error in flutter map.
(Unsupported operation: Infinity or NaN toInt)
This normally only happens during debugging.
*/

if (bounds.southWest!.latitude == bounds.northEast!.latitude) {
bounds.southWest!.latitude += 0.0005;
bounds.northEast!.latitude -= 0.0005;
}

if (bounds.southWest!.longitude == bounds.northEast!.longitude) {
bounds.southWest!.longitude -= 0.0005;
bounds.northEast!.longitude += 0.0005;
}

return bounds;
}

class _RecordingEditorMapState extends State<_RecordingEditorMap> {
late MapController _mapController;
bool _shouldApplyBounds = true;

@override
void initState() {
super.initState();
_mapController = MapController();
}

@override
void didUpdateWidget(_RecordingEditorMap oldWidget) {
super.didUpdateWidget(oldWidget);

// yeah this won't get triggered when the orientation changes.
// too bad...
if (_shouldApplyBounds && oldWidget.pointList != widget.pointList) {
_updateBounds();
}
}

void _updateBounds() {
_mapController.fitBounds(
_getBoundsFromPoints(widget.pointList),
options: const FitBoundsOptions(padding: EdgeInsets.all(80.0)),
);
}

@override
Widget build(BuildContext context) {
return Stack(
children: [
FlutterMap(
mapController: _mapController,
options: MapOptions(
bounds: _getBoundsFromPoints(widget.pointList),
boundsOptions: const FitBoundsOptions(padding: EdgeInsets.all(80.0)),
),
children: [
TileLayer(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: const ["a", "b", "c"],
tileBuilder: darkModeTileBuilder,
backgroundColor: Colors.black54,
),
PolylineLayer(
polylines: [Polyline(
points: widget.pointList,
strokeWidth: 10,
)],
),
],
),
Positioned(
top: 3,
right: 3,
child: ToggleButtons(
isSelected: [_shouldApplyBounds, false],
color: Colors.white,
onPressed: (index) {
switch (index) {
case 0: // lock
setState(() {
_shouldApplyBounds = !_shouldApplyBounds;
});

if (_shouldApplyBounds) _updateBounds();
break;

case 1: // center
_updateBounds();
break;
}
},
children: const [
Icon(Icons.lock),
Icon(Icons.center_focus_strong),
],
),
),
],
);
}

@override
void dispose() {
_mapController.dispose();
super.dispose();
}
}


class _RecordingEditorSlider extends StatelessWidget {
const _RecordingEditorSlider({
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/recording_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:http/http.dart' as http;

import 'package:stasi/db/database_bloc.dart';
import 'package:stasi/routes/recording_editor_route.dart';
import 'package:stasi/pages/running_recording.dart';
import 'package:stasi/notifiers/running_recording.dart';
import 'package:stasi/util/theme.dart';
import 'package:stasi/util/api_client.dart';
import 'package:stasi/model/recording.dart';
Expand Down Expand Up @@ -71,12 +71,12 @@ class _RecordingManagerState extends State<RecordingManager> {
await _uploadRecording(widget.databaseBloc, recordings[index]);
} on http.ClientException {
scaffoldMessenger.showSnackBar(const SnackBar(
content: Text("We couldn't connect to the KGB server. Is your Internet working?")
content: Text("We couldn't connect to the KGB server. Is your Internet working?"),
));
return;
}
scaffoldMessenger.showSnackBar(const SnackBar(
content: Text("Uploaded!")
content: Text("Uploaded!"),
));
await widget.databaseBloc.markRecordingUploadDone(recordings[index].id);
},
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/vehicle_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:background_location/background_location.dart';
import 'package:provider/provider.dart';
import 'package:stasi/pages/running_recording.dart';

import '../db/database_bloc.dart';
import 'package:stasi/notifiers/running_recording.dart';
import 'package:stasi/db/database_bloc.dart';


class VehicleSelection extends StatefulWidget {
Expand Down
Loading

0 comments on commit 1efd37a

Please sign in to comment.