Skip to content

Commit

Permalink
Remember last recording settings (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKun committed Sep 10, 2023
1 parent 794c17c commit 620fb07
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added option to start recording by pressing volume buttons
- Store location metadata in video when geotagging is enabled
- Autofocus and capitalize first letter of custom locale and subtitles text fields
- Remember last recording settings (which camera was used and geotagging checkbox)

## v1.5.2 - 09/2023
- Added quick trim shortcuts in save video page for a more precise editing
Expand Down
18 changes: 13 additions & 5 deletions lib/pages/recording/recording_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../controllers/recording_settings_controller.dart';
import '../../routes/app_pages.dart';
import '../../utils/constants.dart';
import '../../utils/custom_dialog.dart';
import '../../utils/shared_preferences_util.dart';
import '../../utils/utils.dart';

// TODO(KyleKun): refactor this in the future ffs lol
Expand All @@ -25,6 +26,8 @@ class _RecordingPageState extends State<RecordingPage>
final logTag = '[CAMERA] - ';
late CameraController _cameraController;
late List<CameraDescription> _availableCameras;
late CameraDescription _frontCamera;
late CameraDescription _backCamera;
late StreamSubscription<HardwareButton>? volumeButtonStream;

final RecordingSettingsController _recordingSettingsController = Get.find();
Expand Down Expand Up @@ -167,8 +170,13 @@ class _RecordingPageState extends State<RecordingPage>
WidgetsFlutterBinding.ensureInitialized();
await Utils.requestPermission(Permission.microphone);
await Utils.requestPermission(Permission.camera);
final recordWithFrontCamera = SharedPrefsUtil.getBool('recordWithFrontCamera') ?? false;
_availableCameras = await availableCameras();
_initCamera(_availableCameras.first);
_frontCamera = _availableCameras
.firstWhere((description) => description.lensDirection == CameraLensDirection.front);
_backCamera = _availableCameras
.firstWhere((description) => description.lensDirection == CameraLensDirection.back);
_initCamera(recordWithFrontCamera ? _frontCamera : _backCamera);
}

Future<void> _initCamera(CameraDescription description) async {
Expand Down Expand Up @@ -217,12 +225,12 @@ class _RecordingPageState extends State<RecordingPage>
if (toggle) {
CameraDescription newDescription;
if (lensDirection == CameraLensDirection.front) {
newDescription = _availableCameras
.firstWhere((description) => description.lensDirection == CameraLensDirection.back);
newDescription = _backCamera;
SharedPrefsUtil.putBool('recordWithFrontCamera', false);
Utils.logInfo('${logTag}Changed to back camera');
} else {
newDescription = _availableCameras
.firstWhere((description) => description.lensDirection == CameraLensDirection.front);
newDescription = _frontCamera;
SharedPrefsUtil.putBool('recordWithFrontCamera', true);
Utils.logInfo('${logTag}Changed to front camera');
}
_initCamera(newDescription);
Expand Down
18 changes: 15 additions & 3 deletions lib/pages/save_video/save_video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _SaveVideoPageState extends State<SaveVideoPage> {

String? _currentAddress;
Position? _currentPosition;
bool isGeotaggingEnabled = false;
bool isGeotaggingEnabled = SharedPrefsUtil.getBool('enableGeotagging') ?? false;
String? _subtitles;
double _videoStartValue = 0.0;
double _videoEndValue = 0.0;
Expand Down Expand Up @@ -158,6 +158,16 @@ class _SaveVideoPageState extends State<SaveVideoPage> {
return true;
}

Future<void> setGeotagging() async {
Utils.logInfo('[Geolocation] - Getting location...');
await _getCurrentPosition().then(
(_) => SharedPrefsUtil.putBool(
'enableGeotagging',
isGeotaggingEnabled,
),
);
}

Future<void> _getCurrentPosition() async {
final hasPermission = await _handleLocationPermission();
if (!hasPermission) return;
Expand Down Expand Up @@ -274,6 +284,9 @@ class _SaveVideoPageState extends State<SaveVideoPage> {
isTextDate = _recordingSettingsController.dateFormatId.value == 1;
_initCorrectDates();
_initVideoPlayerController();
if (isGeotaggingEnabled) {
setGeotagging();
}
super.initState();
}

Expand Down Expand Up @@ -700,8 +713,7 @@ class _SaveVideoPageState extends State<SaveVideoPage> {
if (!_isLocationProcessing) {
toggleGeotaggingStatus();
if (isGeotaggingEnabled) {
Utils.logInfo('[Geolocation] - Getting location...');
await _getCurrentPosition();
await setGeotagging();
}
setState(() {});
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Record one second of your day, everyday.

publish_to: "none"

version: 1.5.3+16
version: 1.5.3+17

environment:
sdk: ">=2.18.2 <3.0.0"
Expand Down

0 comments on commit 620fb07

Please sign in to comment.