ML-23 Implement migration mechanism for material_lightmeter users (#38)

* migrate existent keys

* await

* Update cd_dev.yml

* Update cd_dev.yml

* Update cd_dev.yml

* Fixed CD flavor artifact upload
This commit is contained in:
Vadim 2023-02-17 22:32:25 +03:00 committed by GitHub
parent 9945005008
commit f8391454b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 9 deletions

View file

@ -3,13 +3,19 @@
# separate terms of service, privacy policy, and support
# documentation.
name: Build Dev APK
name: Build APK
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
flavor:
description: 'Flavor'
type: choice
required: true
options:
- dev
- prod
default: 'dev'
jobs:
build:
@ -47,9 +53,12 @@ jobs:
flutter pub run intl_utils:generate
- name: Build Apk
run: flutter build apk --release --flavor dev --dart-define cameraPreviewAspectRatio=2/3 -t lib/main_dev.dart
env:
FLAVOR: ${{ github.event.inputs.flavor }}
run: flutter build apk --release --flavor $FLAVOR --dart-define cameraPreviewAspectRatio=2/3 -t lib/main_$FLAVOR.dart
- uses: actions/upload-artifact@v3
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: m3_lightmeter.apk
path: build/app/outputs/flutter-apk/app-dev-release.apk
name: m3_lightmeter_${{ github.event.inputs.flavor }}
path: build/app/outputs/flutter-apk/app-${{ github.event.inputs.flavor }}-release.apk

View file

@ -20,12 +20,15 @@ const List<NdValue> ndValues = [
NdValue(16),
NdValue(32),
NdValue(64),
NdValue(100),
NdValue(128),
NdValue(256),
NdValue(400),
NdValue(512),
NdValue(1024),
NdValue(2048),
NdValue(4096),
NdValue(6310),
NdValue(8192),
NdValue(10000),
];

View file

@ -25,7 +25,44 @@ class UserPreferencesService {
final SharedPreferences _sharedPreferences;
UserPreferencesService(this._sharedPreferences);
UserPreferencesService(this._sharedPreferences) {
_migrateOldKeys();
}
Future<void> _migrateOldKeys() async {
final legacyIsoIndex = _sharedPreferences.getInt("curIsoIndex");
if (legacyIsoIndex != null) {
iso = isoValues[legacyIsoIndex];
await _sharedPreferences.remove("curIsoIndex");
}
final legacyNdIndex = _sharedPreferences.getInt("curndIndex");
if (legacyNdIndex != null) {
/// Legacy ND list has 1 extra value at the end, so this check is needed
if (legacyNdIndex < ndValues.length) {
ndFilter = ndValues[legacyNdIndex];
}
await _sharedPreferences.remove("curndIndex");
}
final legacyCameraCalibration = _sharedPreferences.getDouble("cameraCalibr");
if (legacyCameraCalibration != null) {
cameraEvCalibration = legacyCameraCalibration;
await _sharedPreferences.remove("cameraCalibr");
}
final legacyLightSensorCalibration = _sharedPreferences.getDouble("sensorCalibr");
if (legacyLightSensorCalibration != null) {
lightSensorEvCalibration = legacyLightSensorCalibration;
await _sharedPreferences.remove("sensorCalibr");
}
final legacyHaptics = _sharedPreferences.getBool("vibrate");
if (legacyHaptics != null) {
haptics = legacyHaptics;
await _sharedPreferences.remove("vibrate");
}
}
IsoValue get iso => isoValues.firstWhere((v) => v.value == (_sharedPreferences.getInt(_isoKey) ?? 100));
set iso(IsoValue value) => _sharedPreferences.setInt(_isoKey, value.value);