Skip to content

Commit

Permalink
simplified time zone offset check
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Nov 23, 2024
1 parent 66f0e2b commit ec7e4ac
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
when (call.method) {
"canManageMedia" -> safe(call, result, ::canManageMedia)
"getCapabilities" -> defaultScope.launch { safe(call, result, ::getCapabilities) }
"getDefaultTimeZoneRawOffsetMillis" -> safe(call, result, ::getDefaultTimeZoneRawOffsetMillis)
"getLocales" -> safe(call, result, ::getLocales)
"setLocaleConfig" -> safe(call, result, ::setLocaleConfig)
"getPerformanceClass" -> safe(call, result, ::getPerformanceClass)
Expand Down Expand Up @@ -67,10 +66,6 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
)
}

private fun getDefaultTimeZoneRawOffsetMillis(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
result.success(TimeZone.getDefault().rawOffset)
}

private fun getLocales(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
fun toMap(locale: Locale): FieldMap = hashMapOf(
"language" to locale.language,
Expand Down
4 changes: 2 additions & 2 deletions lib/model/settings/modules/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ mixin AppSettings on SettingsAccess {

set forceWesternArabicNumerals(bool newValue) => set(SettingKeys.forceWesternArabicNumeralsKey, newValue);

int get catalogTimeZoneRawOffsetMillis => getInt(SettingKeys.catalogTimeZoneRawOffsetMillisKey) ?? 0;
int get catalogTimeZoneOffsetMillis => getInt(SettingKeys.catalogTimeZoneOffsetMillisKey) ?? 0;

set catalogTimeZoneRawOffsetMillis(int newValue) => set(SettingKeys.catalogTimeZoneRawOffsetMillisKey, newValue);
set catalogTimeZoneOffsetMillis(int newValue) => set(SettingKeys.catalogTimeZoneOffsetMillisKey, newValue);

double getTileExtent(String routeName) => getDouble(SettingKeys.tileExtentPrefixKey + routeName) ?? 0;

Expand Down
16 changes: 7 additions & 9 deletions lib/model/source/media_store_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ class MediaStoreSource extends CollectionSource {
await vaults.init();
await favourites.init();
await covers.init();
final currentTimeZoneOffset = await deviceService.getDefaultTimeZoneRawOffsetMillis();
if (currentTimeZoneOffset != null) {
final catalogTimeZoneOffset = settings.catalogTimeZoneRawOffsetMillis;
if (currentTimeZoneOffset != catalogTimeZoneOffset) {
unawaited(reportService.recordError('Time zone offset change: $currentTimeZoneOffset -> $catalogTimeZoneOffset. Clear catalog metadata to get correct date/times.', null));
await localMediaDb.clearDates();
await localMediaDb.clearCatalogMetadata();
settings.catalogTimeZoneRawOffsetMillis = currentTimeZoneOffset;
}
final currentTimeZoneOffset = DateTime.now().timeZoneOffset.inMilliseconds;
final catalogTimeZoneOffset = settings.catalogTimeZoneOffsetMillis;
if (currentTimeZoneOffset != catalogTimeZoneOffset) {
unawaited(reportService.recordError('Time zone offset change: $currentTimeZoneOffset -> $catalogTimeZoneOffset. Clear catalog metadata to get correct date/times.', null));
await localMediaDb.clearDates();
await localMediaDb.clearCatalogMetadata();
settings.catalogTimeZoneOffsetMillis = currentTimeZoneOffset;
}
await loadDates();
debugPrint('$runtimeType load essentials complete in ${stopwatch.elapsed.inMilliseconds}ms');
Expand Down
12 changes: 0 additions & 12 deletions lib/services/device_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ abstract class DeviceService {

Future<Map<String, dynamic>> getCapabilities();

Future<int?> getDefaultTimeZoneRawOffsetMillis();

Future<List<Locale>> getLocales();

Future<void> setLocaleConfig(List<Locale> locales);
Expand Down Expand Up @@ -52,16 +50,6 @@ class PlatformDeviceService implements DeviceService {
return {};
}

@override
Future<int?> getDefaultTimeZoneRawOffsetMillis() async {
try {
return await _platform.invokeMethod('getDefaultTimeZoneRawOffsetMillis');
} on PlatformException catch (e, stack) {
await reportService.recordError(e, stack);
}
return null;
}

@override
Future<List<Locale>> getLocales() async {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/debug/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _DebugSettingsSectionState extends State<DebugSettingsSection> with Automa
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
child: InfoRowGroup(
info: {
'catalogTimeZoneRawOffsetMillis': '${settings.catalogTimeZoneRawOffsetMillis}',
'catalogTimeZoneRawOffsetMillis': '${settings.catalogTimeZoneOffsetMillis}',
'tileExtent - Collection': '${settings.getTileExtent(CollectionPage.routeName)}',
'tileExtent - Albums': '${settings.getTileExtent(AlbumListPage.routeName)}',
'tileExtent - Countries': '${settings.getTileExtent(CountryListPage.routeName)}',
Expand Down
4 changes: 2 additions & 2 deletions plugins/aves_model/lib/src/settings/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class SettingKeys {

static const Set<String> _internalKeys = {
hasAcceptedTermsKey,
catalogTimeZoneRawOffsetMillisKey,
catalogTimeZoneOffsetMillisKey,
searchHistoryKey,
platformAccelerometerRotationKey,
platformTransitionAnimationScaleKey,
Expand All @@ -21,7 +21,7 @@ class SettingKeys {
static const isErrorReportingAllowedKey = 'is_crashlytics_enabled';
static const localeKey = 'locale';
static const forceWesternArabicNumeralsKey = 'force_western_arabic_numerals';
static const catalogTimeZoneRawOffsetMillisKey = 'catalog_time_zone_raw_offset_millis';
static const catalogTimeZoneOffsetMillisKey = 'catalog_time_zone_raw_offset_millis';
static const tileExtentPrefixKey = 'tile_extent_';
static const tileLayoutPrefixKey = 'tile_layout_';
static const entryRenamingPatternKey = 'entry_renaming_pattern';
Expand Down
3 changes: 0 additions & 3 deletions test/fake/device_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import 'package:flutter/foundation.dart';
import 'package:test/fake.dart';

class FakeDeviceService extends Fake implements DeviceService {
@override
Future<int> getDefaultTimeZoneRawOffsetMillis() => SynchronousFuture(3600000);

@override
Future<int> getAvailableHeapSize() => SynchronousFuture(0x7fffffff);

Expand Down

0 comments on commit ec7e4ac

Please sign in to comment.